Project

General

Profile

Revision f967c042

IDf967c0425a4dd828d194d56edfbf0c47b6003189
Parent a055729c
Child d8efa27b

Added by Andreas Müller 2 months ago

ref #9204 update to hibernate 5.1.17 in cdmlib

View differences:

cdmlib-persistence/src/main/java/eu/etaxonomy/cdm/persistence/dao/hibernate/taxon/TaxonDaoHibernateImpl.java
827 827
        } else {
828 828
            AuditQuery query = getAuditReader().createQuery().forEntitiesAtRevision(Synonym.class,auditEvent.getRevisionNumber());
829 829
            if (onlyAttachedToTaxon){
830
                query.add(new NotNullAuditExpression(new EntityPropertyName("acceptedTaxon")));
830
                query.add(new NotNullAuditExpression(null, new EntityPropertyName("acceptedTaxon")));
831 831
            }
832 832
            query.addProjection(AuditEntity.id().count());
833 833

  
......
875 875
            return (Long)criteria.uniqueResult();
876 876
        } else {
877 877
            AuditQuery query = makeAuditQuery(Synonym.class,auditEvent);
878
            query.add(new NotNullAuditExpression(new EntityPropertyName("acceptedTaxon")));
878
            query.add(new NotNullAuditExpression(null, new EntityPropertyName("acceptedTaxon")));
879 879
            query.addProjection(AuditEntity.id().count());
880 880

  
881 881
            if(type != null) {
cdmlib-test/src/main/java/eu/etaxonomy/cdm/test/unitils/DdlCreator.java
4 4
package eu.etaxonomy.cdm.test.unitils;
5 5

  
6 6

  
7
import java.io.File;
8
import java.io.IOException;
7
import java.util.EnumSet;
9 8

  
10
import org.hibernate.HibernateException;
9
import org.hibernate.boot.Metadata;
10
import org.hibernate.boot.MetadataSources;
11 11
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
12 12
import org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl;
13
import org.hibernate.cfg.AvailableSettings;
14
import org.hibernate.cfg.Configuration;
13
import org.hibernate.boot.registry.StandardServiceRegistry;
14
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
15 15
import org.hibernate.dialect.H2CorrectedDialectTest;
16
import org.hibernate.envers.boot.internal.EnversService;
17
import org.hibernate.envers.boot.internal.EnversServiceImpl;
18 16
import org.hibernate.tool.hbm2ddl.SchemaExport;
19
import org.springframework.core.io.ClassPathResource;
17
import org.hibernate.tool.schema.TargetType;
18
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
19
import org.springframework.orm.hibernate5.LocalSessionFactoryBuilder;
20 20

  
21 21
/**
22 22
 *
......
32 32
 * The result is stored in a file "new-cdm.h2.sql" in the root directory and is written to the console.
33 33
 *
34 34
 * @author a.mueller
35
 *
36 35
 */
37 36
public class DdlCreator {
38 37

  
39 38
	public static void main(String[] args) {
40 39
		try {
41
			new DdlCreator().execute(H2CorrectedDialectTest.class, "h2");
40
			new DdlCreator().execute2(H2CorrectedDialectTest.class, "h2");
42 41
		} catch (Exception e) {
43
			// TODO Auto-generated catch block
44 42
			e.printStackTrace();
45 43
		}
46 44
	}
47 45

  
48
	private void execute(Class<?> dialect, String lowerCaseDialectName, Class<?>... classes) throws IOException, HibernateException, InstantiationException, IllegalAccessException {
49
		String classPath = "eu/etaxonomy/cdm/hibernate.cfg.xml";
50
		ClassPathResource resource = new ClassPathResource(classPath);
51
		File file = resource.getFile();
52

  
53
//		File file = new File("C:\\Users\\pesiimport\\Documents\\cdm-3.3\\cdmlib-persistence\\src\\main\\resources\\eu\\etaxonomy\\cdm\\hibernate.cfg.xml");
54
		System.out.println(file.exists());
55

  
56
		Configuration config = new Configuration().addFile(file);
57
		config.setProperty(AvailableSettings.DIALECT, dialect.getCanonicalName());
58
//		NamingStrategyDelegator;
59
		PhysicalNamingStrategy namingStrategy = new PhysicalNamingStrategyStandardImpl();
60
//		        new DefaultComponentSafeNamingStrategy(); //; = new ImprovedNamingStrategy();
61
		config.setPhysicalNamingStrategy(namingStrategy);
62

  
63
		config.configure(file);
64
//		String[] schema = config.generateSchemaCreationScript((Dialect)dialect.newInstance());
65
//		for (String s : schema){
66
//			System.out.println(s);
67
//		}
68

  
69
		//FIXME #4716
70
		EnversService enversService = new EnversServiceImpl();
71
//		. .getFor(config.);
72
		SchemaExport schemaExport = new SchemaExport(config);
73
		schemaExport.setDelimiter(";");
74
		schemaExport.drop(false, false);
75
		schemaExport.setOutputFile(String.format("%s.%s.%s ", new Object[] {"new-cdm", lowerCaseDialectName, "sql" }));
76
		boolean consolePrint = true;
77
		boolean exportInDatabase = false;
78
		schemaExport.create(consolePrint, exportInDatabase);
79

  
80
		schemaExport.execute(consolePrint, exportInDatabase, false, true);
46
//	private void execute(Class<?> dialect, String lowerCaseDialectName, Class<?>... classes) throws IOException, HibernateException, InstantiationException, IllegalAccessException {
47
//		String classPath = "eu/etaxonomy/cdm/hibernate.cfg.xml";
48
//		ClassPathResource resource = new ClassPathResource(classPath);
49
//		File file = resource.getFile();
50
//
51
////		File file = new File("C:\\Users\\pesiimport\\Documents\\cdm-3.3\\cdmlib-persistence\\src\\main\\resources\\eu\\etaxonomy\\cdm\\hibernate.cfg.xml");
52
//		System.out.println(file.exists());
53
//
54
//		Configuration config = new Configuration().addFile(file);
55
//		config.setProperty(AvailableSettings.DIALECT, dialect.getCanonicalName());
56
////		NamingStrategyDelegator;
57
//		PhysicalNamingStrategy namingStrategy = new PhysicalNamingStrategyStandardImpl();
58
////		        new DefaultComponentSafeNamingStrategy(); //; = new ImprovedNamingStrategy();
59
//		config.setPhysicalNamingStrategy(namingStrategy);
60
//
61
//		config.configure(file);
62
////		String[] schema = config.generateSchemaCreationScript((Dialect)dialect.newInstance());
63
////		for (String s : schema){
64
////			System.out.println(s);
65
////		}
66
//
67
//		//FIXME #4716
68
//		EnversService enversService = new EnversServiceImpl();
69
////		. .getFor(config.);
70
//		SchemaExport schemaExport = new SchemaExport(config);
71
//		schemaExport.setDelimiter(";");
72
//		schemaExport.drop(false, false);
73
//		schemaExport.setOutputFile(String.format("%s.%s.%s ", new Object[] {"new-cdm", lowerCaseDialectName, "sql" }));
74
//		boolean consolePrint = true;
75
//		boolean exportInDatabase = false;
76
//		schemaExport.create(consolePrint, exportInDatabase);
77
//
78
//		schemaExport.execute(consolePrint, exportInDatabase, false, true);
79
//
80
//	}
81

  
82

  
83
    public void execute2(Class<?> dialect, String lowerCaseDialectName){
84
        StandardServiceRegistryBuilder registryBuilder = new StandardServiceRegistryBuilder()
85
                .applySetting("hibernate.dialect", dialect.getName()); // dialect
86

  
87
        StandardServiceRegistry serviceRegistry = registryBuilder.build();
88

  
89
        MetadataSources metadataSources = new MetadataSources(serviceRegistry);
90

  
91

  
92
        PathMatchingResourcePatternResolver resourceLoader = new PathMatchingResourcePatternResolver();
93
        new LocalSessionFactoryBuilder(null, resourceLoader, metadataSources).scanPackages("eu.etaxonomy.cdm.model");
94

  
95
        PhysicalNamingStrategy namingStrategy = new PhysicalNamingStrategyStandardImpl();
96

  
97
        Metadata metadata = metadataSources.buildMetadata();
98

  
99
        new SchemaExport().setFormat(true).setDelimiter(";").setOutputFile("export.sql")
100
            .createOnly(EnumSet.of(TargetType.STDOUT, TargetType.SCRIPT), metadata);
101
    }
102

  
103
//
104
//	private void test5_1(){
105
//	    String packageName;
106
//	    String propertiesFile;
107
//	    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
108
//                .loadProperties(propertiesFile)
109
//                .build();
110
//	    MetadataSources metadata = new MetadataSources(serviceRegistry);
111
//
112
//	    new org.reflections.Reflections(packageName)
113
//	            .getTypesAnnotatedWith(Entity.class)
114
//	            .forEach(metadata::addAnnotatedClass);
115
//
116
//        //STDOUT will export to output window, but other `TargetType` values are available to export to file or to the db.
117
//        EnumSet<TargetType> targetTypes = EnumSet.of(TargetType.STDOUT);
118
//
119
//        SchemaExport export = new SchemaExport();
120
//
121
//        export.setDelimiter(";");
122
//        export.setFormat(true);
123
//
124
//        export.createOnly(targetTypes, metadata.buildMetadata());
125
//	}
126

  
127
//
128
//	public void test5_1_2(){
129
//	    ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
130
//                .configure("hibernate.cfg.xml")
131
//                .build();
132
//	    MetadataImplementor metadata = (MetadataImplementor) new  MetadataSources(serviceRegistry)
133
//	            .buildMetadata();
134
//	    SchemaExport schemaExport = new SchemaExport(metadata);
135
//	    schemaExport.setOutputFile("hbm2schema.sql");
136
//	    schemaExport.create(true, true);
137
//	    ( (StandardServiceRegistryImpl) serviceRegistry ).destroy();
138
//	}
81 139

  
82
	}
83 140
}
84 141

  
pom.xml
31 31
    <spring-security.version>4.2.18.RELEASE</spring-security.version>               <!-- checked 2020-08, further upgrade possible -->
32 32
    <spring-security-oauth2.version>2.5.0.RELEASE</spring-security-oauth2.version>  <!-- checked 2020-08 -->
33 33
    <spring-cloud.version>1.1.3.RELEASE</spring-cloud.version>
34
	<hibernate.version>5.0.7.Final</hibernate.version>
34
	<hibernate.version>5.1.17.Final</hibernate.version>
35 35
	<hibernate-validator.version>6.1.5.Final</hibernate-validator.version>          <!-- checked 2020-08 -->
36 36
    <hibernate-search.version>5.5.2.Final</hibernate-search.version>
37 37
    <lucene.version>5.4.1</lucene.version>
......
1076 1076
        <artifactId>ooxml-schemas</artifactId>
1077 1077
        <version>1.4</version>
1078 1078
      </dependency>
1079
      <!--       <dependency> -->
1080
<!-- maybe needed in cdmlib-io, see https://poi.apache.org/help/faq.html  question 3 on when to use ooxml-schemas and when poi-ooxml-schemas  -->
1081
<!--         <groupId>org.apache.poi</groupId> -->
1082
<!--         <artifactId>ooxml-schemas</artifactId> -->
1083
<!--         <version>1.4</version> -->
1084
<!--       </dependency> -->
1079 1085
      <dependency>
1080 1086
     	<!-- only for version management xmlbeans depends in different versions from 
1081 1087
        org.apache.poi:poi-ooxml-schemas:3.13 and org.apache.poi:ooxml-schemas:1.4 -->
......
1222 1228
      </dependency>
1223 1229
      <!-- >batik-ext required by Xerces 2.11.0 for class ElementTraversal, 
1224 1230
        as this is not included anymore in xml-apis 2.x -->
1225
      <dependency>
1226
        <groupId>org.apache.xmlgraphics</groupId>
1227
        <artifactId>batik-ext</artifactId>
1228
        <version>1.13</version>
1229
      </dependency>
1231
<!--       <dependency> -->
1232
<!--         <groupId>org.apache.xmlgraphics</groupId> -->
1233
<!--         <artifactId>batik-ext</artifactId> -->
1234
<!--         <version>1.13</version> -->
1235
<!--       </dependency> -->
1230 1236
      <dependency> <!-- required by cdmlib-print -->
1231 1237
        <groupId>org.apache.xmlgraphics</groupId>
1232 1238
        <artifactId>fop</artifactId>

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)