Browse Source
Merge in DESIGN/design from ~HADES/design:feature/x to feature/x * commit 'd6474b37be4b512f05d03b296dcc6b465fe8365b': KERNEL-10324 DB模块 优化feature/x
Hades
3 years ago
11 changed files with 321 additions and 13 deletions
@ -0,0 +1,27 @@
|
||||
package com.fr.env.utils; |
||||
|
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.design.env.DesignerWorkspaceInfo; |
||||
import com.fr.design.env.LocalDesignerWorkspaceInfo; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/10 |
||||
*/ |
||||
public class WorkspaceUtils { |
||||
|
||||
private static final String SPECIFY_WORKSPACE = "fr.designer.workspace"; |
||||
|
||||
public static DesignerWorkspaceInfo getWorkspaceInfo() { |
||||
String workspacePath; |
||||
String current = DesignerEnvManager.getEnvManager().getCurEnvName(); |
||||
if (StringUtils.isNotEmpty(workspacePath = System.getProperty(SPECIFY_WORKSPACE))) { |
||||
return LocalDesignerWorkspaceInfo.create(StringUtils.EMPTY, workspacePath); |
||||
} else { |
||||
return DesignerEnvManager.getEnvManager().getWorkspaceInfo(current); |
||||
} |
||||
} |
||||
|
||||
} |
@ -0,0 +1,111 @@
|
||||
package com.fr.exit; |
||||
|
||||
import com.fr.config.dao.PropertiesConstants; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.stable.CommonUtils; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.project.ProjectConstants; |
||||
import com.fr.workspace.WorkContext; |
||||
import java.io.File; |
||||
import java.io.FileOutputStream; |
||||
import java.io.IOException; |
||||
import java.sql.Blob; |
||||
import java.sql.Connection; |
||||
import java.sql.DriverManager; |
||||
import java.sql.PreparedStatement; |
||||
import java.sql.ResultSet; |
||||
import java.sql.SQLException; |
||||
import java.util.Properties; |
||||
|
||||
/** |
||||
* 设计器关闭前的配置缓存一份到Properties |
||||
* |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/1 |
||||
*/ |
||||
public class ConfigToPropMigrator { |
||||
|
||||
private static final String SELECT_FOR_ENTITY = "select id, value from fine_conf_entity"; |
||||
|
||||
private static final String SELECT_FOR_CLASSNAME = "select id, classname from fine_conf_classname"; |
||||
|
||||
private static final String SELECT_FOR_XML_ENTITY = "select id, value from fine_conf_xmlentity"; |
||||
|
||||
private static final ConfigToPropMigrator INSTANCE = new ConfigToPropMigrator(); |
||||
|
||||
public static ConfigToPropMigrator getInstance() { |
||||
return INSTANCE; |
||||
} |
||||
|
||||
public void execute() { |
||||
|
||||
if (WorkContext.getCurrent().isLocal()) { |
||||
|
||||
String url = "jdbc:hsqldb:file://" + WorkContext.getCurrent().getPath() + "/" + ProjectConstants.EMBED_DB_DIRECTORY + "/finedb/db;hsqldb.tx=mvcc"; |
||||
|
||||
try { |
||||
Class.forName("com.fr.third.org.hsqldb.jdbcDriver"); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
return ; |
||||
} |
||||
|
||||
initDirectory(); |
||||
|
||||
try (Connection c = DriverManager.getConnection(url); |
||||
FileOutputStream entityOut = new FileOutputStream(PropertiesConstants.ENTITY_PROP_PATH); |
||||
FileOutputStream classHelperOut = new FileOutputStream(PropertiesConstants.CLASS_NAME_PROP_PATH); |
||||
FileOutputStream xmlEntityOut = new FileOutputStream(PropertiesConstants.XML_ENTITY_PROP_PATH)) { |
||||
|
||||
processClassOrEntity(c, new Properties(), SELECT_FOR_ENTITY, entityOut); |
||||
processClassOrEntity(c, new Properties(), SELECT_FOR_CLASSNAME, classHelperOut); |
||||
processXmlEntity(c, new Properties(), xmlEntityOut); |
||||
DesignerEnvManager.getEnvManager().setPropertiesUsable(true); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
deletePropertiesCache(); |
||||
} |
||||
} |
||||
} |
||||
|
||||
private void initDirectory() { |
||||
File directory = new File(StableUtils.pathJoin(WorkContext.getCurrent().getPath(), ProjectConstants.EMBED_DB_DIRECTORY, ProjectConstants.PROPERTIES_CACHE_FOR_CONFIG)); |
||||
if (!directory.exists()) { |
||||
directory.mkdir(); |
||||
} |
||||
} |
||||
|
||||
private void processClassOrEntity(Connection c, Properties map, String sql, FileOutputStream outputStream) throws SQLException, IOException { |
||||
PreparedStatement query = c.prepareStatement(sql); |
||||
ResultSet resultSet = query.executeQuery(); |
||||
while (resultSet.next()) { |
||||
String id = resultSet.getString(1); |
||||
String value = resultSet.getString(2); |
||||
if (id != null && value != null) { |
||||
map.setProperty(id, value); |
||||
} |
||||
} |
||||
map.store(outputStream, null); |
||||
} |
||||
|
||||
private void processXmlEntity(Connection c, Properties map, FileOutputStream outputStream) throws SQLException, IOException { |
||||
PreparedStatement query = c.prepareStatement(SELECT_FOR_XML_ENTITY); |
||||
ResultSet resultSet = query.executeQuery(); |
||||
while (resultSet.next()) { |
||||
String id = resultSet.getString(1); |
||||
Blob value = resultSet.getBlob(2); |
||||
byte[] bytes = value.getBytes(1L, (int) value.length()); |
||||
map.setProperty(id, new String(bytes)); |
||||
} |
||||
map.store(outputStream, null); |
||||
} |
||||
|
||||
public void deletePropertiesCache() { |
||||
CommonUtils.deleteFile(new File(PropertiesConstants.ENTITY_PROP_PATH)); |
||||
CommonUtils.deleteFile(new File(PropertiesConstants.XML_ENTITY_PROP_PATH)); |
||||
CommonUtils.deleteFile(new File(PropertiesConstants.CLASS_NAME_PROP_PATH)); |
||||
} |
||||
|
||||
} |
@ -0,0 +1,14 @@
|
||||
package com.fr.start.event; |
||||
|
||||
import com.fr.event.Event; |
||||
import com.fr.event.Null; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/7 |
||||
*/ |
||||
public enum LazyStartupEvent implements Event<Null> { |
||||
|
||||
INSTANCE |
||||
} |
@ -0,0 +1,30 @@
|
||||
package com.fr.start.module.optimized; |
||||
|
||||
import com.fr.config.activator.BaseDBActivator; |
||||
import com.fr.config.dao.DaoSelectorFactory; |
||||
import com.fr.event.Event; |
||||
import com.fr.event.Listener; |
||||
import com.fr.event.Null; |
||||
import com.fr.start.event.LazyStartupEvent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/7 |
||||
*/ |
||||
public class BaseDBActivator4Designer extends BaseDBActivator { |
||||
|
||||
@Override |
||||
public void start() { |
||||
if (DaoSelectorFactory.getDaoSelector().useCacheDao()) { |
||||
listenEvent(LazyStartupEvent.INSTANCE, new Listener<Null>(Integer.MAX_VALUE) { |
||||
@Override |
||||
public void on(Event event, Null param) { |
||||
BaseDBActivator4Designer.super.start(); |
||||
} |
||||
}); |
||||
} else { |
||||
super.start(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,27 @@
|
||||
package com.fr.start.module.optimized; |
||||
|
||||
import com.fr.config.activator.ConfigurationActivator; |
||||
import com.fr.config.dao.DaoContext; |
||||
import com.fr.config.dao.DaoSelectorFactory; |
||||
import com.fr.config.dao.impl.PropertiesClassHelperDao; |
||||
import com.fr.config.dao.impl.PropertiesEntityDao; |
||||
import com.fr.config.dao.impl.PropertiesXmlEntityDao; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/7 |
||||
*/ |
||||
public class ConfigurationActivator4Designer extends ConfigurationActivator { |
||||
|
||||
@Override |
||||
protected void initLocalDao() { |
||||
if (DaoSelectorFactory.getDaoSelector().useCacheDao()) { |
||||
DaoContext.setClassHelperDao(new PropertiesClassHelperDao()); |
||||
DaoContext.setEntityDao(new PropertiesEntityDao()); |
||||
DaoContext.setXmlEntityDao(new PropertiesXmlEntityDao()); |
||||
} else { |
||||
super.initLocalDao(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,42 @@
|
||||
package com.fr.start.module.optimized; |
||||
|
||||
import com.fr.config.dao.DaoSelectorFactory; |
||||
import com.fr.config.dao.swicter.DaoSwitcher; |
||||
import com.fr.design.DesignerEnvManager; |
||||
import com.fr.event.Event; |
||||
import com.fr.event.Listener; |
||||
import com.fr.event.Null; |
||||
import com.fr.exit.ConfigToPropMigrator; |
||||
import com.fr.stable.db.tenant.TenantDBAdapter; |
||||
import com.fr.start.event.LazyStartupEvent; |
||||
|
||||
/** |
||||
* @author hades |
||||
* @version 11.0 |
||||
* Created by hades on 2022/3/7 |
||||
*/ |
||||
public class TenantDBAdapter4Designer extends TenantDBAdapter { |
||||
|
||||
@Override |
||||
public void start() { |
||||
if (DaoSelectorFactory.getDaoSelector().useCacheDao()) { |
||||
listenEvent(LazyStartupEvent.INSTANCE, new Listener<Null>() { |
||||
@Override |
||||
public void on(Event event, Null param) { |
||||
TenantDBAdapter4Designer.super.start(); |
||||
afterStart(); |
||||
} |
||||
}); |
||||
|
||||
} else { |
||||
super.start(); |
||||
} |
||||
} |
||||
|
||||
private void afterStart() { |
||||
DaoSwitcher.executeSwitch(); |
||||
ConfigToPropMigrator.getInstance().deletePropertiesCache(); |
||||
DesignerEnvManager.getEnvManager().setPropertiesUsable(false); |
||||
DesignerEnvManager.getEnvManager().saveXMLFile(); |
||||
} |
||||
} |
Loading…
Reference in new issue