Revision 1a1e2ca4
Added by Andreas Müller 9 months ago
.gitignore | ||
---|---|---|
11 | 11 |
.externalToolBuilders |
12 | 12 |
error.log |
13 | 13 |
cdmlib-developer.log |
14 |
workbench.xmi |
|
14 | 15 |
|
15 | 16 |
src/main/resources/dbscripts |
16 | 17 |
|
18 |
cdmlib-cache/src/main/resources/eu/etaxonomy/cdm/mappings/cdm.map.ser |
|
19 |
cdmlib-cache/eu.etaxonomy.cdm.model.description.DescriptionElementBase/segments_1 |
|
20 |
cdmlib-cache/eu.etaxonomy.cdm.model.description.DescriptionElementBase/write.lock |
|
21 |
cdmlib-cache/eu.etaxonomy.cdm.model.name.TaxonName/segments_1 |
|
22 |
cdmlib-cache/eu.etaxonomy.cdm.model.name.TaxonName/write.lock |
|
23 |
cdmlib-cache/eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase/segments_1 |
|
24 |
cdmlib-cache/eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase/write.lock |
|
25 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.Classification/segments_1 |
|
26 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.Classification/write.lock |
|
27 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonBase/segments_1 |
|
28 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonBase/write.lock |
|
29 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonRelationship/segments_1 |
|
30 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonRelationship/write.lock |
|
31 |
|
|
17 | 32 |
cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/ResultWrapper.java |
33 |
|
|
34 |
cdmlib-ext/KmlJaxbMarshallerTest.kml |
|
35 |
|
|
18 | 36 |
cdmlib-io/cdmlib-io.uml |
19 | 37 |
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/markup/Markup_OLD.java |
20 | 38 |
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/database/schema/PUBLIC.xsd |
... | ... | |
23 | 41 |
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/meta.xml |
24 | 42 |
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dwca/in/vernacular.txt |
25 | 43 |
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/jaxb/CdmImporterTest.xml.edited |
44 |
|
|
26 | 45 |
cdmlib-model/ajcore.*.txt |
27 | 46 |
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/ParserProblemRange.java |
28 | 47 |
|
29 | 48 |
cdmlib-persistence/002_cdm.dll |
30 | 49 |
cdmlib-persistence/NewDataSet.xml |
31 |
|
|
32 | 50 |
cdmlib-persistence/cdmlib-persistence.uml |
33 |
|
|
34 | 51 |
cdmlib-persistence/src/test/resources/Copy[!!-~]of[!!-~]test.cdm.datasource.xml |
35 | 52 |
cdmlib-persistence/src/test/resources/dbscripts/Kopie[!!-~]von[!!-~]001_cdm.ddl |
36 |
|
|
37 | 53 |
cdmlib-persistence/test.xml |
54 |
|
|
38 | 55 |
cdmlib-print/*odf_output.odf |
39 | 56 |
|
40 | 57 |
cdmlib-services/CleanSweepInsertLoadStrategy-debug.xml |
41 |
|
|
42 | 58 |
cdmlib-services/cdmlib-services.uml |
43 | 59 |
cdmlib-services/src/main/resources/log4j.properties |
44 |
|
|
45 | 60 |
cdmlib-services/src/test/resources/eu/etaxonomy/cdm/integrationTest.xml |
46 | 61 |
|
47 | 62 |
!cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/specimen/abcd206/in/ggbn/.settings |
48 | 63 |
!cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/data/.settings |
49 | 64 |
!cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/database/update/v35_36/.settings |
50 |
workbench.xmi |
|
51 |
cdmlib-ext/KmlJaxbMarshallerTest.kml |
|
52 |
cdmlib-cache/eu.etaxonomy.cdm.model.description.DescriptionElementBase/segments_1 |
|
53 |
cdmlib-cache/eu.etaxonomy.cdm.model.description.DescriptionElementBase/write.lock |
|
54 |
cdmlib-cache/eu.etaxonomy.cdm.model.name.TaxonName/segments_1 |
|
55 |
cdmlib-cache/eu.etaxonomy.cdm.model.name.TaxonName/write.lock |
|
56 |
cdmlib-cache/eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase/segments_1 |
|
57 |
cdmlib-cache/eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase/write.lock |
|
58 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.Classification/segments_1 |
|
59 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.Classification/write.lock |
|
60 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonBase/segments_1 |
|
61 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonBase/write.lock |
|
62 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonRelationship/segments_1 |
|
63 |
cdmlib-cache/eu.etaxonomy.cdm.model.taxon.TaxonRelationship/write.lock |
cdmlib-cache/pom.xml | ||
---|---|---|
14 | 14 |
<description>CDM Entity Cache</description> |
15 | 15 |
<build> |
16 | 16 |
<plugins> |
17 |
<plugin> |
|
18 |
<groupId>org.codehaus.mojo</groupId> |
|
19 |
<artifactId>exec-maven-plugin</artifactId> |
|
20 |
<version>3.0.0</version> |
|
21 |
<executions> |
|
22 |
<execution> |
|
23 |
<phase>process-resources</phase> |
|
24 |
<goals> |
|
25 |
<goal>exec</goal> |
|
26 |
</goals> |
|
27 |
</execution> |
|
28 |
</executions> |
|
29 |
<configuration> |
|
30 |
<executable>java</executable> |
|
31 |
<arguments> |
|
32 |
<argument>-classpath</argument> |
|
33 |
<classpath/> |
|
34 |
<argument>eu.etaxonomy.cdm.cache.CdmModelCacher</argument> |
|
35 |
</arguments> |
|
36 |
<!-- <mainClass>eu.etaxonomy.cdm.cache.CdmModelCacher</mainClass> |
|
37 |
<cleanupDaemonThreads>true</cleanupDaemonThreads> |
|
38 |
<stopUnresponsiveDaemonThreads>false</stopUnresponsiveDaemonThreads> --> |
|
39 |
</configuration> |
|
40 |
</plugin> |
|
17 | 41 |
</plugins> |
42 |
<pluginManagement> |
|
43 |
<plugins> |
|
44 |
<!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> |
|
45 |
<plugin> |
|
46 |
<groupId>org.eclipse.m2e</groupId> |
|
47 |
<artifactId>lifecycle-mapping</artifactId> |
|
48 |
<version>1.0.0</version> |
|
49 |
<configuration> |
|
50 |
<lifecycleMappingMetadata> |
|
51 |
<pluginExecutions> |
|
52 |
<pluginExecution> |
|
53 |
<pluginExecutionFilter> |
|
54 |
<groupId>org.codehaus.mojo</groupId> |
|
55 |
<artifactId>exec-maven-plugin</artifactId> |
|
56 |
<versionRange>[3.0.0,)</versionRange> |
|
57 |
<phase>process-resources</phase> |
|
58 |
<goals> |
|
59 |
<goal>exec</goal> |
|
60 |
</goals> |
|
61 |
</pluginExecutionFilter> |
|
62 |
<action> |
|
63 |
<ignore></ignore> |
|
64 |
</action> |
|
65 |
</pluginExecution> |
|
66 |
</pluginExecutions> |
|
67 |
</lifecycleMappingMetadata> |
|
68 |
</configuration> |
|
69 |
</plugin> |
|
70 |
</plugins> |
|
71 |
</pluginManagement> |
|
18 | 72 |
</build> |
19 | 73 |
<dependencies> |
20 | 74 |
<dependency> |
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmModelCacher.java | ||
---|---|---|
15 | 15 |
import java.io.ObjectInputStream; |
16 | 16 |
import java.io.ObjectOutputStream; |
17 | 17 |
import java.lang.reflect.Field; |
18 |
import java.net.URISyntaxException; |
|
19 | 18 |
import java.net.URL; |
19 |
import java.util.Collection; |
|
20 | 20 |
import java.util.HashMap; |
21 | 21 |
import java.util.Iterator; |
22 | 22 |
import java.util.Map; |
23 | 23 |
|
24 | 24 |
import org.apache.logging.log4j.LogManager; |
25 | 25 |
import org.apache.logging.log4j.Logger; |
26 |
import org.hibernate.SessionFactory; |
|
27 | 26 |
import org.hibernate.boot.Metadata; |
28 | 27 |
import org.hibernate.boot.MetadataSources; |
29 | 28 |
import org.hibernate.boot.registry.StandardServiceRegistry; |
... | ... | |
31 | 30 |
import org.hibernate.cfg.Configuration; |
32 | 31 |
import org.hibernate.mapping.PersistentClass; |
33 | 32 |
import org.hibernate.mapping.Property; |
34 |
import org.hibernate.metadata.ClassMetadata; |
|
35 | 33 |
import org.hibernate.property.access.spi.Getter; |
36 | 34 |
|
37 | 35 |
import net.sf.ehcache.Cache; |
38 |
import net.sf.ehcache.Element; |
|
39 | 36 |
|
40 | 37 |
/** |
41 | 38 |
* This class is serializing and deserializing the CDM model for performance purposes. |
... | ... | |
55 | 52 |
public static final String CDM_MAP_SER_FOLDER = "/eu/etaxonomy/cdm/mappings/"; |
56 | 53 |
public static final String CDM_MAP_SER_FILE_PATH = CDM_MAP_SER_FOLDER + CDM_MAP_SER_FILE; |
57 | 54 |
|
58 |
public void cacheGetterFields(Cache cache) throws IOException, ClassNotFoundException, URISyntaxException {
|
|
55 |
public void cacheGetterFields(Cache cache) throws IOException, ClassNotFoundException { |
|
59 | 56 |
Map<String, CdmModelFieldPropertyFromClass> modelClassMap = loadModelClassMap(); |
60 | 57 |
|
61 | 58 |
cache.removeAll(); |
62 | 59 |
|
63 | 60 |
for(Map.Entry<String, CdmModelFieldPropertyFromClass> entry : modelClassMap.entrySet()) { |
64 |
cache.put(new Element(entry.getKey(), entry.getValue())); |
|
61 |
cache.put(new net.sf.ehcache.Element(entry.getKey(), entry.getValue()));
|
|
65 | 62 |
} |
66 | 63 |
} |
67 | 64 |
|
68 |
public Map<String, CdmModelFieldPropertyFromClass> loadModelClassMap() throws URISyntaxException, IOException, ClassNotFoundException {
|
|
65 |
public Map<String, CdmModelFieldPropertyFromClass> loadModelClassMap() throws IOException, ClassNotFoundException { |
|
69 | 66 |
|
70 |
// ============== Eclpipse specific ============== // |
|
71 |
/*Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib"); |
|
72 | 67 |
|
73 |
URL modelMapFileBundleURL = bundle.getEntry(CDM_MAP_SER_FILE_PATH); |
|
74 |
URL modelMapFileURL = FileLocator.resolve(modelMapFileBundleURL); |
|
75 |
String modelMapFilePath = modelMapFileURL.getFile(); |
|
76 |
FileInputStream fin = new FileInputStream(modelMapFilePath); |
|
77 |
*/ |
|
78 | 68 |
InputStream fin = this.getClass().getResourceAsStream(CDM_MAP_SER_FILE_PATH); |
79 |
// ==============000000000000000 ============== // |
|
80 |
|
|
81 | 69 |
ObjectInputStream ois = new ObjectInputStream(fin); |
82 | 70 |
@SuppressWarnings("unchecked") |
83 | 71 |
Map<String, CdmModelFieldPropertyFromClass> modelClassMap = (Map<String, CdmModelFieldPropertyFromClass>) ois.readObject(); |
... | ... | |
92 | 80 |
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder() |
93 | 81 |
.configure(hibernateConfigFile) // configures settings from hibernate.cfg.xml |
94 | 82 |
.build(); |
95 |
SessionFactory sessionFactory = null; |
|
83 |
|
|
96 | 84 |
Map<String, CdmModelFieldPropertyFromClass> modelClassMap = new HashMap<>(); |
97 | 85 |
try { |
98 | 86 |
// ConnectionProvider connectionProvider = registry.getService(ConnectionProvider.class); |
99 | 87 |
// DatasourceConnectionProviderImpl providerImpl = registry.getService(DatasourceConnectionProviderImpl.class); |
100 | 88 |
|
101 | 89 |
Metadata metadata = new MetadataSources( registry ).buildMetadata(); |
102 |
sessionFactory = metadata.buildSessionFactory(); |
|
103 |
// Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH); |
|
104 |
|
|
105 |
Map<String, ClassMetadata> classMetaDataMap = sessionFactory.getAllClassMetadata(); |
|
106 |
// Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build(); |
|
107 |
|
|
108 |
for(ClassMetadata classMetaData : classMetaDataMap.values()) { |
|
109 |
Class<?> mappedClass = classMetaData.getMappedClass(); |
|
110 |
|
|
111 |
String mappedClassName = mappedClass.getName(); |
|
112 |
|
|
113 |
PersistentClass persistentClass = metadata.getEntityBinding(mappedClassName); |
|
114 |
CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); |
|
115 |
logger.warn("Adding class : " + mappedClassName + " to cache"); |
|
116 |
addGetters(persistentClass, cmgmfc); |
|
117 |
modelClassMap.put(mappedClassName, cmgmfc); |
|
90 |
Collection<PersistentClass> entityBindings = metadata.getEntityBindings(); |
|
91 |
for (PersistentClass persistentClass : entityBindings) { |
|
92 |
Class<?> mappedClass = persistentClass.getMappedClass(); |
|
93 |
if (mappedClass != null) { |
|
94 |
handleEntityClass(modelClassMap, metadata, mappedClass); |
|
95 |
} |
|
118 | 96 |
} |
97 |
|
|
98 |
// Class<?> epc = entityBindings.iterator().next().getMappedClass(); |
|
99 |
|
|
100 |
//SessionFactory sessionFactory = metadata.buildSessionFactory(); |
|
101 |
// Metamodel metaModel = sessionFactory.getMetamodel(); |
|
102 |
// Set<EntityType<?>> entityTypes = metaModel.getEntities(); |
|
103 |
// for (EntityType<?> entityType : entityTypes) { |
|
104 |
// Class<?> mappedClass = entityType.getJavaType(); |
|
105 |
// handleEntityClass(modelClassMap, metadata, mappedClass); |
|
106 |
// } |
|
107 |
// sessionFactory.close(); |
|
108 |
|
|
109 |
// // *************** OLD ***********************/ |
|
110 |
// |
|
111 |
// Map<String, ClassMetadata> classMetaDataMap = sessionFactory.getAllClassMetadata(); |
|
112 |
//// Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build(); |
|
113 |
// |
|
114 |
// for(ClassMetadata classMetaData : classMetaDataMap.values()) { |
|
115 |
// Class<?> mappedClass = classMetaData.getMappedClass(); |
|
116 |
// |
|
117 |
// String mappedClassName = mappedClass.getName(); |
|
118 |
// |
|
119 |
// PersistentClass persistentClass = metadata.getEntityBinding(mappedClassName); |
|
120 |
// CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName); |
|
121 |
// logger.warn("Adding class : " + mappedClassName + " to cache"); |
|
122 |
// addGetters(persistentClass, cmgmfc); |
|
123 |
// modelClassMap.put(mappedClassName, cmgmfc); |
|
124 |
// } |
|
119 | 125 |
} |
120 | 126 |
catch (Exception e) { |
121 | 127 |
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory |
... | ... | |
126 | 132 |
return modelClassMap; |
127 | 133 |
} |
128 | 134 |
|
135 |
private void handleEntityClass(Map<String, CdmModelFieldPropertyFromClass> modelClassMap, Metadata metadata, |
|
136 |
Class<?> mappedClass) { |
|
137 |
String mappedClassName = mappedClass.getName(); |
|
138 |
PersistentClass persistentClass = metadata.getEntityBinding(mappedClassName); |
|
139 |
CdmModelFieldPropertyFromClass fieldProperties = new CdmModelFieldPropertyFromClass(mappedClassName); |
|
140 |
logger.warn("Adding class : " + mappedClassName + " to cache"); |
|
141 |
addGetters(persistentClass, fieldProperties); |
|
142 |
modelClassMap.put(mappedClassName, fieldProperties); |
|
143 |
} |
|
144 |
|
|
129 | 145 |
public static Configuration buildConfiguration(String hibernateConfigFilePath) { |
130 | 146 |
Configuration configuration = new Configuration().configure(hibernateConfigFilePath); |
131 |
configuration.buildMappings(); |
|
132 | 147 |
return configuration; |
133 | 148 |
} |
134 | 149 |
|
... | ... | |
159 | 174 |
// See also https://dev.e-taxonomy.eu/redmine/projects/edit/wiki/TaxonomicEditorDevelopersGuide#Model-Change-Actions |
160 | 175 |
//Note AM: does not fully work for me, but running the main from the IDE works. |
161 | 176 |
|
177 |
System.out.println("Start CdmModelCacher main."); |
|
162 | 178 |
CdmModelCacher cdmModelCacher = new CdmModelCacher(); |
163 | 179 |
Map<String, CdmModelFieldPropertyFromClass> modelClassMap = cdmModelCacher.generateModelClassMap(); |
164 | 180 |
try{ |
181 |
System.out.println("Model created."); |
|
165 | 182 |
if (!modelClassMap.isEmpty()){ |
166 | 183 |
File outFile = new File("src/main/resources/" + CDM_MAP_SER_FILE_PATH); |
167 | 184 |
System.out.println("writing to " + outFile.getAbsolutePath()); |
... | ... | |
170 | 187 |
oos.writeObject(modelClassMap); |
171 | 188 |
oos.close(); |
172 | 189 |
System.out.println("CDM Map serialized"); |
190 |
System.exit(0); |
|
173 | 191 |
}else{ |
174 | 192 |
String message = "CDM Map was empty. Model cache update NOT successful"; |
175 | 193 |
System.out.println(message); |
176 | 194 |
} |
177 |
|
|
178 | 195 |
}catch(Exception ex){ |
179 | 196 |
ex.printStackTrace(); |
180 | 197 |
} |
198 |
|
|
199 |
System.exit(1); |
|
181 | 200 |
} |
182 |
} |
|
201 |
} |
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmModelCacherConnectionProvider.java | ||
---|---|---|
8 | 8 |
*/ |
9 | 9 |
package eu.etaxonomy.cdm.cache; |
10 | 10 |
|
11 |
import java.net.URL; |
|
12 |
|
|
11 | 13 |
import javax.sql.DataSource; |
12 | 14 |
|
13 | 15 |
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl; |
... | ... | |
25 | 27 |
* @author a.mueller |
26 | 28 |
*/ |
27 | 29 |
public class CdmModelCacherConnectionProvider extends DatasourceConnectionProviderImpl{ |
28 |
private static final long serialVersionUID = 454393966637126346L; |
|
30 |
|
|
31 |
private static final long serialVersionUID = 454393966637126346L; |
|
29 | 32 |
|
30 | 33 |
public CdmModelCacherConnectionProvider() { |
31 |
super(); |
|
32 | 34 |
setDataSource(getDataSourcePreliminary()); |
33 | 35 |
} |
34 | 36 |
|
35 | 37 |
private DataSource getDataSourcePreliminary() { |
36 | 38 |
String database = "modelCacher"; |
37 |
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database; |
|
39 |
URL location = this.getClass().getProtectionDomain().getCodeSource().getLocation(); |
|
40 |
String path = location.getFile().replace("classes/", "tmp/h2/"+database); |
|
41 |
// String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database; |
|
38 | 42 |
String username = "sa"; |
39 |
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path);
|
|
43 |
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("temp", username, "", path);
|
|
40 | 44 |
return dataSource; |
41 | 45 |
} |
42 | 46 |
} |
cdmlib-cache/src/main/java/eu/etaxonomy/cdm/cache/CdmRemoteCacheManager.java | ||
---|---|---|
9 | 9 |
package eu.etaxonomy.cdm.cache; |
10 | 10 |
|
11 | 11 |
import java.io.IOException; |
12 |
import java.net.URISyntaxException; |
|
13 | 12 |
|
14 | 13 |
import org.apache.logging.log4j.LogManager; |
15 | 14 |
import org.apache.logging.log4j.Logger; |
... | ... | |
72 | 71 |
CdmModelCacher cmdmc = new CdmModelCacher(); |
73 | 72 |
cmdmc.cacheGetterFields(cdmlibModelCache); |
74 | 73 |
|
75 |
} catch (CacheException | ClassNotFoundException | IOException | URISyntaxException e) {
|
|
74 |
} catch (CacheException | ClassNotFoundException | IOException e) { |
|
76 | 75 |
throw new CdmClientCacheException(e); |
77 | 76 |
} |
78 | 77 |
} |
Also available in: Unified diff
ref #6696 create CdmModelCache during maven and remove cached model from git