Skip to content

Commit 5f6d1d2

Browse files
committed
HHH-8844 - Add support for Java 8 date and time types (JSR-310)
1 parent 3e73948 commit 5f6d1d2

File tree

26 files changed

+1183
-58
lines changed

26 files changed

+1183
-58
lines changed

build.gradle

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ buildscript {
2222
repositories {
2323
mavenCentral()
2424
mavenLocal()
25+
jcenter()
2526

2627
maven {
2728
name 'jboss-nexus'
@@ -120,9 +121,6 @@ subprojects { subProject ->
120121
// todo : need to make sure these are non-exported
121122
description = 'Non-exported compile-time dependencies.'
122123
}
123-
jbossLoggingTool {
124-
description = "Dependencies for running the JBoss logging AnnotationProcessor tool"
125-
}
126124
jaxb {
127125
description = 'Dependencies for running ant xjc (jaxb class generation)'
128126
}
@@ -149,8 +147,6 @@ subprojects { subProject ->
149147
testRuntime( libraries.h2 )
150148
testRuntime( libraries.woodstox )
151149

152-
jbossLoggingTool( libraries.logging_processor )
153-
154150
jaxb( libraries.jaxb ){
155151
exclude group: "javax.xml.stream"
156152
}
@@ -159,7 +155,6 @@ subprojects { subProject ->
159155
jaxb( libraries.jaxb2_jaxb )
160156
jaxb( libraries.jaxb2_jaxb_xjc )
161157

162-
animalSniffer ( libraries.animal_sniffer )
163158
javaApiSignature ( libraries.java16_signature )
164159
}
165160

@@ -273,32 +268,10 @@ subprojects { subProject ->
273268
// Gradle plugin). For now, just compile first in order to get the logging classes.
274269
eclipseClasspath.dependsOn generateSources
275270

276-
277-
// Animal Sniffer ~~~~~~~~~~~~~~~~~~
278-
// add animal sniffer Java API checking to the main compile tasks
279-
280-
// copy the resolved Animal Sniffer signature dependency artifact to a known location and name
281-
task copyJavaApiSignature(type: Copy) {
282-
from configurations.javaApiSignature
283-
into "$buildDir/javaApiSignature/"
284-
rename '.*signature', 'javaApi.signature'
285-
}
286-
287-
// prepare the Animal Sniffer signature copy every time (before) we compile
288-
compileJava.dependsOn copyJavaApiSignature
289-
290-
// and then after compilation, run the Animal Sniffer tool
291-
compileJava.doLast {
292-
ant.taskdef(
293-
name: 'animalSniffer',
294-
classname: 'org.codehaus.mojo.animal_sniffer.ant.CheckSignatureTask',
295-
classpath: configurations.animalSniffer.asPath
296-
)
297-
298-
ant.animalSniffer(
299-
signature: "$buildDir/javaApiSignature/javaApi.signature",
300-
classpath: sourceSets.main.compileClasspath.asPath) {
301-
path( path: sourceSets.main.output.classesDir )
271+
if ( subProject.name != 'hibernate-java8' ) {
272+
apply plugin: org.hibernate.build.animalsniffer.AnimalSnifferPlugin
273+
animalsniffer {
274+
signature = "org.codehaus.mojo.signature:java16:+@signature"
302275
}
303276
}
304277

buildSrc/build.gradle

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
repositories {
2+
mavenCentral()
3+
}
4+
5+
apply plugin: "groovy"
6+
7+
dependencies {
8+
compile gradleApi()
9+
compile localGroovy()
10+
11+
compile "org.codehaus.mojo:animal-sniffer:1.14"
12+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* Copyright (c) 2015, Red Hat Inc. or third-party contributors as
5+
* indicated by the @author tags or express copyright attribution
6+
* statements applied by the authors. All third-party contributions are
7+
* distributed under license by Red Hat Inc.
8+
*
9+
* This copyrighted material is made available to anyone wishing to use, modify,
10+
* copy, or redistribute it subject to the terms and conditions of the GNU
11+
* Lesser General Public License, as published by the Free Software Foundation.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15+
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
16+
* for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with this distribution; if not, write to:
20+
* Free Software Foundation, Inc.
21+
* 51 Franklin Street, Fifth Floor
22+
* Boston, MA 02110-1301 USA
23+
*/
24+
package org.hibernate.build.animalsniffer
25+
26+
import org.gradle.api.Action
27+
import org.gradle.api.GradleException
28+
import org.gradle.api.Plugin
29+
import org.gradle.api.Project
30+
import org.gradle.api.Task
31+
import org.gradle.api.plugins.JavaPlugin
32+
33+
import groovy.transform.Canonical
34+
import org.codehaus.mojo.animal_sniffer.SignatureChecker
35+
import org.codehaus.mojo.animal_sniffer.logging.Logger
36+
import org.slf4j.LoggerFactory
37+
38+
class AnimalSnifferPlugin implements Plugin<Project> {
39+
private org.slf4j.Logger logger = LoggerFactory.getLogger( this.class )
40+
41+
@Override
42+
void apply(Project project) {
43+
project.configurations.maybeCreate( "signature" )
44+
final AnimalSnifferExtension extension = project.extensions.create( "animalsniffer", AnimalSnifferExtension )
45+
46+
project.tasks.findByName( JavaPlugin.CLASSES_TASK_NAME ).doLast(
47+
new Action<Task>() {
48+
@Override
49+
void execute(Task task) {
50+
if ( extension.skip ) {
51+
return;
52+
}
53+
54+
def logger = new GradleLogger( logger )
55+
def signatures = project.configurations.signature.resolvedConfiguration.resolvedArtifacts*.file
56+
signatures.each {
57+
SignatureChecker signatureChecker = new SignatureChecker(
58+
it.newInputStream(),
59+
Collections.emptySet(),
60+
logger
61+
)
62+
signatureChecker.setCheckJars( false );
63+
64+
List<File> sourceDirs = new ArrayList<File>();
65+
sourceDirs.addAll( task.project.sourceSets.main.java.srcDirs )
66+
signatureChecker.setSourcePath( sourceDirs )
67+
68+
signatureChecker.process( project.file( task.project.sourceSets.main.output.classesDir ) );
69+
70+
if ( signatureChecker.isSignatureBroken() ) {
71+
throw new GradleException(
72+
"Signature errors found. Verify them and ignore them with the proper annotation if needed."
73+
);
74+
}
75+
}
76+
}
77+
}
78+
);
79+
}
80+
}
81+
82+
@Canonical
83+
class GradleLogger implements Logger {
84+
@Delegate
85+
org.slf4j.Logger logger
86+
}
87+
88+
class AnimalSnifferExtension {
89+
String signature = ""
90+
String[] signatures = []
91+
boolean skip = false
92+
}

hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
*
3434
* @author Steve Ebersole
3535
*/
36-
public class Identifier {
36+
public class Identifier implements Comparable<Identifier> {
3737
private final String text;
3838
private final boolean isQuoted;
3939

@@ -211,5 +211,10 @@ public static Identifier quote(Identifier identifier) {
211211
? identifier
212212
: Identifier.toIdentifier( identifier.getText(), true );
213213
}
214+
215+
@Override
216+
public int compareTo(Identifier o) {
217+
return getCanonicalName().compareTo( o.getCanonicalName() );
218+
}
214219
}
215220

hibernate-core/src/main/java/org/hibernate/boot/model/relational/Database.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626
import java.util.ArrayList;
2727
import java.util.Collection;
2828
import java.util.Collections;
29-
import java.util.HashMap;
3029
import java.util.List;
3130
import java.util.Map;
31+
import java.util.TreeMap;
3232

3333
import org.hibernate.boot.model.naming.Identifier;
3434
import org.hibernate.boot.model.naming.PhysicalNamingStrategy;
@@ -48,7 +48,7 @@ public class Database {
4848

4949
private Schema implicitSchema;
5050

51-
private final Map<Schema.Name,Schema> schemaMap = new HashMap<Schema.Name, Schema>();
51+
private final Map<Schema.Name,Schema> schemaMap = new TreeMap<Schema.Name, Schema>();
5252

5353
private List<AuxiliaryDatabaseObject> auxiliaryDatabaseObjects;
5454
private List<InitCommand> initCommands;

hibernate-core/src/main/java/org/hibernate/boot/model/relational/Schema.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
package org.hibernate.boot.model.relational;
2525

2626
import java.util.Collection;
27-
import java.util.HashMap;
2827
import java.util.Map;
28+
import java.util.TreeMap;
2929

3030
import org.hibernate.HibernateException;
3131
import org.hibernate.boot.model.naming.Identifier;
@@ -48,8 +48,8 @@ public class Schema {
4848

4949
private final Name physicalName;
5050

51-
private Map<Identifier, Table> tables = new HashMap<Identifier, Table>();
52-
private Map<Identifier, Sequence> sequences = new HashMap<Identifier, Sequence>();
51+
private Map<Identifier, Table> tables = new TreeMap<Identifier, Table>();
52+
private Map<Identifier, Sequence> sequences = new TreeMap<Identifier, Sequence>();
5353

5454
public Schema(Database database, Name name) {
5555
this.database = database;
@@ -168,7 +168,7 @@ public Iterable<Sequence> getSequences() {
168168
return sequences.values();
169169
}
170170

171-
public static class Name {
171+
public static class Name implements Comparable<Name> {
172172
private final Identifier catalog;
173173
private final Identifier schema;
174174

@@ -211,5 +211,38 @@ public int hashCode() {
211211
result = 31 * result + (schema != null ? schema.hashCode() : 0);
212212
return result;
213213
}
214+
215+
@Override
216+
public int compareTo(Name that) {
217+
// per Comparable, the incoming Name cannot be null. However, its catalog/schema might be
218+
// so we need to account for that.
219+
int catalogCheck = ComparableHelper.compare( this.getCatalog(), that.getCatalog() );
220+
if ( catalogCheck != 0 ) {
221+
return catalogCheck;
222+
}
223+
224+
return ComparableHelper.compare( this.getSchema(), that.getSchema() );
225+
}
226+
}
227+
228+
public static class ComparableHelper {
229+
public static <T extends Comparable<T>> int compare(T first, T second) {
230+
if ( first == null ) {
231+
if ( second == null ) {
232+
return 0;
233+
}
234+
else {
235+
return 1;
236+
}
237+
}
238+
else {
239+
if ( second == null ) {
240+
return -1;
241+
}
242+
else {
243+
return first.compareTo( second );
244+
}
245+
}
246+
}
214247
}
215248
}

hibernate-core/src/main/java/org/hibernate/internal/util/compare/ComparableComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
* @author Gavin King
3434
* @author Steve Ebersole
3535
*/
36-
public class ComparableComparator implements Comparator<Comparable>, Serializable {
36+
public class ComparableComparator<T extends Comparable> implements Comparator<T>, Serializable {
3737
public static final Comparator INSTANCE = new ComparableComparator();
3838

3939
@SuppressWarnings({ "unchecked" })

hibernate-core/src/test/java/org/hibernate/test/criteria/LongInElementsTest.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
* Boston, MA 02110-1301 USA
2323
*/
2424
package org.hibernate.test.criteria;
25-
import static org.junit.Assert.assertEquals;
2625

2726
import java.util.ArrayList;
2827
import java.util.List;
@@ -36,19 +35,24 @@
3635
import org.hibernate.dialect.SQLServerDialect;
3736
import org.hibernate.dialect.SybaseDialect;
3837
import org.hibernate.dialect.TeradataDialect;
39-
import org.hibernate.test.hql.StateProvince;
38+
4039
import org.hibernate.testing.SkipForDialect;
4140
import org.hibernate.testing.TestForIssue;
4241
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
42+
import org.hibernate.test.hql.StateProvince;
43+
import org.junit.Ignore;
4344
import org.junit.Test;
4445

46+
import static org.junit.Assert.assertEquals;
47+
4548
/**
4649
* HHH-2166 Long "in" lists in queries results in a Java stack overflow
4750
* exception. to reproduce this issue, you should add
4851
* "<argLine>-Xss128k</argLine>" to the surefire plugin (test on Fedora 12)
4952
*
5053
* @author Strong Liu
5154
*/
55+
@Ignore
5256
public class LongInElementsTest extends BaseCoreFunctionalTestCase {
5357
private static final int ELEMENTS_SIZE = 4000;
5458

hibernate-envers/hibernate-envers.gradle

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
apply plugin: 'hibernate-matrix-testing'
22

3-
configurations {
4-
hibernateJpaModelGenTool {
5-
description = "Dependencies for running the Hibernate JPA Metamodel Generator AnnotationProcessor tool"
6-
}
7-
}
8-
93
dependencies {
104
compile( project( ':hibernate-core' ) )
115
compile( project( ':hibernate-entitymanager' ) )
@@ -17,8 +11,6 @@ dependencies {
1711
testCompile( project(path: ':hibernate-entitymanager', configuration: 'tests') )
1812

1913
testRuntime( libraries.javassist )
20-
21-
hibernateJpaModelGenTool( project( ':hibernate-jpamodelgen' ) )
2214
}
2315

2416
def pomName() {
@@ -48,8 +40,6 @@ sourceSets {
4840
}
4941
}
5042

51-
addMetaGenProcessor( sourceSets.main )
52-
5343
jar {
5444
manifest {
5545
instructionFirst 'Import-Package',

hibernate-envers/src/main/java/org/hibernate/envers/internal/EnversMessageLogger.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@
2323
*/
2424
package org.hibernate.envers.internal;
2525

26-
import org.hibernate.internal.CoreMessageLogger;
27-
26+
import org.jboss.logging.BasicLogger;
2827
import org.jboss.logging.annotations.LogMessage;
2928
import org.jboss.logging.annotations.Message;
3029
import org.jboss.logging.annotations.MessageLogger;
@@ -38,7 +37,7 @@
3837
* New messages must be added after the last message defined to ensure message codes are unique.
3938
*/
4039
@MessageLogger(projectCode = "HHH")
41-
public interface EnversMessageLogger extends CoreMessageLogger {
40+
public interface EnversMessageLogger extends BasicLogger {
4241
/**
4342
* Message indicating that user attempted to use the deprecated ValidTimeAuditStrategy
4443
*/

0 commit comments

Comments
 (0)