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.plugins.JavaPluginConvention
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.testing.Test
import org.hibernate.build.gradle.testing.database.DatabaseProfile
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: 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 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_RUNTIME_CONFIG_NAME = "matrixRuntime";
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 SourceSet testSourceSet;
private Configuration matrixCompileConfig;
private Configuration matrixRuntimeConfig;
private Task matrixTask;
private SourceSet matrixSourceSet;
// currently, only the build jdk is supported
private Jdk theJdk = new Jdk();
@ -78,23 +76,16 @@ public class MatrixTestingPlugin implements Plugin<Project> {
matrixCompileConfig = prepareCompileConfiguration();
matrixRuntimeConfig = prepareRuntimeConfiguration();
matrixSourceSet = prepareSourceSet();
testSourceSet = project.convention.getPlugin( JavaPluginConvention ).sourceSets
.getByName( SourceSet.TEST_SOURCE_SET_NAME );
matrixTask = prepareGroupingTask();
for ( MatrixNode matrixNode: matrixNodes ) {
Task matrixNodeTask = prepareNodeTask( matrixNode );
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() {
List<MatrixNode> matrixNodes = new ArrayList<MatrixNode>();
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 ) );
}
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() {
Task matrixTask = project.tasks.add( MATRIX_TASK_NAME );
matrixTask.group = "Verification"
@ -169,60 +142,18 @@ public class MatrixTestingPlugin implements Plugin<Project> {
log.debug( "Adding Matrix Testing task $taskName" );
final Test nodeTask = project.tasks.add( taskName, Test );
nodeTask.description = "Runs the matrix against ${node.name}"
nodeTask.classpath = node.databaseProfile.testingRuntimeConfiguration + matrixSourceSet.runtimeClasspath
nodeTask.testClassesDir = matrixSourceSet.output.classesDir
nodeTask.classpath = node.databaseProfile.testingRuntimeConfiguration + testSourceSet.runtimeClasspath
nodeTask.testClassesDir = testSourceSet.output.classesDir
nodeTask.ignoreFailures = true
nodeTask.workingDir = node.baseOutputDirectory
nodeTask.testReportDir = new File(node.baseOutputDirectory, "reports")
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['hibernate.test.validatefailureexpected'] = true
nodeTask.jvmArgs = ['-Xms1024M', '-Xmx1024M']//, '-XX:MaxPermSize=512M', '-Xss4096k', '-Xverify:none', '-XX:+UseFastAccessorMethods', '-XX:+DisableExplicitGC']
nodeTask.maxHeapSize = "1024M"
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 )
}
compileMatrixJava.options.define(compilerArgs: ["-proc:none", "-encoding", "UTF-8"])
manifest.mainAttributes(
'Main-Class': 'org.hibernate.Version'
)
sourceSets {
matrix {
java {
srcDir 'src/matrix/java'
}
resources {
srcDir 'src/matrix/resources'
}
}
}
sourceSets.main {
jaxbTargetDir = file( "${buildDir}/generated-src/jaxb/main" )
java.srcDir jaxbTargetDir
@ -61,8 +51,6 @@ sourceSets.test.resources {
idea {
module {
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
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* 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
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class CascadeToEmbeddedManyToOneTest extends BaseCoreFunctionalTestCase {
@Test
public void testPersistCascadeToSetOfEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
sess.persist( new CodedPairSetHolder( "CODE", setOfPairs ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Test
public void testPersistCascadeToEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"));
sess.persist( new CodedPairHolder( "CODE", personPair ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
CodedPairSetHolder.class,
CodedPairHolder.class,
Person.class,
PersonPair.class
};
}
}
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* 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
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.test.annotations.cascade;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
public class CascadeToEmbeddedManyToOneTest extends BaseCoreFunctionalTestCase {
@Test
public void testPersistCascadeToSetOfEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
final Set<PersonPair> setOfPairs = new HashSet<PersonPair>();
setOfPairs.add(new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2")));
sess.persist( new CodedPairSetHolder( "CODE", setOfPairs ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Test
public void testPersistCascadeToEmbedded() {
Session sess = openSession();
try {
final Transaction trx = sess.beginTransaction();
try {
PersonPair personPair = new PersonPair(new Person("PERSON NAME 1"), new Person("PERSON NAME 2"));
sess.persist( new CodedPairHolder( "CODE", personPair ) );
sess.flush();
} finally {
trx.rollback();
}
} finally {
sess.close();
}
}
@Override
protected Class[] getAnnotatedClasses() {
return new Class[]{
CodedPairSetHolder.class,
CodedPairHolder.class,
Person.class,
PersonPair.class
};
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

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