Preliminary adapt CDM model cacher script to work for cached model update
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 2 May 2016 18:41:11 +0000 (20:41 +0200)
committerAndreas Müller <a.mueller@bgbm.org>
Wed, 11 May 2016 09:43:03 +0000 (11:43 +0200)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacherConnectionProvider.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml
eu.etaxonomy.taxeditor.test/src/test/resources/.cdmLibrary/writableResources/test.mgd.datasources.xml

index 9975269..42e300f 100644 (file)
@@ -23,12 +23,13 @@ import org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl;
 import org.hibernate.boot.registry.StandardServiceRegistry;
 import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
 import org.hibernate.cfg.Configuration;
+import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
+import org.hibernate.engine.jdbc.connections.spi.ConnectionProvider;
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Property;
 import org.hibernate.metadata.ClassMetadata;
 import org.hibernate.property.access.spi.Getter;
 import org.osgi.framework.Bundle;
-
 import org.hibernate.boot.Metadata;
 
 
@@ -79,14 +80,18 @@ public class CdmModelCacher {
        SessionFactory sessionFactory = null;
        Map<String, CdmModelFieldPropertyFromClass> modelClassMap = new HashMap<String, CdmModelFieldPropertyFromClass>();
        try {
-               sessionFactory = new MetadataSources( registry ).buildMetadata().buildSessionFactory();
-               Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH);
+//             ConnectionProvider connectionProvider = registry.getService(ConnectionProvider.class);
+//             DatasourceConnectionProviderImpl providerImpl = registry.getService(DatasourceConnectionProviderImpl.class);
+
+               Metadata metadata = new MetadataSources( registry ).buildMetadata();
+               sessionFactory = metadata.buildSessionFactory();
+//             Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH);
                Map<String, ClassMetadata> classMetaDataMap = sessionFactory.getAllClassMetadata();
-               Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build();
+//             Metadata metadata = new MetadataSources( registry ).getMetadataBuilder().applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE ).build();
            
 
             for(ClassMetadata classMetaData :classMetaDataMap.values()) {
-               Class mappedClass = classMetaData.getMappedClass();
+               Class<?> mappedClass = classMetaData.getMappedClass();
                
                 String mappedClassName = mappedClass.getName();
                
@@ -101,6 +106,7 @@ public class CdmModelCacher {
                // The registry would be destroyed by the SessionFactory, but we had trouble building the SessionFactory
                // so destroy it manually.
                StandardServiceRegistryBuilder.destroy( registry );
+               e.printStackTrace();
        }
        
        
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacherConnectionProvider.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacherConnectionProvider.java
new file mode 100644 (file)
index 0000000..6297b5b
--- /dev/null
@@ -0,0 +1,34 @@
+package eu.etaxonomy.taxeditor.remoting.cache;
+
+import javax.sql.DataSource;
+
+import org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl;
+
+import eu.etaxonomy.cdm.database.CdmDataSource;
+import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
+
+/**
+ * This is a very preliminary class to get the model cache running. Need to better understand how 
+ * the datasource works with hibernate service registry before implementing the correct way.
+ * Or use a running source.
+ * @author a.mueller
+ *
+ */
+public class CdmModelCacherConnectionProvider extends DatasourceConnectionProviderImpl{
+
+       public CdmModelCacherConnectionProvider() {
+               super();
+               setDataSource(getDataSourcePreliminary());
+       }
+
+       private DataSource getDataSourcePreliminary() {
+               String database = "xyz";
+               String path = "C:\\Users\\a.mueller\\.cdmLibrary\\writableResources\\h2\\LocalH2_" + database;
+        String username = "sa";
+        CdmDataSource dataSource = CdmDataSource.NewH2EmbeddedInstance("cdmTest", username, "", path,   NomenclaturalCode.ICNAFP);
+        return dataSource;
+       }
+       
+       
+
+}
index e48ff8a..491b203 100644 (file)
@@ -7,11 +7,17 @@
     <session-factory>\r
 \r
       <property name="connection.release_mode">after_transaction</property>\r
+      \r
+      <property name="hibernate.implicit_naming_strategy">org.hibernate.boot.model.naming.ImplicitNamingStrategyComponentPathImpl</property>\r
+      \r
 \r
       <!-- Connection Pooling -->\r
 <!--       <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider</property> -->\r
-      <property name="hibernate.connection.provider_class">org.hibernate.service.jdbc.connections.internal.DatasourceConnectionProviderImpl</property>\r
-           <!--\r
+      <!-- <property name="hibernate.connection.provider_class">org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl</property>\r
+          -->\r
+             <property name="hibernate.connection.provider_class">eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacherConnectionProvider</property>\r
+          \r
+            <!--\r
           Configuring the C3P0ConnectionProvider\r
           ========================================\r
           see http://www.mchange.com/projects/c3p0/index.html#hibernate-specific\r
       <!-- View Package -->\r
       <mapping class="eu.etaxonomy.cdm.model.view.AuditEvent"/>\r
       \r
-      <!-- for filling caches -->\r
-      <!-- since hibernate 4 listeners are not handled via hibernate.cfg.xml anymore -->\r
-      <!--  http://stackoverflow.com/questions/8616146/eventlisteners-using-hibernate-4-0-with-spring-3-1-0-release\r
-            https://community.jboss.org/wiki/HibernateCoreMigrationGuide40 -->\r
+\r
 \r
     </session-factory>\r
 </hibernate-configuration>
\ No newline at end of file
index c352d50..5a1c1a2 100644 (file)
@@ -16,6 +16,6 @@
    <property name="driverClass" value="org.h2.Driver"/>
    <property name="user" value="sa"/>
    <property name="password" value=""/>
-   <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"/>
+   <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"/>
  </bean>
 </beans>