consolidate src/test and src/matrix

This commit is contained in:
Steve Ebersole 2012-06-07 14:06:43 -05:00
parent 77d83b8a10
commit 0196ad20f8
1944 changed files with 578 additions and 659 deletions

View File

@ -31,7 +31,6 @@ import org.gradle.api.logging.Logger
import org.gradle.api.logging.Logging import org.gradle.api.logging.Logging
import org.gradle.api.plugins.JavaPluginConvention import org.gradle.api.plugins.JavaPluginConvention
import org.gradle.api.tasks.SourceSet import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test import org.gradle.api.tasks.testing.Test
import org.hibernate.build.gradle.testing.database.DatabaseProfile import org.hibernate.build.gradle.testing.database.DatabaseProfile
import org.hibernate.build.gradle.testing.database.DatabaseProfilePlugin import org.hibernate.build.gradle.testing.database.DatabaseProfilePlugin
@ -43,7 +42,7 @@ import static org.gradle.api.plugins.JavaPlugin.TEST_RUNTIME_CONFIGURATION_NAME
/** /**
* TODO : 1) add a base configuration of common attribute across all matrix node tasks (convention) * TODO : 1) add a base configuration of common attribute across all matrix node tasks (convention)
* TODO: 2) somehow allow applying just a single database to a project (non matrix testing). * TODO : 2) somehow allow applying just a single database to a project (non matrix testing).
* *
* @author Steve Ebersole * @author Steve Ebersole
* @author Strong Liu * @author Strong Liu
@ -54,14 +53,13 @@ public class MatrixTestingPlugin implements Plugin<Project> {
public static final String MATRIX_COMPILE_CONFIG_NAME = "matrixCompile"; public static final String MATRIX_COMPILE_CONFIG_NAME = "matrixCompile";
public static final String MATRIX_RUNTIME_CONFIG_NAME = "matrixRuntime"; public static final String MATRIX_RUNTIME_CONFIG_NAME = "matrixRuntime";
public static final String MATRIX_TASK_NAME = "matrix"; public static final String MATRIX_TASK_NAME = "matrix";
public static final String MATRIX_SOURCE_SET_NAME = "matrix";
public static final String SKIP_UNIT_TEST = "hibernate-matrix-skip-unittest";
private Project project; private Project project;
private SourceSet testSourceSet;
private Configuration matrixCompileConfig; private Configuration matrixCompileConfig;
private Configuration matrixRuntimeConfig; private Configuration matrixRuntimeConfig;
private Task matrixTask; private Task matrixTask;
private SourceSet matrixSourceSet;
// currently, only the build jdk is supported // currently, only the build jdk is supported
private Jdk theJdk = new Jdk(); private Jdk theJdk = new Jdk();
@ -78,23 +76,16 @@ public class MatrixTestingPlugin implements Plugin<Project> {
matrixCompileConfig = prepareCompileConfiguration(); matrixCompileConfig = prepareCompileConfiguration();
matrixRuntimeConfig = prepareRuntimeConfiguration(); matrixRuntimeConfig = prepareRuntimeConfiguration();
matrixSourceSet = prepareSourceSet(); testSourceSet = project.convention.getPlugin( JavaPluginConvention ).sourceSets
.getByName( SourceSet.TEST_SOURCE_SET_NAME );
matrixTask = prepareGroupingTask(); matrixTask = prepareGroupingTask();
for ( MatrixNode matrixNode: matrixNodes ) { for ( MatrixNode matrixNode: matrixNodes ) {
Task matrixNodeTask = prepareNodeTask( matrixNode ); Task matrixNodeTask = prepareNodeTask( matrixNode );
matrixTask.dependsOn( matrixNodeTask ); matrixTask.dependsOn( matrixNodeTask );
} }
if ( ! shouldSkipMatrixTestsAgainstDefaultDb() ) {
createTestTaskForMatrixSourceSet();
}
} }
private boolean shouldSkipMatrixTestsAgainstDefaultDb() {
return "true".equals( project.properties[SKIP_UNIT_TEST] ) || "true".equals( System.properties[SKIP_UNIT_TEST] );
}
private List<MatrixNode> locateMatrixNodes() { private List<MatrixNode> locateMatrixNodes() {
List<MatrixNode> matrixNodes = new ArrayList<MatrixNode>(); List<MatrixNode> matrixNodes = new ArrayList<MatrixNode>();
Iterable<DatabaseProfile> profiles = project.rootProject.plugins[DatabaseProfilePlugin].databaseProfiles; Iterable<DatabaseProfile> profiles = project.rootProject.plugins[DatabaseProfilePlugin].databaseProfiles;
@ -127,24 +118,6 @@ public class MatrixTestingPlugin implements Plugin<Project> {
.extendsFrom( project.configurations.getByName( TEST_RUNTIME_CONFIGURATION_NAME ) ); .extendsFrom( project.configurations.getByName( TEST_RUNTIME_CONFIGURATION_NAME ) );
} }
private SourceSet prepareSourceSet() {
final SourceSetContainer sourceSets = project.convention.getPlugin( JavaPluginConvention ).sourceSets;
SourceSet sourceSet = sourceSets.findByName( MATRIX_SOURCE_SET_NAME );
if ( sourceSet == null ) {
sourceSet = sourceSets.add( MATRIX_SOURCE_SET_NAME );
}
final SourceSet mainSourceSet = sourceSets.getByName(SourceSet.MAIN_SOURCE_SET_NAME); //sourceSets.main
final SourceSet unitTestSourceSet = sourceSets.getByName(SourceSet.TEST_SOURCE_SET_NAME); //sourceSets.test
sourceSet.compileClasspath = mainSourceSet.output + unitTestSourceSet.output + matrixCompileConfig
sourceSet.runtimeClasspath = sourceSet.output + mainSourceSet.output + unitTestSourceSet.output + matrixRuntimeConfig
sourceSet.output.classesDir = new File(unitTestSourceSet.output.classesDir.parentFile, "matrix")
sourceSet.resources {
setSrcDirs(['src/matrix/java', 'src/matrix/resources'])
}
return sourceSet;
}
private Task prepareGroupingTask() { private Task prepareGroupingTask() {
Task matrixTask = project.tasks.add( MATRIX_TASK_NAME ); Task matrixTask = project.tasks.add( MATRIX_TASK_NAME );
matrixTask.group = "Verification" matrixTask.group = "Verification"
@ -169,60 +142,18 @@ public class MatrixTestingPlugin implements Plugin<Project> {
log.debug( "Adding Matrix Testing task $taskName" ); log.debug( "Adding Matrix Testing task $taskName" );
final Test nodeTask = project.tasks.add( taskName, Test ); final Test nodeTask = project.tasks.add( taskName, Test );
nodeTask.description = "Runs the matrix against ${node.name}" nodeTask.description = "Runs the matrix against ${node.name}"
nodeTask.classpath = node.databaseProfile.testingRuntimeConfiguration + matrixSourceSet.runtimeClasspath nodeTask.classpath = node.databaseProfile.testingRuntimeConfiguration + testSourceSet.runtimeClasspath
nodeTask.testClassesDir = matrixSourceSet.output.classesDir nodeTask.testClassesDir = testSourceSet.output.classesDir
nodeTask.ignoreFailures = true nodeTask.ignoreFailures = true
nodeTask.workingDir = node.baseOutputDirectory nodeTask.workingDir = node.baseOutputDirectory
nodeTask.testReportDir = new File(node.baseOutputDirectory, "reports") nodeTask.testReportDir = new File(node.baseOutputDirectory, "reports")
nodeTask.testResultsDir = new File(node.baseOutputDirectory, "results") nodeTask.testResultsDir = new File(node.baseOutputDirectory, "results")
nodeTask.dependsOn( project.tasks.getByName( matrixSourceSet.classesTaskName ) ); nodeTask.dependsOn( project.tasks.getByName( testSourceSet.classesTaskName ) );
nodeTask.systemProperties = node.databaseAllocation.properties nodeTask.systemProperties = node.databaseAllocation.properties
nodeTask.systemProperties['hibernate.test.validatefailureexpected'] = true nodeTask.systemProperties['hibernate.test.validatefailureexpected'] = true
nodeTask.jvmArgs = ['-Xms1024M', '-Xmx1024M']//, '-XX:MaxPermSize=512M', '-Xss4096k', '-Xverify:none', '-XX:+UseFastAccessorMethods', '-XX:+DisableExplicitGC'] nodeTask.jvmArgs = ['-Xms1024M', '-Xmx1024M']//, '-XX:MaxPermSize=512M', '-Xss4096k', '-Xverify:none', '-XX:+UseFastAccessorMethods', '-XX:+DisableExplicitGC']
nodeTask.maxHeapSize = "1024M" nodeTask.maxHeapSize = "1024M"
return nodeTask; return nodeTask;
} }
/**
* we need create a Test task which runs tests in matrix and also use resources in test.resources
*/
private void createTestTaskForMatrixSourceSet() {
final Test test = project.tasks.test
final Test matrixUnitTask = project.tasks.add("matrixUnitTest", Test)
matrixUnitTask.description = "Run matrix sources as unit test"
matrixUnitTask.classpath = matrixSourceSet.runtimeClasspath
matrixUnitTask.testClassesDir = matrixSourceSet.output.classesDir
matrixUnitTask.workingDir = test.workingDir
matrixUnitTask.testReportDir = test.testReportDir
matrixUnitTask.testResultsDir = test.testResultsDir
matrixUnitTask.systemProperties = test.systemProperties
test.dependsOn matrixUnitTask
def sourceSets = project.convention.getPlugin(JavaPluginConvention).sourceSets
project.tasks.getByName("processMatrixResources").doLast({
project.copy {
from(sourceSets.test.java.srcDirs) {
include '**/*.properties'
include '**/*.xml'
}
into matrixSourceSet.output.classesDir
}
project.copy {
from(sourceSets.test.resources.srcDirs) {
include '**/*.properties'
include '**/*.xml'
}
into matrixSourceSet.output.classesDir
}
project.copy {
from(matrixSourceSet.java.srcDirs) {
include '**/*.properties'
include '**/*.xml'
}
into matrixSourceSet.output.classesDir
}
})
}
} }

View File

@ -32,21 +32,11 @@ dependencies {
testRuntime( libraries.javassist ) testRuntime( libraries.javassist )
} }
compileMatrixJava.options.define(compilerArgs: ["-proc:none", "-encoding", "UTF-8"])
manifest.mainAttributes( manifest.mainAttributes(
'Main-Class': 'org.hibernate.Version' 'Main-Class': 'org.hibernate.Version'
) )
sourceSets {
matrix {
java {
srcDir 'src/matrix/java'
}
resources {
srcDir 'src/matrix/resources'
}
}
}
sourceSets.main { sourceSets.main {
jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" ) jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
java.srcDir jaxbTargetDir java.srcDir jaxbTargetDir
@ -61,8 +51,6 @@ sourceSets.test.resources {
idea { idea {
module { module {
sourceDirs += file( '$buildDir/generated-src/antlr/main' ) sourceDirs += file( '$buildDir/generated-src/antlr/main' )
testSourceDirs += file( 'src/matrix/java')
testSourceDirs += file( 'src/matrix/resources')
} }
} }

View File

@ -1,82 +1,82 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import org.junit.Test; import org.junit.Test;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class CascadeToEmbeddedManyToOneTest extends BaseCoreFunctionalTestCase { public class CascadeToEmbeddedManyToOneTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testPersistCascadeToSetOfEmbedded() { public void testPersistCascadeToSetOfEmbedded() {
Session sess = openSession(); Session sess = openSession();
try { try {
final Transaction trx = sess.beginTransaction(); final Transaction trx = sess.beginTransaction();
try { try {
final Set<PersonPair> setOfPairs = new HashSet<PersonPair>(); final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"))); setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
sess.persist( new CodedPairSetHolder( "CODE", setOfPairs ) ); sess.persist( new CodedPairSetHolder( "CODE", setOfPairs ) );
sess.flush(); sess.flush();
} finally { } finally {
trx.rollback(); trx.rollback();
} }
} finally { } finally {
sess.close(); sess.close();
} }
} }
@Test @Test
public void testPersistCascadeToEmbedded() { public void testPersistCascadeToEmbedded() {
Session sess = openSession(); Session sess = openSession();
try { try {
final Transaction trx = sess.beginTransaction(); final Transaction trx = sess.beginTransaction();
try { try {
PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")); PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"));
sess.persist( new CodedPairHolder( "CODE", personPair ) ); sess.persist( new CodedPairHolder( "CODE", personPair ) );
sess.flush(); sess.flush();
} finally { } finally {
trx.rollback(); trx.rollback();
} }
} finally { } finally {
sess.close(); sess.close();
} }
} }
@Override @Override
protected Class[] getAnnotatedClasses() { protected Class[] getAnnotatedClasses() {
return new Class[]{ return new Class[]{
CodedPairSetHolder.class, CodedPairSetHolder.class,
CodedPairHolder.class, CodedPairHolder.class,
Person.class, Person.class,
PersonPair.class PersonPair.class
}; };
} }
} }

View File

@ -1,61 +1,61 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
/** /**
* @author Jeff Schnitzer * @author Jeff Schnitzer
*/ */
@Entity @Entity
public class Child public class Child
{ {
/** */ /** */
@Id @Id
@GeneratedValue @GeneratedValue
public Long id; public Long id;
/** */ /** */
@ManyToOne(cascade=CascadeType.PERSIST) @ManyToOne(cascade=CascadeType.PERSIST)
@JoinColumn(name="parentId", nullable=false) @JoinColumn(name="parentId", nullable=false)
Parent parent; Parent parent;
/** */ /** */
public Child() {} public Child() {}
/** */ /** */
public Child(Parent p) public Child(Parent p)
{ {
this.parent = p; this.parent = p;
} }
/** */ /** */
public Parent getParent() { return this.parent; } public Parent getParent() { return this.parent; }
public void setParent(Parent value) { this.parent = value; } public void setParent(Parent value) { this.parent = value; }
} }

View File

@ -1,112 +1,112 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import java.io.Serializable; import java.io.Serializable;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set; import java.util.Set;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.ElementCollection; import javax.persistence.ElementCollection;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.JoinTable; import javax.persistence.JoinTable;
import javax.persistence.Table; import javax.persistence.Table;
import org.hibernate.annotations.ForeignKey; import org.hibernate.annotations.ForeignKey;
@Entity @Entity
@Table(name = "CODED_PAIR_SET_HOLDER") @Table(name = "CODED_PAIR_SET_HOLDER")
class CodedPairSetHolder implements Serializable { class CodedPairSetHolder implements Serializable {
private static final long serialVersionUID = 3757670856634990003L; private static final long serialVersionUID = 3757670856634990003L;
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "ID") @Column(name = "ID")
private Long id; private Long id;
@Column(name = "CODE", nullable = false, unique = true, updatable = false, length = 256) @Column(name = "CODE", nullable = false, unique = true, updatable = false, length = 256)
private String code; private String code;
@ElementCollection @ElementCollection
@JoinTable(name = "CODED_PAIR_HOLDER_PAIR_SET", joinColumns = @JoinColumn(name = "CODED_PAIR_HOLDER_ID")) @JoinTable(name = "CODED_PAIR_HOLDER_PAIR_SET", joinColumns = @JoinColumn(name = "CODED_PAIR_HOLDER_ID"))
@ForeignKey(name = "FK_PAIR_SET") @ForeignKey(name = "FK_PAIR_SET")
private final Set<PersonPair> pairs = new HashSet<PersonPair>(0); private final Set<PersonPair> pairs = new HashSet<PersonPair>(0);
CodedPairSetHolder() { CodedPairSetHolder() {
super(); super();
} }
CodedPairSetHolder(final String pCode, final Set<PersonPair> pPersonPairs) { CodedPairSetHolder(final String pCode, final Set<PersonPair> pPersonPairs) {
super(); super();
this.code = pCode; this.code = pCode;
this.pairs.addAll(pPersonPairs); this.pairs.addAll(pPersonPairs);
} }
Long getId() { Long getId() {
return this.id; return this.id;
} }
String getCode() { String getCode() {
return this.code; return this.code;
} }
Set<PersonPair> getPairs() { Set<PersonPair> getPairs() {
return Collections.unmodifiableSet(this.pairs); return Collections.unmodifiableSet(this.pairs);
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 101; final int prime = 101;
int result = 1; int result = 1;
result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode()); result = prime * result + ((getCode() == null) ? 0 : getCode().hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(final Object pObject) { public boolean equals(final Object pObject) {
if (this == pObject) { if (this == pObject) {
return true; return true;
} }
if (pObject == null) { if (pObject == null) {
return false; return false;
} }
if (!(pObject instanceof CodedPairSetHolder )) { if (!(pObject instanceof CodedPairSetHolder )) {
return false; return false;
} }
final CodedPairSetHolder other = (CodedPairSetHolder) pObject; final CodedPairSetHolder other = (CodedPairSetHolder) pObject;
if (getCode() == null) { if (getCode() == null) {
if (other.getCode() != null) { if (other.getCode() != null) {
return false; return false;
} }
} else if (!getCode().equals(other.getCode())) { } else if (!getCode().equals(other.getCode())) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,65 +1,65 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import java.util.Set; import java.util.Set;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.OneToOne; import javax.persistence.OneToOne;
/** /**
* @author Jeff Schnitzer * @author Jeff Schnitzer
*/ */
@Entity @Entity
public class Parent public class Parent
{ {
/** */ /** */
@Id @Id
@GeneratedValue @GeneratedValue
public Long id; public Long id;
/** */ /** */
@OneToMany(cascade=CascadeType.ALL, mappedBy="parent") @OneToMany(cascade=CascadeType.ALL, mappedBy="parent")
public Set<Child> children; public Set<Child> children;
/** */ /** */
@OneToOne(cascade=CascadeType.ALL) @OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="defaultChildId", nullable=false) @JoinColumn(name="defaultChildId", nullable=false)
Child defaultChild; Child defaultChild;
/** */ /** */
public Parent() {} public Parent() {}
/** */ /** */
public Child getDefaultChild() { return this.defaultChild; } public Child getDefaultChild() { return this.defaultChild; }
public void setDefaultChild(Child value) { this.defaultChild = value; } public void setDefaultChild(Child value) { this.defaultChild = value; }
/** */ /** */
public Set<Child> getChildren() { return this.children; } public Set<Child> getChildren() { return this.children; }
public void setChildren(Set<Child> value) { this.children = value; } public void setChildren(Set<Child> value) { this.children = value; }
} }

View File

@ -1,94 +1,94 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.GeneratedValue; import javax.persistence.GeneratedValue;
import javax.persistence.Id; import javax.persistence.Id;
import javax.persistence.Table; import javax.persistence.Table;
@Entity @Entity
@Table(name = "PERSON") @Table(name = "PERSON")
class Person implements Serializable { class Person implements Serializable {
private static final long serialVersionUID = 960914272100925312L; private static final long serialVersionUID = 960914272100925312L;
@Id @Id
@GeneratedValue @GeneratedValue
@Column(name = "ID") @Column(name = "ID")
private Long id; private Long id;
@Column(name = "NAME", nullable = false, unique = true, updatable = false, length = 256) @Column(name = "NAME", nullable = false, unique = true, updatable = false, length = 256)
private String name; private String name;
Person() { Person() {
super(); super();
} }
Person(final String pName) { Person(final String pName) {
super(); super();
this.name = pName; this.name = pName;
} }
Long getId() { Long getId() {
return this.id; return this.id;
} }
String getName() { String getName() {
return this.name; return this.name;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 103; final int prime = 103;
int result = 1; int result = 1;
result = prime * result + ((getName() == null) ? 0 : getName().hashCode()); result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(final Object pObject) { public boolean equals(final Object pObject) {
if (this == pObject) { if (this == pObject) {
return true; return true;
} }
if (pObject == null) { if (pObject == null) {
return false; return false;
} }
if (!(pObject instanceof Person)) { if (!(pObject instanceof Person)) {
return false; return false;
} }
final Person other = (Person) pObject; final Person other = (Person) pObject;
if (getName() == null) { if (getName() == null) {
if (other.getName() != null) { if (other.getName() != null) {
return false; return false;
} }
} else if (!getName().equals(other.getName())) { } else if (!getName().equals(other.getName())) {
return false; return false;
} }
return true; return true;
} }
} }

View File

@ -1,106 +1,106 @@
/* /*
* Hibernate, Relational Persistence for Idiomatic Java * Hibernate, Relational Persistence for Idiomatic Java
* *
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as * Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution * indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are * statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc. * distributed under license by Red Hat Inc.
* *
* This copyrighted material is made available to anyone wishing to use, modify, * This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU * copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation. * Lesser General Public License, as published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details. * for more details.
* *
* You should have received a copy of the GNU Lesser General Public License * You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to: * along with this distribution; if not, write to:
* Free Software Foundation, Inc. * Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor * 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA * Boston, MA 02110-1301 USA
*/ */
package org.hibernate.test.annotations.cascade; package org.hibernate.test.annotations.cascade;
import java.io.Serializable; import java.io.Serializable;
import javax.persistence.CascadeType; import javax.persistence.CascadeType;
import javax.persistence.Embeddable; import javax.persistence.Embeddable;
import javax.persistence.FetchType; import javax.persistence.FetchType;
import javax.persistence.JoinColumn; import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne; import javax.persistence.ManyToOne;
import org.hibernate.annotations.ForeignKey; import org.hibernate.annotations.ForeignKey;
@Embeddable @Embeddable
class PersonPair implements Serializable { class PersonPair implements Serializable {
private static final long serialVersionUID = 4543565503074112720L; private static final long serialVersionUID = 4543565503074112720L;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }) @ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@JoinColumn(name = "LEFT_PERSON_ID", nullable = false, updatable = false) @JoinColumn(name = "LEFT_PERSON_ID", nullable = false, updatable = false)
@ForeignKey(name = "FK_LEFT_PERSON") @ForeignKey(name = "FK_LEFT_PERSON")
private Person left; private Person left;
@ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH }) @ManyToOne(optional = false, fetch = FetchType.LAZY, cascade = { CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH })
@JoinColumn(name = "RIGHT_PERSON_ID", nullable = false, updatable = false) @JoinColumn(name = "RIGHT_PERSON_ID", nullable = false, updatable = false)
@ForeignKey(name = "FK_RIGHT_PERSON") @ForeignKey(name = "FK_RIGHT_PERSON")
private Person right; private Person right;
PersonPair() { PersonPair() {
super(); super();
} }
PersonPair(final Person pLeft, final Person pRight) { PersonPair(final Person pLeft, final Person pRight) {
super(); super();
this.left = pLeft; this.left = pLeft;
this.right = pRight; this.right = pRight;
} }
Person getLeft() { Person getLeft() {
return this.left; return this.left;
} }
Person getRight() { Person getRight() {
return this.right; return this.right;
} }
@Override @Override
public int hashCode() { public int hashCode() {
final int prime = 107; final int prime = 107;
int result = 1; int result = 1;
result = prime * result + ((getLeft() == null) ? 0 : getLeft().hashCode()); result = prime * result + ((getLeft() == null) ? 0 : getLeft().hashCode());
result = prime * result + ((getRight() == null) ? 0 : getRight().hashCode()); result = prime * result + ((getRight() == null) ? 0 : getRight().hashCode());
return result; return result;
} }
@Override @Override
public boolean equals(final Object pObject) { public boolean equals(final Object pObject) {
if (this == pObject) { if (this == pObject) {
return true; return true;
} }
if (pObject == null) { if (pObject == null) {
return false; return false;
} }
if (!(pObject instanceof PersonPair)) { if (!(pObject instanceof PersonPair)) {
return false; return false;
} }
final PersonPair other = (PersonPair) pObject; final PersonPair other = (PersonPair) pObject;
if (getRight() == null) { if (getRight() == null) {
if (other.getRight() != null) { if (other.getRight() != null) {
return false; return false;
} }
} else if (!getRight().equals(other.getRight())) { } else if (!getRight().equals(other.getRight())) {
return false; return false;
} }
if (getLeft() == null) { if (getLeft() == null) {
if (other.getLeft() != null) { if (other.getLeft() != null) {
return false; return false;
} }
} else if (!getLeft().equals(other.getLeft())) { } else if (!getLeft().equals(other.getLeft())) {
return false; return false;
} }
return true; return true;
} }
} }

Some files were not shown because too many files have changed in this diff Show More