HHH-6381 Adding a actual assertion which tests the optional part. Also applying formatting styles.
This commit is contained in:
parent
20559966b3
commit
d1eec59c08
|
@ -112,7 +112,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
// Span of the tables directly mapped by this entity and super-classes, if any
|
// Span of the tables directly mapped by this entity and super-classes, if any
|
||||||
private final int coreTableSpan;
|
private final int coreTableSpan;
|
||||||
// only contains values for SecondaryTables ie. not tables part of the "coreTableSpan"
|
// only contains values for SecondaryTables, ie. not tables part of the "coreTableSpan"
|
||||||
private final boolean[] isNullableTable;
|
private final boolean[] isNullableTable;
|
||||||
|
|
||||||
//INITIALIZATION:
|
//INITIALIZATION:
|
||||||
|
@ -187,21 +187,21 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
isNullableTable = new boolean[persistentClass.getJoinClosureSpan()];
|
isNullableTable = new boolean[persistentClass.getJoinClosureSpan()];
|
||||||
|
|
||||||
int tabIndex = 0;
|
int tableIndex = 0;
|
||||||
Iterator joinIter = persistentClass.getJoinClosureIterator();
|
Iterator joinIter = persistentClass.getJoinClosureIterator();
|
||||||
while ( joinIter.hasNext() ) {
|
while ( joinIter.hasNext() ) {
|
||||||
Join join = (Join) joinIter.next();
|
Join join = (Join) joinIter.next();
|
||||||
|
|
||||||
isNullableTable[tabIndex++] = join.isOptional();
|
isNullableTable[tableIndex++] = join.isOptional();
|
||||||
|
|
||||||
Table tab = join.getTable();
|
Table table = join.getTable();
|
||||||
|
|
||||||
String tabname = tab.getQualifiedName(
|
String tableName = table.getQualifiedName(
|
||||||
factory.getDialect(),
|
factory.getDialect(),
|
||||||
factory.getSettings().getDefaultCatalogName(),
|
factory.getSettings().getDefaultCatalogName(),
|
||||||
factory.getSettings().getDefaultSchemaName()
|
factory.getSettings().getDefaultSchemaName()
|
||||||
);
|
);
|
||||||
tables.add(tabname);
|
tables.add( tableName );
|
||||||
|
|
||||||
KeyValue key = join.getKey();
|
KeyValue key = join.getKey();
|
||||||
int joinIdColumnSpan = key.getColumnSpan();
|
int joinIdColumnSpan = key.getColumnSpan();
|
||||||
|
@ -279,7 +279,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
|
key[k] = ( (Column) citer.next() ).getQuotedName( factory.getDialect() );
|
||||||
}
|
}
|
||||||
keyColumns.add( key );
|
keyColumns.add( key );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] naturalOrderSubclassTableNameClosure = ArrayHelper.toStringArray( subtables );
|
String[] naturalOrderSubclassTableNameClosure = ArrayHelper.toStringArray( subtables );
|
||||||
|
@ -543,8 +542,9 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isNullableTable(int j) {
|
protected boolean isNullableTable(int j) {
|
||||||
if (j < coreTableSpan)
|
if ( j < coreTableSpan ) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
return isNullableTable[j - coreTableSpan];
|
return isNullableTable[j - coreTableSpan];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,7 +552,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
|
return subclassTableSequentialSelect[j] && !isClassOrSuperclassTable[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*public void postInstantiate() throws MappingException {
|
/*public void postInstantiate() throws MappingException {
|
||||||
super.postInstantiate();
|
super.postInstantiate();
|
||||||
//TODO: other lock modes?
|
//TODO: other lock modes?
|
||||||
|
@ -622,7 +621,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
throw new JDBCException( "could not load by id: " + MessageHelper.infoString(this, id), sqle );
|
throw new JDBCException( "could not load by id: " + MessageHelper.infoString(this, id), sqle );
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
private static final void reverse(Object[] objects, int len) {
|
private static final void reverse(Object[] objects, int len) {
|
||||||
Object[] temp = new Object[len];
|
Object[] temp = new Object[len];
|
||||||
for ( int i = 0; i < len; i++ ) {
|
for ( int i = 0; i < len; i++ ) {
|
||||||
|
@ -636,11 +634,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the first n elements of the incoming array
|
* Reverse the first n elements of the incoming array
|
||||||
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* @param n
|
* @param n
|
||||||
|
*
|
||||||
* @return New array with the first n elements in reversed order
|
* @return New array with the first n elements in reversed order
|
||||||
*/
|
*/
|
||||||
private static final String[] reverse(String [] objects, int n) {
|
private static String[] reverse(String[] objects, int n) {
|
||||||
|
|
||||||
int size = objects.length;
|
int size = objects.length;
|
||||||
String[] temp = new String[size];
|
String[] temp = new String[size];
|
||||||
|
@ -658,11 +658,13 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the first n elements of the incoming array
|
* Reverse the first n elements of the incoming array
|
||||||
|
*
|
||||||
* @param objects
|
* @param objects
|
||||||
* @param n
|
* @param n
|
||||||
|
*
|
||||||
* @return New array with the first n elements in reversed order
|
* @return New array with the first n elements in reversed order
|
||||||
*/
|
*/
|
||||||
private static final String[][] reverse(String[][] objects, int n) {
|
private static String[][] reverse(String[][] objects, int n) {
|
||||||
int size = objects.length;
|
int size = objects.length;
|
||||||
String[][] temp = new String[size][];
|
String[][] temp = new String[size][];
|
||||||
for ( int i = 0; i < n; i++ ) {
|
for ( int i = 0; i < n; i++ ) {
|
||||||
|
@ -677,7 +679,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public String fromTableFragment(String alias) {
|
public String fromTableFragment(String alias) {
|
||||||
return getTableName() + ' ' + alias;
|
return getTableName() + ' ' + alias;
|
||||||
}
|
}
|
||||||
|
@ -738,7 +739,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String[] toColumns(String alias, String propertyName) throws QueryException {
|
public String[] toColumns(String alias, String propertyName) throws QueryException {
|
||||||
|
|
||||||
if ( ENTITY_CLASS.equals( propertyName ) ) {
|
if ( ENTITY_CLASS.equals( propertyName ) ) {
|
||||||
// This doesn't actually seem to work but it *might*
|
// This doesn't actually seem to work but it *might*
|
||||||
// work on some dbs. Also it doesn't work if there
|
// work on some dbs. Also it doesn't work if there
|
||||||
|
@ -751,7 +751,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
|
||||||
else {
|
else {
|
||||||
return super.toColumns( alias, propertyName );
|
return super.toColumns( alias, propertyName );
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int[] getPropertyTableNumbersInSelect() {
|
protected int[] getPropertyTableNumbersInSelect() {
|
||||||
|
|
|
@ -23,11 +23,12 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.test.annotations.inheritance.joined;
|
package org.hibernate.test.annotations.inheritance.joined;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import java.math.BigInteger;
|
||||||
import org.hibernate.Transaction;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import org.hibernate.Session;
|
||||||
|
import org.hibernate.Transaction;
|
||||||
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
@ -42,22 +43,34 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
||||||
Session s = openSession();
|
Session s = openSession();
|
||||||
Transaction tx = s.beginTransaction();
|
Transaction tx = s.beginTransaction();
|
||||||
SwimmingPool sp = new SwimmingPool();
|
SwimmingPool sp = new SwimmingPool();
|
||||||
//sp.setAddress( "Park Avenue" );
|
|
||||||
s.persist( sp );
|
s.persist( sp );
|
||||||
s.flush();
|
s.flush();
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
|
BigInteger rowCount = getTableRowCount( s );
|
||||||
|
assertEquals(
|
||||||
|
"The address table is marked as optional. For null values no database row should be created",
|
||||||
|
BigInteger.valueOf( 0 ),
|
||||||
|
rowCount
|
||||||
|
);
|
||||||
|
|
||||||
SwimmingPool sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
SwimmingPool sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||||
assertEquals( sp.getAddress(), null );
|
assertEquals( sp.getAddress(), null );
|
||||||
|
|
||||||
PoolAddress addr = new PoolAddress();
|
PoolAddress address = new PoolAddress();
|
||||||
addr.setAddress("Park Avenue");
|
address.setAddress( "Park Avenue" );
|
||||||
sp2.setAddress(addr);
|
sp2.setAddress( address );
|
||||||
|
|
||||||
s.flush();
|
s.flush();
|
||||||
s.clear();
|
s.clear();
|
||||||
|
|
||||||
sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
sp2 = (SwimmingPool) s.get( SwimmingPool.class, sp.getId() );
|
||||||
|
rowCount = getTableRowCount( s );
|
||||||
|
assertEquals(
|
||||||
|
"Now we should have a row in the pool address table ",
|
||||||
|
BigInteger.valueOf( 1 ),
|
||||||
|
rowCount
|
||||||
|
);
|
||||||
assertFalse( sp2.getAddress() == null );
|
assertFalse( sp2.getAddress() == null );
|
||||||
assertEquals( sp2.getAddress().getAddress(), "Park Avenue" );
|
assertEquals( sp2.getAddress().getAddress(), "Park Avenue" );
|
||||||
|
|
||||||
|
@ -65,9 +78,12 @@ public class JoinedSubclassAndSecondaryTable extends BaseCoreFunctionalTestCase
|
||||||
s.close();
|
s.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigInteger getTableRowCount(Session s) {
|
||||||
|
return (BigInteger) s.createSQLQuery( "select count(*) from POOL_ADDRESS" ).uniqueResult();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class[] getAnnotatedClasses() {
|
protected Class[] getAnnotatedClasses() {
|
||||||
return new Class[] { Pool.class, SwimmingPool.class };
|
return new Class[] { Pool.class, SwimmingPool.class };
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -409,5 +409,4 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue