提交 c914c897 编写于 作者: R Ray

update dynamic

上级 ba385e5e
......@@ -17,18 +17,19 @@ import com.x.base.core.entity.annotation.CheckRemove;
public class EntityManagerContainerFactory extends SliceEntityManagerContainerFactory {
private volatile static EntityManagerContainerFactory instance;
private static EntityManagerContainerFactory instance;
public static void init(String webApplicationDirectory, List<String> entities) throws Exception {
public static void init(String webApplicationDirectory, List<String> entities, boolean loadDynamic)
throws Exception {
synchronized (EntityManagerContainerFactory.class) {
if (instance != null) {
EntityManagerContainerFactory.close();
}
instance = new EntityManagerContainerFactory(webApplicationDirectory, entities);
instance = new EntityManagerContainerFactory(webApplicationDirectory, entities, loadDynamic);
}
}
public static void init(String source) throws Exception {
public static void init(String source) {
synchronized (EntityManagerContainerFactory.class) {
if (instance != null) {
EntityManagerContainerFactory.close();
......@@ -37,7 +38,7 @@ public class EntityManagerContainerFactory extends SliceEntityManagerContainerFa
}
}
public static void init() throws Exception {
public static void init() {
synchronized (EntityManagerContainerFactory.class) {
if (instance != null) {
EntityManagerContainerFactory.close();
......@@ -46,27 +47,27 @@ public class EntityManagerContainerFactory extends SliceEntityManagerContainerFa
}
}
public static EntityManagerContainerFactory instance() throws Exception {
public static EntityManagerContainerFactory instance() {
if (instance == null) {
throw new Exception("get EntityManagerContainerFactory instance error, not initial.");
throw new IllegalStateException("get EntityManagerContainerFactory instance error, not initial.");
}
return instance;
}
private EntityManagerContainerFactory(String webApplicationDirectory, List<String> entities) throws Exception {
super(webApplicationDirectory, entities,false);
super(webApplicationDirectory, entities, false, false);
}
private EntityManagerContainerFactory(String webApplicationDirectory, List<String> entities,
boolean sliceFeatureEnable) throws Exception {
super(webApplicationDirectory, entities,sliceFeatureEnable);
private EntityManagerContainerFactory(String webApplicationDirectory, List<String> entities, boolean loadDynamic)
throws Exception {
super(webApplicationDirectory, entities, false, loadDynamic);
}
private EntityManagerContainerFactory(String source) throws Exception {
private EntityManagerContainerFactory(String source) {
super(source);
}
public static void close() throws Exception {
public static void close() {
try {
if (instance != null) {
for (EntityManagerFactory emf : instance.entityManagerFactoryMap.values()) {
......@@ -87,42 +88,49 @@ public class EntityManagerContainerFactory extends SliceEntityManagerContainerFa
/* 由于可能重新载入 */
instance = null;
} catch (Exception e) {
throw new Exception("close error.", e);
throw new IllegalStateException("close error.", e);
}
}
public EntityManagerContainer create() {
EntityManagerContainer container = new EntityManagerContainer(this);
return container;
return new EntityManagerContainer(this);
}
public <T extends JpaObject> EntityManager createEntityManager(Class<T> cls) throws Exception {
public <T extends JpaObject> EntityManager createEntityManager(Class<T> cls) {
try {
for (Class<?> clazz : entityManagerFactoryMap.keySet()) {
if (clazz.isAssignableFrom(cls)) {
return entityManagerFactoryMap.get(clazz).createEntityManager();
for (Map.Entry<Class<? extends JpaObject>, EntityManagerFactory> en : entityManagerFactoryMap.entrySet()) {
if (en.getKey().isAssignableFrom(cls)) {
return entityManagerFactoryMap.get(en.getKey()).createEntityManager();
}
}
throw new Exception("can not createEntityManager for class " + cls.getName()
throw new IllegalStateException("can not createEntityManager for class " + cls.getName()
+ ", not registed in EntityManagerContainerFactory.");
} catch (Exception e) {
throw new Exception("get entityManager for " + cls + " error.", e);
throw new IllegalStateException("get entityManager for " + cls + " error.", e);
}
}
public Map<Field, CheckPersist> getCheckPersistFields(Class<?> clazz) throws Exception {
public Map<Field, CheckPersist> getCheckPersistFields(Class<?> clazz) {
return checkPersistFieldMap.get(assignableFrom(clazz));
}
public Map<Field, CheckRemove> getCheckRemoveFields(Class<?> clazz) throws Exception {
public Map<Field, CheckRemove> getCheckRemoveFields(Class<?> clazz) {
return checkRemoveFieldMap.get(assignableFrom(clazz));
}
public List<Field> getFlagFields(Class<?> clazz) throws Exception {
public List<Field> getFlagFields(Class<?> clazz) {
return flagMap.get(assignableFrom(clazz));
}
public List<Field> getRestrictFlagFields(Class<?> clazz) throws Exception {
public List<Field> getRestrictFlagFields(Class<?> clazz) {
return restrictFlagMap.get(assignableFrom(clazz));
}
public static void refresh(String webApplicationDirectory, List<String> entities) throws Exception {
if (instance == null) {
throw new IllegalStateException("get EntityManagerContainerFactory instance error, not initial.");
}
instance.refreshDynamicEntity(webApplicationDirectory, entities);
}
}
......@@ -5,15 +5,8 @@ import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import com.x.base.core.container.FactorDistributionPolicy;
import com.x.base.core.entity.dynamic.DynamicBaseEntity;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.dynamic.DynamicEntity;
import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Node;
import com.x.base.core.project.tools.ListTools;
import java.util.Set;
import java.util.TreeSet;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.BooleanUtils;
......@@ -26,6 +19,21 @@ import org.dom4j.QName;
import org.dom4j.io.OutputFormat;
import org.dom4j.io.XMLWriter;
import com.x.base.core.container.FactorDistributionPolicy;
import com.x.base.core.entity.JpaObject;
import com.x.base.core.entity.annotation.ContainerEntity;
import com.x.base.core.entity.dynamic.DynamicBaseEntity;
import com.x.base.core.entity.dynamic.DynamicEntity;
import com.x.base.core.entity.tools.JpaObjectTools;
import com.x.base.core.project.config.Config;
import com.x.base.core.project.config.Node;
import com.x.base.core.project.tools.ClassLoaderTools;
import com.x.base.core.project.tools.ListTools;
import io.github.classgraph.ClassGraph;
import io.github.classgraph.ClassInfo;
import io.github.classgraph.ScanResult;
public class PersistenceXmlHelper {
private PersistenceXmlHelper() {
......@@ -147,7 +155,8 @@ public class PersistenceXmlHelper {
property.addAttribute("value", "false");
}
public static List<String> write(String path, List<String> entities, boolean dynamicFlag) throws Exception {
@SuppressWarnings("unchecked")
public static List<String> write(String path, List<String> entities, boolean loadDynamic) {
List<String> names = new ArrayList<>();
String name = "";
try {
......@@ -158,46 +167,44 @@ public class PersistenceXmlHelper {
persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
persistence.addAttribute("version", "2.0");
List<String> dyClasses = new ArrayList<>();
ClassLoader cl = Thread.currentThread().getContextClassLoader();
for (String className : names) {
name = className;
Class<? extends JpaObject> clazz = (Class<JpaObject>) Class.forName(className);
Class<? extends JpaObject> clazz = (Class<JpaObject>) cl.loadClass(className);
Element unit = persistence.addElement("persistence-unit");
unit.addAttribute("name", className);
unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
Element provider = unit.addElement("provider");
provider.addText(PersistenceProviderImpl.class.getName());
for (Class<?> o : JpaObjectTools.scanMappedSuperclass(clazz)) {
Element mapped_element = unit.addElement("class");
mapped_element.addText(o.getName());
}
}
if (dynamicFlag) {
for (String className : names) {
if (className.startsWith(DynamicEntity.CLASS_PACKAGE)) {
dyClasses.add(className);
}
}
if (!dyClasses.isEmpty()) {
String dyClassName = DynamicBaseEntity.class.getName();
names.add(dyClassName);
Element unit = persistence.addElement("persistence-unit");
unit.addAttribute("name", dyClassName);
unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
Element provider = unit.addElement("provider");
provider.addText(PersistenceProviderImpl.class.getName());
for (String dyClass : dyClasses) {
Element mapped_element = unit.addElement("class");
mapped_element.addText(dyClass);
}
for (Class<?> o : JpaObjectTools.scanMappedSuperclass(DynamicBaseEntity.class)) {
if (!o.getName().equals(DynamicBaseEntity.class.getName())) {
Element mapped_element = unit.addElement("class");
mapped_element.addText(o.getName());
}
}
}
unit.addElement("class").addText(o.getName());
}
}
if (loadDynamic) {
addDynamicClass(persistence);
// for (String className : names) {
// if (className.startsWith(DynamicEntity.CLASS_PACKAGE)) {
// dyClasses.add(className);
// }
// }
// if (!dyClasses.isEmpty()) {
// String dyClassName = DynamicBaseEntity.class.getName();
// names.add(dyClassName);
//
// Element unit = persistence.addElement("persistence-unit");
// unit.addAttribute("name", dyClassName);
// unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
// Element provider = unit.addElement("provider");
// provider.addText(PersistenceProviderImpl.class.getName());
// for (String dyClass : dyClasses) {
// unit.addElement("class").addText(dyClass);
// }
// for (Class<?> o : JpaObjectTools.scanMappedSuperclass(DynamicBaseEntity.class)) {
// if (!o.getName().equals(DynamicBaseEntity.class.getName())) {
// unit.addElement("class").addText(o.getName());
// }
// }
// }
}
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
......@@ -208,27 +215,52 @@ public class PersistenceXmlHelper {
writer.close();
return names;
} catch (Exception e) {
throw new Exception("write error.className:" + name, e);
throw new IllegalStateException("write error.className:" + name, e);
}
}
private static void addDynamicClass(Element persistence) throws Exception {
Set<String> names = new TreeSet<>();
ClassLoader cl = ClassLoaderTools.urlClassLoader(true, false, false, false, true);
try (ScanResult sr = new ClassGraph().addClassLoader(cl).enableAnnotationInfo().scan()) {
for (ClassInfo info : sr.getClassesWithAnnotation(ContainerEntity.class.getName())) {
Class<?> cls = cl.loadClass(info.getName());
if (StringUtils.startsWith(cls.getName(), DynamicEntity.CLASS_PACKAGE)) {
names.add(cls.getName());
for (Class<?> o : JpaObjectTools.scanMappedSuperclass(cls)) {
names.add(o.getName());
}
}
}
}
Element unit = persistence.addElement("persistence-unit");
unit.addAttribute("name", DynamicBaseEntity.class.getName());
unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
Element provider = unit.addElement("provider");
provider.addText(PersistenceProviderImpl.class.getName());
for (String name : names) {
unit.addElement("class").addText(name);
}
}
public static Properties properties(String className, boolean sliceFeatureEnable) throws Exception {
if (sliceFeatureEnable) {
if (Config.externalDataSources().enable()) {
return properties_external_slice(className);
if (BooleanUtils.isTrue(Config.externalDataSources().enable())) {
return propertiesExternalSlice(className);
} else {
return properties_internal_slice(className);
return propertiesInternalSlice(className);
}
} else {
if (Config.externalDataSources().enable()) {
return properties_external_single(className);
if (BooleanUtils.isTrue(Config.externalDataSources().enable())) {
return propertiesExternalSingle(className);
} else {
return properties_internal_single(className);
return propertiesInternalSingle(className);
}
}
}
private static Properties properties_base_slice(String className) throws Exception {
private static Properties propertiesBaseSlice(String className) throws Exception {
Properties properties = new Properties();
properties.put("openjpa.BrokerFactory", "slice");
properties.put("openjpa.slice.Lenient", "false");
......@@ -246,8 +278,8 @@ public class PersistenceXmlHelper {
return properties;
}
private static Properties properties_external_slice(String className) throws Exception {
Properties properties = properties_base_slice(className);
private static Properties propertiesExternalSlice(String className) throws Exception {
Properties properties = propertiesBaseSlice(className);
properties.put("openjpa.jdbc.DBDictionary", Config.externalDataSources().dictionary());
/* 如果是DB2 添加 Schema,mysql 不需要Schema 如果用了Schema H2数据库就会报错说没有Schema */
if (Config.externalDataSources().hasSchema()) {
......@@ -262,8 +294,8 @@ public class PersistenceXmlHelper {
return properties;
}
private static Properties properties_internal_slice(String className) throws Exception {
Properties properties = properties_base_slice(className);
private static Properties propertiesInternalSlice(String className) throws Exception {
Properties properties = propertiesBaseSlice(className);
properties.put("openjpa.jdbc.DBDictionary", SlicePropertiesBuilder.dictionary_h2);
properties.put("openjpa.slice.Names",
StringUtils.join(Config.nodes().dataServers().findNamesOfContainerEntity(className), ","));
......@@ -274,7 +306,7 @@ public class PersistenceXmlHelper {
return properties;
}
private static Properties properties_base_single(String className) throws Exception {
private static Properties propertiesBaseSingle(String className) throws Exception {
Properties properties = new Properties();
properties.put("openjpa.QueryCompilationCache", "false");
properties.put("openjpa.IgnoreChanges", "true");
......@@ -290,8 +322,8 @@ public class PersistenceXmlHelper {
return properties;
}
private static Properties properties_external_single(String className) throws Exception {
Properties properties = properties_base_single(className);
private static Properties propertiesExternalSingle(String className) throws Exception {
Properties properties = propertiesBaseSingle(className);
properties.put("openjpa.jdbc.DBDictionary", Config.externalDataSources().dictionary());
/* 如果是DB2 添加 Schema,mysql 不需要Schema 如果用了Schema H2数据库就会报错说没有Schema */
if (Config.externalDataSources().hasSchema()) {
......@@ -308,8 +340,8 @@ public class PersistenceXmlHelper {
return properties;
}
private static Properties properties_internal_single(String className) throws Exception {
Properties properties = properties_base_single(className);
private static Properties propertiesInternalSingle(String className) throws Exception {
Properties properties = propertiesBaseSingle(className);
properties.put("openjpa.jdbc.DBDictionary", SlicePropertiesBuilder.dictionary_h2);
for (String name : Config.nodes().dataServers().findNamesOfContainerEntity(className)) {
properties.put("openjpa.ConnectionFactoryName", Config.RESOURCE_JDBC_PREFIX + name);
......
......@@ -29,29 +29,33 @@ import com.x.base.core.entity.annotation.CheckPersist;
import com.x.base.core.entity.annotation.CheckRemove;
import com.x.base.core.entity.annotation.Flag;
import com.x.base.core.entity.annotation.RestrictFlag;
import com.x.base.core.entity.dynamic.DynamicBaseEntity;
import com.x.base.core.entity.dynamic.DynamicEntity;
public abstract class SliceEntityManagerContainerFactory {
protected static String META_INF = "META-INF";
protected static String PERSISTENCE_XML_PATH = META_INF + "/persistence.xml";
protected static final String META_INF = "META-INF";
protected static final String PERSISTENCE_XML_PATH = META_INF + "/persistence.xml";
/* class 与 entityManagerFactory 映射表 */
protected Map<Class<? extends JpaObject>, EntityManagerFactory> entityManagerFactoryMap = new ConcurrentHashMap<Class<? extends JpaObject>, EntityManagerFactory>();
protected Map<Class<? extends JpaObject>, EntityManagerFactory> entityManagerFactoryMap = new ConcurrentHashMap<>();
/* class 与 @Flag字段 映射表 */
protected Map<Class<? extends JpaObject>, List<Field>> flagMap = new ConcurrentHashMap<Class<? extends JpaObject>, List<Field>>();
protected Map<Class<? extends JpaObject>, List<Field>> flagMap = new ConcurrentHashMap<>();
/* class 与 entityManagerFactory 映射表 */
protected Map<Class<? extends JpaObject>, List<Field>> restrictFlagMap = new ConcurrentHashMap<Class<? extends JpaObject>, List<Field>>();
protected Map<Class<? extends JpaObject>, List<Field>> restrictFlagMap = new ConcurrentHashMap<>();
/* class 与 class 中需要检查 Persist 字段的对应表 */
protected Map<Class<? extends JpaObject>, Map<Field, CheckPersist>> checkPersistFieldMap = new ConcurrentHashMap<Class<? extends JpaObject>, Map<Field, CheckPersist>>();
protected Map<Class<? extends JpaObject>, Map<Field, CheckPersist>> checkPersistFieldMap = new ConcurrentHashMap<>();
/* class 与 class 中需要检查 Remove 字段的对应表 */
protected Map<Class<? extends JpaObject>, Map<Field, CheckRemove>> checkRemoveFieldMap = new ConcurrentHashMap<Class<? extends JpaObject>, Map<Field, CheckRemove>>();
protected Map<Class<? extends JpaObject>, Map<Field, CheckRemove>> checkRemoveFieldMap = new ConcurrentHashMap<>();
protected SliceEntityManagerContainerFactory(String webApplicationDirectory, List<String> entities,
boolean sliceFeatureEnable) throws Exception {
boolean sliceFeatureEnable, boolean loadDynmic) throws Exception {
File path = new File(webApplicationDirectory + "/WEB-INF/classes/" + PERSISTENCE_XML_PATH);
List<String> classNames = PersistenceXmlHelper.write(path.getAbsolutePath(), entities, true);
List<String> classNames = PersistenceXmlHelper.write(path.getAbsolutePath(), entities, loadDynmic);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
for (String className : classNames) {
Class<? extends JpaObject> clz = (Class<? extends JpaObject>) Class.forName(className);
@SuppressWarnings("unchecked")
Class<? extends JpaObject> clz = (Class<? extends JpaObject>) classLoader.loadClass(className);
checkPersistFieldMap.put(clz, this.loadCheckPersistField(clz));
checkRemoveFieldMap.put(clz, this.loadCheckRemoveField(clz));
Properties properties = PersistenceXmlHelper.properties(clz.getName(), sliceFeatureEnable);
......@@ -75,7 +79,7 @@ public abstract class SliceEntityManagerContainerFactory {
}
}
protected SliceEntityManagerContainerFactory(String source) throws Exception {
protected SliceEntityManagerContainerFactory(String source) {
Set<Class<? extends JpaObject>> classes = this.listUnitClass(source);
for (Class<? extends JpaObject> clz : classes) {
checkPersistFieldMap.put(clz, this.loadCheckPersistField(clz));
......@@ -100,17 +104,17 @@ public abstract class SliceEntityManagerContainerFactory {
}
@SuppressWarnings("unchecked")
public <T> Class<T> assignableFrom(Class<T> cls) throws Exception {
public <T> Class<T> assignableFrom(Class<T> cls) {
for (Class<?> clazz : this.entityManagerFactoryMap.keySet()) {
if (clazz.isAssignableFrom(cls)) {
return (Class<T>) clazz;
}
}
throw new Exception("can not find jpa assignable class for " + cls + ".");
throw new IllegalStateException("can not find jpa assignable class for " + cls + ".");
}
private <T extends JpaObject> Map<Field, CheckPersist> loadCheckPersistField(Class<T> cls) throws Exception {
Map<Field, CheckPersist> map = new HashMap<Field, CheckPersist>();
private <T extends JpaObject> Map<Field, CheckPersist> loadCheckPersistField(Class<T> cls) {
Map<Field, CheckPersist> map = new HashMap<>();
for (Field fld : cls.getDeclaredFields()) {
CheckPersist checkPersist = fld.getAnnotation(CheckPersist.class);
if (null != checkPersist) {
......@@ -120,8 +124,8 @@ public abstract class SliceEntityManagerContainerFactory {
return map;
}
private <T extends JpaObject> Map<Field, CheckRemove> loadCheckRemoveField(Class<T> cls) throws Exception {
Map<Field, CheckRemove> map = new HashMap<Field, CheckRemove>();
private <T extends JpaObject> Map<Field, CheckRemove> loadCheckRemoveField(Class<T> cls) {
Map<Field, CheckRemove> map = new HashMap<>();
for (Field fld : cls.getDeclaredFields()) {
CheckRemove checkRemove = fld.getAnnotation(CheckRemove.class);
if (null != checkRemove) {
......@@ -131,7 +135,8 @@ public abstract class SliceEntityManagerContainerFactory {
return map;
}
private Set<Class<? extends JpaObject>> listUnitClass(String source) throws Exception {
@SuppressWarnings("unchecked")
private Set<Class<? extends JpaObject>> listUnitClass(String source) {
try {
Set<Class<? extends JpaObject>> classes = new HashSet<>();
URL url;
......@@ -141,19 +146,53 @@ public abstract class SliceEntityManagerContainerFactory {
url = this.getClass().getClassLoader().getResource(source);
}
if (null == url) {
throw new Exception("can not load resource: " + source + ".");
throw new IllegalStateException("can not load resource: " + source + ".");
}
File file = new File(url.toURI());
SAXReader reader = new SAXReader();
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
Document document = reader.read(file);
for (Object o : document.getRootElement().elements("persistence-unit")) {
Element unit = (Element) o;
for (Element unit : document.getRootElement().elements("persistence-unit")) {
classes.add((Class<JpaObject>) Class.forName(unit.attribute("name").getValue()));
}
return classes;
} catch (Exception e) {
throw new Exception("list unit error:" + source, e);
throw new IllegalStateException("list unit error:" + source, e);
}
}
public void refreshDynamicEntity(String webApplicationDirectory, List<String> entities) throws Exception {
File path = new File(webApplicationDirectory + "/WEB-INF/classes/" + PERSISTENCE_XML_PATH);
List<String> classNames = PersistenceXmlHelper.write(path.getAbsolutePath(), entities, true);
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
for (String className : classNames) {
if (className.startsWith(DynamicEntity.CLASS_PACKAGE)
|| className.equals(DynamicBaseEntity.class.getName())) {
@SuppressWarnings("unchecked")
Class<? extends JpaObject> clz = (Class<? extends JpaObject>) classLoader.loadClass(className);
checkPersistFieldMap.put(clz, this.loadCheckPersistField(clz));
checkRemoveFieldMap.put(clz, this.loadCheckRemoveField(clz));
Properties properties = PersistenceXmlHelper.properties(clz.getName(), false);
entityManagerFactoryMap.put(clz,
OpenJPAPersistence.createEntityManagerFactory(clz.getName(), PERSISTENCE_XML_PATH, properties));
List<Field> flagFields = new ArrayList<>();
List<Field> restrictFlagFields = new ArrayList<>();
for (Field o : FieldUtils.getFieldsListWithAnnotation(clz, Id.class)) {
flagFields.add(o);
restrictFlagFields.add(o);
}
for (Field o : FieldUtils.getFieldsListWithAnnotation(clz, Flag.class)) {
flagFields.add(o);
restrictFlagFields.add(o);
}
for (Field o : FieldUtils.getFieldsListWithAnnotation(clz, RestrictFlag.class)) {
restrictFlagFields.add(o);
}
flagMap.put(clz, Collections.unmodifiableList(flagFields));
restrictFlagMap.put(clz, Collections.unmodifiableList(restrictFlagFields));
}
}
}
}
\ No newline at end of file
......@@ -131,15 +131,6 @@ public class Context extends AbstractContext {
private AbstractQueue<WrapClearCacheRequest> clearCacheRequestQueue;
// @Override
// public AbstractQueue<WrapClearCacheRequest> clearCacheRequestQueue() {
// return this.clearCacheRequestQueue;
// }
// public ThreadFactory threadFactory() {
// return this.threadFactory;
// }
/* 队列 */
private List<AbstractQueue<?>> queues;
......@@ -147,12 +138,14 @@ public class Context extends AbstractContext {
this.token = UUID.randomUUID().toString();
this.applications = new Applications();
this.queues = new ArrayList<>();
// this.scheduler = new StdSchedulerFactory(SchedulerFactoryProperties.concrete()).getScheduler();
// this.scheduler.getListenerManager().addJobListener(new JobReportListener(), EverythingMatcher.allJobs());
// this.scheduler.start();
}
public static Context concrete(ServletContextEvent servletContextEvent) throws Exception {
return concrete(servletContextEvent, false);
}
public static Context concrete(ServletContextEvent servletContextEvent, boolean loadDynamic) throws Exception {
// 强制忽略ssl服务器认证
SslTools.ignoreSsl();
ServletContext servletContext = servletContextEvent.getServletContext();
......@@ -167,7 +160,7 @@ public class Context extends AbstractContext {
context.weight = Config.currentNode().getApplication().weight(context.clazz);
context.scheduleWeight = Config.currentNode().getApplication().scheduleWeight(context.clazz);
context.sslEnable = Config.currentNode().getApplication().getSslEnable();
context.initDatas();
context.initDatas(loadDynamic);
servletContext.setAttribute(AbstractContext.class.getName(), context);
SchedulerFactoryProperties schedulerFactoryProperties = SchedulerFactoryProperties.concrete();
schedulerFactoryProperties.setProperty("org.quartz.scheduler.instanceName",
......@@ -196,10 +189,6 @@ public class Context extends AbstractContext {
JsonElement jsonElement = XGsonBuilder.instance().toJsonTree(application);
// 将当前的application写入到servletContext
servletContext.setAttribute(SERVLETCONTEXT_ATTRIBUTE_APPLICATION, jsonElement.toString());
// 发送注册到本地的信号
// JsonObject registApplicationLocal = jsonElement.getAsJsonObject();
// registApplicationLocal.addProperty("type", "registApplicationLocal");
// Config.resource_node_eventQueue().put(registApplicationLocal);
}
public <T extends AbstractJob> void scheduleLocal(Class<T> cls, String cron) throws Exception {
......@@ -284,7 +273,15 @@ public class Context extends AbstractContext {
if (ArrayUtils.isNotEmpty(this.module.containerEntities())) {
logger.info("{} loading datas, entity size:{}.", this.clazz.getName(),
this.module.containerEntities().length);
EntityManagerContainerFactory.init(path, ListTools.toList(this.module.containerEntities()));
EntityManagerContainerFactory.init(path, ListTools.toList(this.module.containerEntities()), false);
}
}
private void initDatas(boolean loadDynamic) throws Exception {
if (ArrayUtils.isNotEmpty(this.module.containerEntities())) {
logger.info("{} loading datas, entity size:{}.", this.clazz.getName(),
this.module.containerEntities().length);
EntityManagerContainerFactory.init(path, ListTools.toList(this.module.containerEntities()), loadDynamic);
}
}
......
......@@ -5,6 +5,35 @@ import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
//@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "流程设计", packageName = "com.x.processplatform.assemble.designer", containerEntities = {
// "com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.DocumentVersion",
// "com.x.processplatform.core.entity.content.Draft", "com.x.processplatform.core.entity.content.Attachment",
// "com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.ReadCompleted",
// "com.x.processplatform.core.entity.content.Review", "com.x.processplatform.core.entity.content.Record",
// "com.x.processplatform.core.entity.content.SerialNumber", "com.x.processplatform.core.entity.content.Task",
// "com.x.processplatform.core.entity.content.TaskCompleted", "com.x.processplatform.core.entity.content.Work",
// "com.x.processplatform.core.entity.content.WorkCompleted", "com.x.processplatform.core.entity.content.WorkLog",
// "com.x.processplatform.core.entity.content.Record", "com.x.processplatform.core.entity.element.Invoke",
// "com.x.processplatform.core.entity.element.Split", "com.x.processplatform.core.entity.element.File",
// "com.x.processplatform.core.entity.element.Form", "com.x.processplatform.core.entity.element.FormVersion",
// "com.x.processplatform.core.entity.element.FormField", "com.x.processplatform.core.entity.element.TemplateForm",
// "com.x.processplatform.core.entity.element.Application", "com.x.processplatform.core.entity.element.Script",
// "com.x.processplatform.core.entity.element.ScriptVersion", "com.x.processplatform.core.entity.element.Merge",
// "com.x.processplatform.core.entity.element.Agent", "com.x.processplatform.core.entity.element.Process",
// "com.x.processplatform.core.entity.element.ProcessVersion", "com.x.processplatform.core.entity.element.Choice",
// "com.x.processplatform.core.entity.element.Delay", "com.x.processplatform.core.entity.element.Parallel",
// "com.x.processplatform.core.entity.element.Begin", "com.x.processplatform.core.entity.element.Cancel",
// "com.x.processplatform.core.entity.element.Embed", "com.x.processplatform.core.entity.element.Service",
// "com.x.processplatform.core.entity.element.Manual", "com.x.processplatform.core.entity.element.Route",
// "com.x.processplatform.core.entity.element.End", "com.x.processplatform.core.entity.element.ApplicationDict",
// "com.x.processplatform.core.entity.element.ApplicationDictItem",
// "com.x.processplatform.core.entity.element.QueryView", "com.x.processplatform.core.entity.element.QueryStat",
// "com.x.processplatform.core.entity.element.Mapping", "com.x.query.core.entity.Item",
// "com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script",
// "com.x.query.dynamic.entity.*" }, storeJars = { "x_organization_core_entity", "x_organization_core_express",
// "x_processplatform_core_entity", "x_processplatform_core_express", "x_query_core_entity",
// "x_cms_core_entity", "x_portal_core_entity" }, dynamicJars = {
// "x_query_dynamic_entity", }, storageTypes = { StorageType.processPlatform })
@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "流程设计", packageName = "com.x.processplatform.assemble.designer", containerEntities = {
"com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.DocumentVersion",
"com.x.processplatform.core.entity.content.Draft", "com.x.processplatform.core.entity.content.Attachment",
......@@ -29,11 +58,10 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.processplatform.core.entity.element.ApplicationDictItem",
"com.x.processplatform.core.entity.element.QueryView", "com.x.processplatform.core.entity.element.QueryStat",
"com.x.processplatform.core.entity.element.Mapping", "com.x.query.core.entity.Item",
"com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script",
"com.x.query.dynamic.entity.*" }, storeJars = { "x_organization_core_entity", "x_organization_core_express",
"x_processplatform_core_entity", "x_processplatform_core_express", "x_query_core_entity",
"x_cms_core_entity", "x_portal_core_entity" }, dynamicJars = {
"x_query_dynamic_entity", }, storageTypes = { StorageType.processPlatform })
"com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script" }, storeJars = {
"x_organization_core_entity", "x_organization_core_express", "x_processplatform_core_entity",
"x_processplatform_core_express", "x_query_core_entity", "x_cms_core_entity",
"x_portal_core_entity" }, dynamicJars = {}, storageTypes = { StorageType.processPlatform })
public class x_processplatform_assemble_designer extends Deployable {
}
......@@ -5,6 +5,35 @@ import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
//@Module(type = ModuleType.SERVICE, category = ModuleCategory.OFFICIAL, name = "流程服务", packageName = "com.x.processplatform.service.processing", containerEntities = {
// "com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.Draft",
// "com.x.processplatform.core.entity.content.Attachment",
// "com.x.processplatform.core.entity.content.TaskCompleted",
// "com.x.processplatform.core.entity.content.ReadCompleted", "com.x.processplatform.core.entity.content.Review",
// "com.x.processplatform.core.entity.content.Record", "com.x.processplatform.core.entity.content.WorkCompleted",
// "com.x.processplatform.core.entity.content.WorkLog", "com.x.processplatform.core.entity.content.Record",
// "com.x.processplatform.core.entity.content.Task", "com.x.processplatform.core.entity.content.Work",
// "com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.DocumentVersion",
// "com.x.processplatform.core.entity.content.SerialNumber", "com.x.processplatform.core.entity.element.End",
// "com.x.processplatform.core.entity.content.DocSign", "com.x.processplatform.core.entity.content.DocSignScrawl",
// "com.x.processplatform.core.entity.element.Application",
// "com.x.processplatform.core.entity.element.ApplicationDict",
// "com.x.processplatform.core.entity.element.ApplicationDictItem",
// "com.x.processplatform.core.entity.element.Script", "com.x.processplatform.core.entity.element.Cancel",
// "com.x.processplatform.core.entity.element.Merge", "com.x.processplatform.core.entity.element.Route",
// "com.x.processplatform.core.entity.element.Choice", "com.x.processplatform.core.entity.element.Invoke",
// "com.x.processplatform.core.entity.element.Manual", "com.x.processplatform.core.entity.element.Parallel",
// "com.x.processplatform.core.entity.element.Begin", "com.x.processplatform.core.entity.element.Split",
// "com.x.processplatform.core.entity.element.Process", "com.x.processplatform.core.entity.element.Service",
// "com.x.processplatform.core.entity.element.Agent", "com.x.processplatform.core.entity.element.Delay",
// "com.x.processplatform.core.entity.element.File", "com.x.processplatform.core.entity.element.Form",
// "com.x.processplatform.core.entity.element.FormField", "com.x.processplatform.core.entity.element.Embed",
// "com.x.processplatform.core.entity.element.Mapping", "com.x.processplatform.core.entity.log.SignalStackLog",
// "com.x.query.core.entity.Item", "com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script",
// "com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform }, storeJars = {
// "x_organization_core_entity", "x_organization_core_express", "x_processplatform_core_entity",
// "x_processplatform_core_express", "x_query_core_entity", "x_cms_core_entity",
// "x_portal_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
@Module(type = ModuleType.SERVICE, category = ModuleCategory.OFFICIAL, name = "流程服务", packageName = "com.x.processplatform.service.processing", containerEntities = {
"com.x.processplatform.core.entity.content.Snap", "com.x.processplatform.core.entity.content.Draft",
"com.x.processplatform.core.entity.content.Attachment",
......@@ -29,11 +58,10 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.processplatform.core.entity.element.File", "com.x.processplatform.core.entity.element.Form",
"com.x.processplatform.core.entity.element.FormField", "com.x.processplatform.core.entity.element.Embed",
"com.x.processplatform.core.entity.element.Mapping", "com.x.processplatform.core.entity.log.SignalStackLog",
"com.x.query.core.entity.Item", "com.x.cms.core.entity.element.Script", "com.x.portal.core.entity.Script",
"com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform }, storeJars = {
"com.x.query.core.entity.Item", "com.x.cms.core.entity.element.Script",
"com.x.portal.core.entity.Script" }, storageTypes = { StorageType.processPlatform }, storeJars = {
"x_organization_core_entity", "x_organization_core_express", "x_processplatform_core_entity",
"x_processplatform_core_express", "x_query_core_entity", "x_cms_core_entity",
"x_portal_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
"x_processplatform_core_express", "x_query_core_entity", "x_cms_core_entity", "x_portal_core_entity" })
public class x_processplatform_service_processing extends Deployable {
}
......@@ -5,6 +5,25 @@ import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
//@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "数据查询设计", packageName = "com.x.query.assemble.designer", containerEntities = {
// "com.x.query.core.entity.program.Argument", "com.x.query.core.entity.Item", "com.x.query.core.entity.Query",
// "com.x.query.core.entity.View", "com.x.query.core.entity.Stat", "com.x.query.core.entity.Reveal",
// "com.x.query.core.entity.neural.Entry", "com.x.query.core.entity.neural.InText",
// "com.x.query.core.entity.neural.OutText", "com.x.query.core.entity.neural.InValue",
// "com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
// "com.x.query.core.entity.schema.Table", "com.x.query.core.entity.schema.Statement",
// "com.x.query.core.entity.ImportModel",
// "com.x.processplatform.core.entity.content.Review", "com.x.processplatform.core.entity.content.Work",
// "com.x.processplatform.core.entity.content.WorkCompleted", "com.x.processplatform.core.entity.content.Task",
// "com.x.processplatform.core.entity.content.TaskCompleted", "com.x.processplatform.core.entity.content.Read",
// "com.x.processplatform.core.entity.content.ReadCompleted","com.x.processplatform.core.entity.element.Process",
// "com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
// "com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo", "com.x.cms.core.entity.Review",
// "com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.Group",
// "com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform }, storeJars = {
// "x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
// "x_processplatform_core_entity", "x_cms_core_entity",
// "x_query_core_express" }, dynamicJars = { "x_query_dynamic_entity" })
@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "数据查询设计", packageName = "com.x.query.assemble.designer", containerEntities = {
"com.x.query.core.entity.program.Argument", "com.x.query.core.entity.Item", "com.x.query.core.entity.Query",
"com.x.query.core.entity.View", "com.x.query.core.entity.Stat", "com.x.query.core.entity.Reveal",
......@@ -12,17 +31,15 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.query.core.entity.neural.OutText", "com.x.query.core.entity.neural.InValue",
"com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
"com.x.query.core.entity.schema.Table", "com.x.query.core.entity.schema.Statement",
"com.x.query.core.entity.ImportModel",
"com.x.processplatform.core.entity.content.Review", "com.x.processplatform.core.entity.content.Work",
"com.x.processplatform.core.entity.content.WorkCompleted", "com.x.processplatform.core.entity.content.Task",
"com.x.processplatform.core.entity.content.TaskCompleted", "com.x.processplatform.core.entity.content.Read",
"com.x.processplatform.core.entity.content.ReadCompleted","com.x.processplatform.core.entity.element.Process",
"com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
"com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo", "com.x.cms.core.entity.Review",
"com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.Group",
"com.x.query.dynamic.entity.*" }, storageTypes = { StorageType.processPlatform }, storeJars = {
"com.x.query.core.entity.ImportModel", "com.x.processplatform.core.entity.content.Review",
"com.x.processplatform.core.entity.content.Work", "com.x.processplatform.core.entity.content.WorkCompleted",
"com.x.processplatform.core.entity.content.Task", "com.x.processplatform.core.entity.content.TaskCompleted",
"com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.ReadCompleted",
"com.x.processplatform.core.entity.element.Process", "com.x.processplatform.core.entity.content.Attachment",
"com.x.cms.core.entity.Document", "com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo",
"com.x.cms.core.entity.Review", "com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit",
"com.x.organization.core.entity.Group" }, storageTypes = { StorageType.processPlatform }, storeJars = {
"x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
"x_processplatform_core_entity", "x_cms_core_entity",
"x_query_core_express" }, dynamicJars = { "x_query_dynamic_entity" })
"x_processplatform_core_entity", "x_cms_core_entity", "x_query_core_express" })
public class x_query_assemble_designer extends Deployable {
}
......@@ -5,6 +5,32 @@ import com.x.base.core.project.annotation.Module;
import com.x.base.core.project.annotation.ModuleCategory;
import com.x.base.core.project.annotation.ModuleType;
//@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "数据查询", packageName = "com.x.query.assemble.surface", containerEntities = {
// "com.x.query.core.entity.program.Argument", "com.x.query.core.entity.Item", "com.x.query.core.entity.Query",
// "com.x.query.core.entity.View", "com.x.query.core.entity.Stat", "com.x.query.core.entity.Reveal",
// "com.x.query.core.entity.segment.Word", "com.x.query.core.entity.segment.Entry",
// "com.x.query.core.entity.neural.Entry", "com.x.query.core.entity.neural.InText",
// "com.x.query.core.entity.neural.OutText", "com.x.query.core.entity.neural.InValue",
// "com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
// "com.x.query.core.entity.schema.Table", "com.x.query.core.entity.schema.Statement",
// "com.x.query.core.entity.ImportModel","com.x.query.core.entity.ImportRecord",
// "com.x.query.core.entity.ImportRecordItem",
// "com.x.processplatform.core.entity.content.Task", "com.x.processplatform.core.entity.content.TaskCompleted",
// "com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.ReadCompleted",
// "com.x.processplatform.core.entity.content.Review", "com.x.processplatform.core.entity.content.Work",
// "com.x.processplatform.core.entity.content.WorkCompleted","com.x.processplatform.core.entity.element.Process",
// "com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
// "com.x.cms.core.entity.Review", "com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo",
// "com.x.cms.core.entity.Document", "com.x.cms.core.entity.DocumentViewRecord","com.x.cms.core.entity.DocumentCommentInfo",
// "com.x.cms.core.entity.element.File", "com.x.cms.core.entity.FileInfo",
// "com.x.cms.core.entity.DocumentCommentContent", "com.x.cms.core.entity.DocumentCommentCommend",
// "com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.Group",
// "com.x.organization.core.entity.Role", "com.x.organization.core.entity.Identity",
// "com.x.query.dynamic.entity.*", "com.x.general.core.entity.GeneralFile"},
// storageTypes = { StorageType.processPlatform, StorageType.cms, StorageType.general}, storeJars = {
// "x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
// "x_processplatform_core_entity", "x_cms_core_entity",
// "x_query_core_express", "x_general_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
@Module(type = ModuleType.ASSEMBLE, category = ModuleCategory.OFFICIAL, name = "数据查询", packageName = "com.x.query.assemble.surface", containerEntities = {
"com.x.query.core.entity.program.Argument", "com.x.query.core.entity.Item", "com.x.query.core.entity.Query",
"com.x.query.core.entity.View", "com.x.query.core.entity.Stat", "com.x.query.core.entity.Reveal",
......@@ -13,23 +39,23 @@ import com.x.base.core.project.annotation.ModuleType;
"com.x.query.core.entity.neural.OutText", "com.x.query.core.entity.neural.InValue",
"com.x.query.core.entity.neural.OutValue", "com.x.query.core.entity.neural.Model",
"com.x.query.core.entity.schema.Table", "com.x.query.core.entity.schema.Statement",
"com.x.query.core.entity.ImportModel","com.x.query.core.entity.ImportRecord",
"com.x.query.core.entity.ImportRecordItem",
"com.x.processplatform.core.entity.content.Task", "com.x.processplatform.core.entity.content.TaskCompleted",
"com.x.processplatform.core.entity.content.Read", "com.x.processplatform.core.entity.content.ReadCompleted",
"com.x.processplatform.core.entity.content.Review", "com.x.processplatform.core.entity.content.Work",
"com.x.processplatform.core.entity.content.WorkCompleted","com.x.processplatform.core.entity.element.Process",
"com.x.processplatform.core.entity.content.Attachment", "com.x.cms.core.entity.Document",
"com.x.cms.core.entity.Review", "com.x.cms.core.entity.AppInfo", "com.x.cms.core.entity.CategoryInfo",
"com.x.cms.core.entity.Document", "com.x.cms.core.entity.DocumentViewRecord","com.x.cms.core.entity.DocumentCommentInfo",
"com.x.query.core.entity.ImportModel", "com.x.query.core.entity.ImportRecord",
"com.x.query.core.entity.ImportRecordItem", "com.x.processplatform.core.entity.content.Task",
"com.x.processplatform.core.entity.content.TaskCompleted", "com.x.processplatform.core.entity.content.Read",
"com.x.processplatform.core.entity.content.ReadCompleted", "com.x.processplatform.core.entity.content.Review",
"com.x.processplatform.core.entity.content.Work", "com.x.processplatform.core.entity.content.WorkCompleted",
"com.x.processplatform.core.entity.element.Process", "com.x.processplatform.core.entity.content.Attachment",
"com.x.cms.core.entity.Document", "com.x.cms.core.entity.Review", "com.x.cms.core.entity.AppInfo",
"com.x.cms.core.entity.CategoryInfo", "com.x.cms.core.entity.Document",
"com.x.cms.core.entity.DocumentViewRecord", "com.x.cms.core.entity.DocumentCommentInfo",
"com.x.cms.core.entity.element.File", "com.x.cms.core.entity.FileInfo",
"com.x.cms.core.entity.DocumentCommentContent", "com.x.cms.core.entity.DocumentCommentCommend",
"com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit", "com.x.organization.core.entity.Group",
"com.x.organization.core.entity.Role", "com.x.organization.core.entity.Identity",
"com.x.query.dynamic.entity.*", "com.x.general.core.entity.GeneralFile"},
storageTypes = { StorageType.processPlatform, StorageType.cms, StorageType.general}, storeJars = {
"com.x.organization.core.entity.Person", "com.x.organization.core.entity.Unit",
"com.x.organization.core.entity.Group", "com.x.organization.core.entity.Role",
"com.x.organization.core.entity.Identity", "com.x.general.core.entity.GeneralFile" }, storageTypes = {
StorageType.processPlatform, StorageType.cms, StorageType.general }, storeJars = {
"x_query_core_entity", "x_organization_core_entity", "x_organization_core_express",
"x_processplatform_core_entity", "x_cms_core_entity",
"x_query_core_express", "x_general_core_entity" }, dynamicJars = { "x_query_dynamic_entity" })
"x_processplatform_core_entity", "x_cms_core_entity", "x_query_core_express",
"x_general_core_entity" })
public class x_query_assemble_surface extends Deployable {
}
......@@ -56,9 +56,9 @@ public class InstrumentationAgent {
if (Files.exists(base.resolve(CUSTOM_JARS))) {
load(base, CUSTOM_JARS);
}
if (Files.exists(base.resolve(DYNAMIC_JARS))) {
load(base, DYNAMIC_JARS);
}
// if (Files.exists(base.resolve(DYNAMIC_JARS))) {
// load(base, DYNAMIC_JARS);
// }
setLog4j2(base, args);
loadWithCfg(base, STORE_JARS);
loadWithCfg(base, ext());
......
......@@ -72,14 +72,13 @@ public class ResourceFactory {
}
public static void init() throws Exception {
ClassLoader cl = ClassLoaderTools.urlClassLoader(true, false, true, true, true, unzipCustomWar());
ClassLoader cl = ClassLoaderTools.urlClassLoader(true, false, true, true, false, unzipCustomWar());
try (ScanResult sr = new ClassGraph().addClassLoader(cl).enableAnnotationInfo().scan()) {
node();
containerEntities(cl, sr);
containerEntityNames(sr);
stroageContainerEntityNames(sr);
disableDruidMysqlUsePingMethod();
}
if (BooleanUtils.isTrue(Config.externalDataSources().enable())) {
external();
......
......@@ -93,12 +93,12 @@ public abstract class JettySeverTools {
jars.add(file.getAbsolutePath());
}
}
if (module.dynamicJars() != null && module.dynamicJars().length > 0) {
IOFileFilter filter = new WildcardFileFilter(DynamicEntity.JAR_PREFIX + "*.jar");
for (File o : FileUtils.listFiles(Config.dir_dynamic_jars(true), filter, null)) {
jars.add(o.getAbsolutePath());
}
}
// if (module.dynamicJars() != null && module.dynamicJars().length > 0) {
// IOFileFilter filter = new WildcardFileFilter(DynamicEntity.JAR_PREFIX + "*.jar");
// for (File o : FileUtils.listFiles(Config.dir_dynamic_jars(true), filter, null)) {
// jars.add(o.getAbsolutePath());
// }
// }
for (Path path : paths) {
if (Files.exists(path) && Files.isDirectory(path)) {
try (Stream<Path> stream = Files.walk(path, FileVisitOption.FOLLOW_LINKS)) {
......
......@@ -207,7 +207,7 @@ public class Context extends AbstractContext {
private void initDatas() throws Exception {
logger.print("{} loading datas, entity size:{}.", this.clazz.getName(), this.module.containerEntities().length);
EntityManagerContainerFactory.init(path, ListTools.toList(this.module.containerEntities()));
EntityManagerContainerFactory.init(path, ListTools.toList(this.module.containerEntities()), false);
}
private void checkDefaultRole(EntityManagerContainer emc) throws Exception {
......
......@@ -6,13 +6,19 @@ import javax.servlet.annotation.WebListener;
import com.x.base.core.project.Context;
/**
* web应用初始化
*
* @author sword
*/
@WebListener
public class ApplicationServletContextListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent servletContextEvent) {
try {
ThisApplication.context = Context.concrete(servletContextEvent);
Business.getClassLoader(true);
ThisApplication.setContext(Context.concrete(servletContextEvent, true));
ThisApplication.init();
ThisApplication.context().regist();
} catch (Exception e) {
......
......@@ -2,6 +2,9 @@ package com.x.query.assemble.designer;
import java.io.File;
import java.io.StringWriter;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
......@@ -19,10 +22,16 @@ import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
import org.apache.commons.io.filefilter.IOFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.container.factory.PersistenceXmlHelper;
import com.x.base.core.entity.dynamic.DynamicEntity;
import com.x.base.core.entity.dynamic.DynamicEntityBuilder;
......@@ -56,13 +65,15 @@ import com.x.query.core.entity.schema.Table;
*/
public class Business {
private static Logger logger = LoggerFactory.getLogger(Business.class);
private static final Logger LOGGER = LoggerFactory.getLogger(Business.class);
public static final String DOT_JAR = ".jar";
private static ClassLoader classLoader = null;
private EntityManagerContainer emc;
public Business(EntityManagerContainer emc) throws Exception {
public Business(EntityManagerContainer emc) {
this.emc = emc;
}
......@@ -70,9 +81,30 @@ public class Business {
return this.emc;
}
/**
* 获取包含自定义jar包的ClassLoader
*
* @param refresh
* @return
* @throws Exception
*/
public static synchronized ClassLoader getClassLoader(boolean refresh) throws Exception {
if (refresh || classLoader == null) {
List<URL> urlList = new ArrayList<>();
IOFileFilter filter = new WildcardFileFilter(DynamicEntity.JAR_PREFIX + "*" + DOT_JAR);
for (File o : FileUtils.listFiles(Config.dir_dynamic_jars(true), filter, null)) {
urlList.add(o.toURI().toURL());
}
classLoader = URLClassLoader.newInstance(urlList.toArray(new URL[urlList.size()]),
Thread.currentThread().getContextClassLoader());
Thread.currentThread().setContextClassLoader(classLoader);
}
return classLoader;
}
private Organization organization;
public Organization organization() throws Exception {
public Organization organization() {
if (null == this.organization) {
this.organization = new Organization(ThisApplication.context());
}
......@@ -153,7 +185,7 @@ public class Business {
public boolean controllable(EffectivePerson effectivePerson) throws Exception {
boolean result = false;
if (effectivePerson.isManager() || (this.organization().person().hasRole(effectivePerson,
if (effectivePerson.isManager() || BooleanUtils.isTrue(this.organization().person().hasRole(effectivePerson,
OrganizationDefinition.Manager, OrganizationDefinition.QueryManager))) {
result = true;
}
......@@ -162,7 +194,7 @@ public class Business {
public boolean editable(EffectivePerson effectivePerson, Query o) throws Exception {
boolean result = false;
if (effectivePerson.isManager() || (this.organization().person().hasRole(effectivePerson,
if (effectivePerson.isManager() || BooleanUtils.isTrue(this.organization().person().hasRole(effectivePerson,
OrganizationDefinition.Manager, OrganizationDefinition.QueryManager))) {
result = true;
}
......@@ -175,29 +207,27 @@ public class Business {
}
public boolean editable(EffectivePerson effectivePerson, Table o) throws Exception {
boolean result = false;
if (effectivePerson.isManager() || (this.organization().person().hasRole(effectivePerson,
if (effectivePerson.isManager() || BooleanUtils.isTrue(this.organization().person().hasRole(effectivePerson,
OrganizationDefinition.Manager, OrganizationDefinition.QueryManager))) {
result = true;
return true;
}
if (!result && (null != o)) {
if (null != o) {
if (ListTools.isEmpty(o.getEditPersonList()) && ListTools.isEmpty(o.getEditUnitList())) {
result = true;
if (!result) {
if (effectivePerson.isPerson(o.getEditPersonList())) {
result = true;
return true;
} else {
if (ListTools.isNotEmpty(o.getEditPersonList()) && effectivePerson.isPerson(o.getEditPersonList())) {
return true;
}
if (!result && ListTools.isNotEmpty(o.getEditUnitList())) {
if (ListTools.isNotEmpty(o.getEditUnitList())) {
List<String> units = this.organization().unit()
.listWithPerson(effectivePerson.getDistinguishedName());
if (ListTools.containsAny(units, o.getEditUnitList())) {
result = true;
}
return true;
}
}
}
}
return result;
return false;
}
public boolean executable(EffectivePerson effectivePerson, Statement o) throws Exception {
......@@ -208,8 +238,8 @@ public class Business {
}
if (!result) {
if (effectivePerson.isManager()
|| (this.organization().person().hasRole(effectivePerson, OrganizationDefinition.Manager,
OrganizationDefinition.QueryManager))
|| BooleanUtils.isTrue(this.organization().person().hasRole(effectivePerson,
OrganizationDefinition.Manager, OrganizationDefinition.QueryManager))
|| effectivePerson.isPerson(o.getExecutePersonList())) {
result = true;
}
......@@ -228,19 +258,20 @@ public class Business {
public boolean buildAllTable() throws Exception {
File jar = new File(Config.dir_dynamic_jars(true), DynamicEntity.JAR_NAME + DOT_JAR);
List<Query> queryList = emc.fetchAll(Query.class);
for(Query query : queryList){
this.buildAllTable(query.getId());
for (Query q : queryList) {
this.buildAllTable(q.getId());
}
if(jar.exists()){
jar.delete();
if (jar.exists()) {
Files.delete(jar.toPath());
}
return true;
}
public boolean buildAllTable(String query) throws Exception {
boolean result = false;
List<Table> tables = emc.listEqualAndEqual(Table.class, Table.status_FIELDNAME, Table.STATUS_build, Table.query_FIELDNAME, query);
if(ListTools.isEmpty(tables)){
List<Table> tables = emc.listEqualAndEqual(Table.class, Table.status_FIELDNAME, Table.STATUS_build,
Table.query_FIELDNAME, query);
if (ListTools.isEmpty(tables)) {
return true;
}
File dir = new File(Config.dir_local_temp_dynamic(true), StringTools.uniqueToken());
......@@ -265,7 +296,7 @@ public class Business {
t.setBuildSuccess(true);
emc.commit();
} catch (Exception e) {
logger.error(e);
LOGGER.error(e);
}
}
if (!classNames.isEmpty()) {
......@@ -289,10 +320,10 @@ public class Business {
Iterable<JavaFileObject> res = fileManager.list(StandardLocation.SOURCE_PATH, DynamicEntity.CLASS_PACKAGE,
EnumSet.of(JavaFileObject.Kind.SOURCE), true);
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>();
DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<>();
StringWriter out = new StringWriter();
if (!compiler.getTask(out, fileManager, diagnostics, null, null, res).call()) {
if (BooleanUtils.isFalse(compiler.getTask(out, fileManager, diagnostics, null, null, res).call())) {
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics.getDiagnostics()) {
out.append("Error on line " + diagnostic.getLineNumber() + " in " + diagnostic).append('\n');
}
......@@ -305,6 +336,8 @@ public class Business {
File jar = new File(Config.dir_dynamic_jars(true), DynamicEntity.JAR_PREFIX + query + DOT_JAR);
JarTools.jar(target, jar);
LOGGER.info("build table reload jar:{}", jar.getName());
this.reloadClass(classNames);
}
FileUtils.cleanDirectory(dir);
return result;
......@@ -323,7 +356,7 @@ public class Business {
+ StringUtils.join(paths, File.pathSeparator) + "\" " + Enhance.class.getName() + " \""
+ target.getAbsolutePath() + "\"";
logger.debug("enhance command:{}.", command);
LOGGER.debug("enhance command:{}.", () -> command);
ProcessBuilder processBuilder = new ProcessBuilder();
......@@ -333,13 +366,37 @@ public class Business {
processBuilder.command("sh", "-c", command);
}
Process process = processBuilder.start();
Process p = processBuilder.start();
String resp = IOUtils.toString(process.getErrorStream(), DefaultCharset.charset_utf_8);
String resp = IOUtils.toString(p.getErrorStream(), DefaultCharset.charset_utf_8);
process.destroy();
p.destroy();
logger.info("enhance result:{}.", resp);
LOGGER.info("enhance result:{}.", () -> resp);
}
private void reloadClass(List<String> classNames) {
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
System.out.println("reloadClass");
System.out.println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Gson gson = new GsonBuilder().serializeNulls().create();
try {
ClassLoader cl = getClassLoader(true);
@SuppressWarnings("unchecked")
List<String> entityList = (List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES);
for (String className : classNames) {
Object jpaObject = cl.loadClass(className).getDeclaredConstructor().newInstance();
LOGGER.info("reload entity {} info:{}", className, gson.toJson(jpaObject));
if (!entityList.contains(className)) {
entityList.add(className);
}
}
EntityManagerContainerFactory.refresh(ThisApplication.context().path(),
ListTools.toList(ThisApplication.context().module().containerEntities()));
} catch (Exception e) {
LOGGER.error(e);
}
}
}
......@@ -15,6 +15,10 @@ public class ThisApplication {
return context;
}
protected static void setContext(Context context) {
ThisApplication.context = context;
}
public static void init() {
try {
CacheManager.init(context.clazz().getSimpleName());
......
......@@ -12,7 +12,7 @@ import com.x.query.assemble.designer.Business;
class ActionBuild extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionBuild.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ActionBuild.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson) throws Exception {
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
......@@ -24,7 +24,7 @@ class ActionBuild extends BaseAction {
}
wo.setValue(business.buildAllTable());
logger.print("build table complete!");
LOGGER.print("build table complete!");
result.setData(wo);
return result;
......
package com.x.query.assemble.designer.jaxrs.table;
import java.util.Date;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
......
......@@ -16,6 +16,7 @@ import com.x.query.core.entity.Query;
import com.x.query.core.entity.schema.Table;
import java.io.File;
import java.nio.file.Files;
import java.util.List;
class ActionBuildTable extends BaseAction {
......@@ -34,13 +35,14 @@ class ActionBuildTable extends BaseAction {
if (null == curQuery) {
throw new ExceptionEntityNotExist(queryId, Query.class);
}
// 兼容老版本的jar,删除统一的一个jar
File jar = new File(Config.dir_dynamic_jars(true), DynamicEntity.JAR_NAME + Business.DOT_JAR);
if(jar.exists()){
List<Query> queryList = emc.fetchAll(Query.class);
for(Query query : queryList){
business.buildAllTable(query.getId());
}
jar.delete();
Files.delete(jar.toPath());
wo.setValue(true);
}else {
wo.setValue(business.buildAllTable(queryId));
......
package com.x.query.assemble.designer.jaxrs.table;
import java.util.List;
import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.Application;
import com.x.base.core.project.x_query_assemble_designer;
import com.x.base.core.project.connection.CipherConnectionAction;
import com.x.base.core.project.exception.ExceptionAccessDenied;
import com.x.base.core.project.exception.ExceptionEntityNotExist;
......@@ -12,17 +16,13 @@ import com.x.base.core.project.jaxrs.WrapBoolean;
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
import com.x.base.core.project.tools.ListTools;
import com.x.base.core.project.x_query_assemble_designer;
import com.x.query.assemble.designer.Business;
import com.x.query.assemble.designer.ThisApplication;
import com.x.query.core.entity.Query;
import com.x.query.core.entity.schema.Table;
import java.util.List;
class ActionBuildTableDispatch extends BaseAction {
private static Logger logger = LoggerFactory.getLogger(ActionBuildTableDispatch.class);
private static final Logger LOGGER = LoggerFactory.getLogger(ActionBuildTableDispatch.class);
ActionResult<Wo> execute(EffectivePerson effectivePerson, String queryId) throws Exception {
ActionResult<Wo> result = new ActionResult<>();
......@@ -41,7 +41,7 @@ class ActionBuildTableDispatch extends BaseAction {
if (ListTools.isNotEmpty(apps)) {
apps.stream().forEach(o -> {
String url = o.getUrlJaxrsRoot() + "table/"+ queryId +"/build?tt="+System.currentTimeMillis();
logger.info("{} do dispatch build query {} table request to : {}", effectivePerson.getDistinguishedName(), queryId, url);
LOGGER.info("{} do dispatch build query {} table request to : {}.", effectivePerson.getDistinguishedName(), queryId, url);
try {
CipherConnectionAction.get(effectivePerson.getDebugger(), url);
} catch (Exception e) {
......
......@@ -19,6 +19,8 @@ import com.x.query.core.entity.schema.Table;
class ActionRowInsert extends BaseAction {
ActionResult<Wo> execute(EffectivePerson effectivePerson, String tableFlag, JsonElement jsonElement)
throws Exception {
ClassLoader cl = Business.getClassLoader(false);
Thread.currentThread().setContextClassLoader(cl);
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
ActionResult<Wo> result = new ActionResult<>();
Table table = emc.flag(tableFlag, Table.class);
......@@ -29,13 +31,14 @@ class ActionRowInsert extends BaseAction {
this.check(effectivePerson, business, table);
DynamicEntity dynamicEntity = new DynamicEntity(table.getName());
@SuppressWarnings("unchecked")
Class<? extends JpaObject> cls = (Class<JpaObject>) Class.forName(dynamicEntity.className());
// Class<? extends JpaObject> cls = (Class<JpaObject>)
// Class.forName(dynamicEntity.className());
Class<? extends JpaObject> cls = (Class<? extends JpaObject>) cl.loadClass(dynamicEntity.className());
List<Object> os = new ArrayList<>();
if (jsonElement.isJsonArray()) {
jsonElement.getAsJsonArray().forEach(o -> {
os.add(gson.fromJson(o, cls));
});
jsonElement.getAsJsonArray().forEach(o -> os.add(gson.fromJson(o, cls)));
} else if (jsonElement.isJsonObject()) {
os.add(gson.fromJson(jsonElement, cls));
}
......@@ -46,7 +49,7 @@ class ActionRowInsert extends BaseAction {
emc.commit();
Wo wo = new Wo();
for (Object o : os) {
wo.addValue(((JpaObject)o).getId(), true);
wo.addValue(((JpaObject) o).getId(), true);
}
result.setData(wo);
return result;
......@@ -55,6 +58,8 @@ class ActionRowInsert extends BaseAction {
public static class Wo extends WrapStringList {
private static final long serialVersionUID = 8695439000472972753L;
}
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册