Revision d1fcc397
Added by Andreas Müller almost 8 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java | ||
---|---|---|
23 | 23 |
import org.hibernate.boot.registry.StandardServiceRegistry; |
24 | 24 |
import org.hibernate.boot.registry.StandardServiceRegistryBuilder; |
25 | 25 |
import org.hibernate.cfg.Configuration; |
26 |
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl; |
|
27 |
import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider; |
|
26 | 28 |
import org.hibernate.mapping.PersistentClass; |
27 | 29 |
import org.hibernate.mapping.Property; |
28 | 30 |
import org.hibernate.metadata.ClassMetadata; |
29 | 31 |
import org.hibernate.property.access.spi.Getter; |
30 | 32 |
import org.osgi.framework.Bundle; |
31 |
|
|
32 | 33 |
import org.hibernate.boot.Metadata; |
33 | 34 |
|
34 | 35 |
|
... | ... | |
79 | 80 |
SessionFactory sessionFactory = null; |
80 | 81 |
Map<String, CdmModelFieldPropertyFromClass> modelClassMap = new HashMap<String, CdmModelFieldPropertyFromClass>(); |
81 | 82 |
try { |
82 |
sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory(); |
|
83 |
Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH); |
|
83 |
// ConnectionProvider connectionProvider = registry.getService(ConnectionProvider.class); |
|
84 |
// DatasourceConnectionProviderImpl providerImpl = registry.getService(DatasourceConnectionProviderImpl.class); |
|
85 |
|
|
86 |
Metadata metadata = new MetadataSources( registry ).buildMetadata(); |
|
87 |
sessionFactory = metadata.buildSessionFactory(); |
|
88 |
// Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH); |
|
84 | 89 |
Map<String, ClassMetadata> classMetaDataMap = sessionFactory.getAllClassMetadata(); |
85 |
Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build(); |
|
90 |
// Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build();
|
|
86 | 91 |
|
87 | 92 |
|
88 | 93 |
for(ClassMetadata classMetaData :classMetaDataMap.values()) { |
89 |
Class mappedClass = classMetaData.getMappedClass(); |
|
94 |
Class<?> mappedClass = classMetaData.getMappedClass();
|
|
90 | 95 |
|
91 | 96 |
String mappedClassName = mappedClass.getName(); |
92 | 97 |
|
... | ... | |
101 | 106 |
// The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory |
102 | 107 |
// so destroy it manually. |
103 | 108 |
StandardServiceRegistryBuilder.destroy( registry ); |
109 |
e.printStackTrace(); |
|
104 | 110 |
} |
105 | 111 |
|
106 | 112 |
|
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacherConnectionProvider.java | ||
---|---|---|
1 |
package eu.etaxonomy.taxeditor.remoting.cache; |
|
2 |
|
|
3 |
import javax.sql.DataSource; |
|
4 |
|
|
5 |
import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl; |
|
6 |
|
|
7 |
import eu.etaxonomy.cdm.database.CdmDataSource; |
|
8 |
import eu.etaxonomy.cdm.model.name.NomenclaturalCode; |
|
9 |
|
|
10 |
/** |
|
11 |
* This is a very preliminary class to get the model cache running. Need to better understand how |
|
12 |
* the datasource works with hibernate service registry before implementing the correct way. |
|
13 |
* Or use a running source. |
|
14 |
* @author a.mueller |
|
15 |
* |
|
16 |
*/ |
|
17 |
public class CdmModelCacherConnectionProvider extends DatasourceConnectionProviderImpl{ |
|
18 |
|
|
19 |
public CdmModelCacherConnectionProvider() { |
|
20 |
super(); |
|
21 |
setDataSource(getDataSourcePreliminary()); |
|
22 |
} |
|
23 |
|
|
24 |
private DataSource getDataSourcePreliminary() { |
|
25 |
String database = "xyz"; |
|
26 |
String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database; |
|
27 |
String username = "sa"; |
|
28 |
CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path, NomenclaturalCode.ICNAFP); |
|
29 |
return dataSource; |
|
30 |
} |
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
} |
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml | ||
---|---|---|
7 | 7 |
<session-factory> |
8 | 8 |
|
9 | 9 |
<property name="connection.release_mode">after_transaction</property> |
10 |
|
|
11 |
<property name="hibernate.implicit_naming_strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl</property> |
|
12 |
|
|
10 | 13 |
|
11 | 14 |
<!-- Connection Pooling --> |
12 | 15 |
<!-- <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property> --> |
13 |
<property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl</property> |
|
14 |
<!-- |
|
16 |
<!-- <property name="hibernate.connection.provider_class">org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl</property> |
|
17 |
--> |
|
18 |
<property name="hibernate.connection.provider_class">eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacherConnectionProvider</property> |
|
19 |
|
|
20 |
<!-- |
|
15 | 21 |
Configuring the C3P0ConnectionProvider |
16 | 22 |
======================================== |
17 | 23 |
see http://www.mchange.com/projects/c3p0/index.html#hibernate-specific |
... | ... | |
204 | 210 |
<!-- View Package --> |
205 | 211 |
<mapping class="eu.etaxonomy.cdm.model.view.AuditEvent"/> |
206 | 212 |
|
207 |
<!-- for filling caches --> |
|
208 |
<!-- since hibernate 4 listeners are not handled via hibernate.cfg.xml anymore --> |
|
209 |
<!-- http://stackoverflow.com/questions/8616146/eventlisteners-using-hibernate-4-0-with-spring-3-1-0-release |
|
210 |
https://community.jboss.org/wiki/HibernateCoreMigrationGuide40 --> |
|
213 |
|
|
211 | 214 |
|
212 | 215 |
</session-factory> |
213 | 216 |
</hibernate-configuration> |
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/test.mgd.datasources.xml | ||
---|---|---|
16 | 16 |
<property name="driverClass" value="org.h2.Driver"/> |
17 | 17 |
<property name="user" value="sa"/> |
18 | 18 |
<property name="password" value=""/> |
19 |
<property name="jdbcUrl" value="jdbc:h2:file:/home/andreas/workspaces/cdm/taxeditor/eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/h2/LocalH2/cdmTest;AUTO_SERVER=TRUE"/>
|
|
19 |
<property name="jdbcUrl" value="jdbc:h2:file:C:\Users\a.mueller\eclipse\git\taxeditor\eu.etaxonomy.taxeditor.test\src\test\resources\.cdmLibrary\writableResources\h2\LocalH2/cdmTest;AUTO_SERVER=TRUE"/>
|
|
20 | 20 |
</bean> |
21 | 21 |
</beans> |
Also available in: Unified diff
Preliminary adapt CDM model cacher script to work for cached model update