HHH-7706 some minor issues in the metamodel branch

This commit is contained in:
Strong Liu 2012-10-22 17:06:14 +08:00
parent d2a76dbe1a
commit 064c355cd0
8 changed files with 56 additions and 72 deletions

View File

@ -1424,13 +1424,20 @@ public class Binder {
}
private void bindPrimaryTable( final EntityBinding entityBinding, final EntitySource entitySource ) {
entityBinding.setPrimaryTable( createTable( entitySource.getPrimaryTable(), new DefaultNamingStrategy() {
final TableSpecification table = createTable(
entitySource.getPrimaryTable(), new DefaultNamingStrategy() {
@Override
public String defaultName() {
return bindingContexts.peek().getNamingStrategy().classToTableName( entityBinding.getEntity().getClassName() );
String name = StringHelper.isNotEmpty( entityBinding.getJpaEntityName() ) ? entityBinding.getJpaEntityName() : entityBinding
.getEntity()
.getClassName();
return bindingContexts.peek().getNamingStrategy().classToTableName( name );
}
} ) );
}
);
entityBinding.setPrimaryTable( table );
entityBinding.setPrimaryTableName( table.getLogicalName().getText() );
}
private void bindSecondaryTables( final EntityBinding entityBinding, final EntitySource entitySource ) {
@ -1587,13 +1594,14 @@ public class Binder {
}
private void bindUniqueConstraints( final EntityBinding entityBinding, final EntitySource entitySource ) {
int uniqueIndexPerTable = 0;
for ( final ConstraintSource constraintSource : entitySource.getConstraints() ) {
if ( UniqueConstraintSource.class.isInstance( constraintSource ) ) {
final TableSpecification table = entityBinding.locateTable( constraintSource.getTableName() );
final String constraintName = constraintSource.name();
if ( constraintName == null ) {
throw new NotYetImplementedException( "create default constraint name" );
}
uniqueIndexPerTable++;
final String constraintName = StringHelper.isEmpty( constraintSource.name() )
? "key" + uniqueIndexPerTable
: constraintSource.name();
final UniqueKey uniqueKey = table.getOrCreateUniqueKey( constraintName );
for ( final String columnName : constraintSource.columnNames() ) {
uniqueKey.addColumn( table.locateOrCreateColumn( quotedIdentifier( columnName ) ) );
@ -1808,6 +1816,18 @@ public class Binder {
entityClassName,
bindingContext.makeClassReference( entityClassName ),
superEntityBinding == null ? null : superEntityBinding.getEntity() ) );
entityBinding.setJpaEntityName( entitySource.getJpaEntityName() ); //must before creating primary table
entityBinding.setDynamicUpdate( entitySource.isDynamicUpdate() );
entityBinding.setDynamicInsert( entitySource.isDynamicInsert() );
entityBinding.setBatchSize( entitySource.getBatchSize() );
entityBinding.setSelectBeforeUpdate( entitySource.isSelectBeforeUpdate() );
entityBinding.setAbstract( entitySource.isAbstract() );
entityBinding.setCustomLoaderName( entitySource.getCustomLoaderName() );
entityBinding.setCustomInsert( entitySource.getCustomSqlInsert() );
entityBinding.setCustomUpdate( entitySource.getCustomSqlUpdate() );
entityBinding.setCustomDelete( entitySource.getCustomSqlDelete() );
entityBinding.setJpaCallbackClasses( entitySource.getJpaCallbackClasses() );
// Create relational table
if ( superEntityBinding != null && inheritanceType == InheritanceType.SINGLE_TABLE ) {
entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() );
@ -1851,18 +1871,7 @@ public class Binder {
entitySource.getMetaAttributeSources(),
true,
metadata.getGlobalMetaAttributeContext() ) );
entityBinding.setJpaEntityName( entitySource.getJpaEntityName() );
entityBinding.setDynamicUpdate( entitySource.isDynamicUpdate() );
entityBinding.setDynamicInsert( entitySource.isDynamicInsert() );
entityBinding.setBatchSize( entitySource.getBatchSize() );
entityBinding.setSelectBeforeUpdate( entitySource.isSelectBeforeUpdate() );
entityBinding.setAbstract( entitySource.isAbstract() );
entityBinding.setCustomLoaderName( entitySource.getCustomLoaderName() );
entityBinding.setCustomInsert( entitySource.getCustomSqlInsert() );
entityBinding.setCustomUpdate( entitySource.getCustomSqlUpdate() );
entityBinding.setCustomDelete( entitySource.getCustomSqlDelete() );
entityBinding.setJpaCallbackClasses( entitySource.getJpaCallbackClasses() );
if ( entitySource.getSynchronizedTableNames() != null ) {
entityBinding.addSynchronizedTableNames( entitySource.getSynchronizedTableNames() );
}

View File

@ -40,7 +40,7 @@ public abstract class AbstractTableSpecification implements TableSpecification {
private final int tableNumber;
private final List<Value> valueList = new ArrayList<Value>();
private final LinkedHashMap<String, Value> valueMap = new LinkedHashMap<String, Value>();
private final LinkedHashMap<Identifier, Value> valueMap = new LinkedHashMap<Identifier, Value>();
private final PrimaryKey primaryKey = new PrimaryKey( this );
private final List<ForeignKey> foreignKeys = new ArrayList<ForeignKey>();
@ -61,20 +61,23 @@ public abstract class AbstractTableSpecification implements TableSpecification {
@Override
public Column locateOrCreateColumn(String name) {
if ( valueMap.containsKey( name ) ) {
return (Column) valueMap.get( name );
Column column = locateColumn( name );
if(column == null){
column = createColumn( name );
}
return createColumn( name );
return column;
}
@Override
public Column locateColumn(String name) {
if ( valueMap.containsKey( name ) ) {
return (Column) valueMap.get( name );
final Identifier identifier = Identifier.toIdentifier( name );
if ( valueMap.containsKey( identifier ) ) {
return (Column) valueMap.get( identifier );
}
return null;
}
@Override
public Column createColumn(String name) {
return createColumn( Identifier.toIdentifier( name ) );
@ -83,18 +86,19 @@ public abstract class AbstractTableSpecification implements TableSpecification {
@Override
public Column createColumn(Identifier name) {
final Column column = new Column( this, valueList.size(), name );
valueMap.put( name.getText(), column );
valueMap.put( name, column );
valueList.add( column );
return column;
}
@Override
public DerivedValue locateOrCreateDerivedValue(String fragment) {
if ( valueMap.containsKey( fragment ) ) {
return (DerivedValue) valueMap.get( fragment );
final Identifier identifier = Identifier.toIdentifier( fragment );
if ( valueMap.containsKey( identifier ) ) {
return (DerivedValue) valueMap.get( identifier );
}
final DerivedValue value = new DerivedValue( this, valueList.size(), fragment );
valueMap.put( fragment, value );
valueMap.put( identifier, value );
valueList.add( value );
return value;
}

View File

@ -30,8 +30,6 @@ import java.util.GregorianCalendar;
import java.util.List;
import java.util.TimeZone;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.hibernate.HibernateException;
@ -39,9 +37,7 @@ import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.StaleStateException;
import org.hibernate.Transaction;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.type.StandardBasicTypes;
import static org.junit.Assert.assertEquals;
@ -52,14 +48,17 @@ import static org.junit.Assert.fail;
/**
* @author Emmanuel Bernard
*/
@FailureExpectedWithNewMetamodel
public class EntityTest extends BaseCoreFunctionalTestCase {
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
protected boolean isCleanupTestDataRequired() {
return true;
}
@Test
public void testLoad() throws Exception {
//put an object in DB
if ( isMetadataUsed ) {
assertEquals( "Flight", getEntityBinding( Flight.class ).getPrimaryTableName() );
}
Session s = openSession();
Transaction tx = s.beginTransaction();
@ -314,7 +313,9 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
@Test
public void testEntityName() throws Exception {
if ( isMetadataUsed ) {
assertEquals( "Corporation", getEntityBinding( Company.class ).getPrimaryTableName() );
}
Session s = openSession();
Transaction tx = s.beginTransaction();
Company comp = new Company();
@ -421,27 +422,5 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
Sky.class
};
}
// tests are leaving data around, so drop/recreate schema for now. this is wha the old tests did
@Override
protected boolean createSchema() {
return false;
}
@Before
public void runCreateSchema() {
schemaExport().create( false, true );
}
private SchemaExport schemaExport() {
return new SchemaExport( serviceRegistry(), configuration() );
}
@After
public void runDropSchema() {
schemaExport().drop( false, true );
}
}

View File

@ -29,7 +29,6 @@ import java.util.ArrayList;
import org.hibernate.Session;
import org.hibernate.collection.internal.PersistentBag;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -38,7 +37,6 @@ import org.junit.Test;
*
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel( jiraKey = "HHH-7680" )
public class PersistentBagTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {

View File

@ -42,7 +42,6 @@ import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.sql.SimpleSelect;
import org.hibernate.testing.FailureExpected;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -52,7 +51,6 @@ import org.junit.Test;
*
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel( jiraKey = "HHH-7680" )
public class PersistentListTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {

View File

@ -24,7 +24,6 @@
package org.hibernate.test.reattachment;
import org.hibernate.Session;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -33,7 +32,6 @@ import org.junit.Test;
*
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel( jiraKey = "HHH-7680" )
public class CollectionReattachmentTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {

View File

@ -30,7 +30,6 @@ import java.util.Iterator;
import java.util.Set;
import org.hibernate.Session;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
@ -39,7 +38,6 @@ import org.junit.Test;
*
* @author Steve Ebersole
*/
@FailureExpectedWithNewMetamodel( jiraKey = "HHH-7680" )
public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
@Override
public String[] getMappings() {
@ -100,7 +98,6 @@ public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
@Test
@SuppressWarnings( {"unchecked"})
@FailureExpectedWithNewMetamodel
public void testIterateWithClearTopOfLoop() {
Session s = openSession();
s.beginTransaction();
@ -142,7 +139,6 @@ public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
@Test
@SuppressWarnings( {"unchecked"})
@FailureExpectedWithNewMetamodel
public void testIterateWithClearBottomOfLoop() {
Session s = openSession();
s.beginTransaction();
@ -184,7 +180,6 @@ public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
@Test
@SuppressWarnings( {"unchecked"})
@FailureExpectedWithNewMetamodel
public void testIterateWithEvictTopOfLoop() {
Session s = openSession();
s.beginTransaction();
@ -222,7 +217,6 @@ public class ProxyReattachmentTest extends BaseCoreFunctionalTestCase {
@Test
@SuppressWarnings( {"unchecked"})
@FailureExpectedWithNewMetamodel
public void testIterateWithEvictBottomOfLoop() {
Session s = openSession();
s.beginTransaction();

View File

@ -89,7 +89,7 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
public static final Dialect DIALECT = Dialect.getDialect();
private boolean isMetadataUsed;
protected boolean isMetadataUsed;
private Configuration configuration;
private MetadataImplementor metadataImplementor;
private StandardServiceRegistryImpl serviceRegistry;
@ -502,7 +502,11 @@ public abstract class BaseCoreFunctionalTestCase extends BaseUnitTestCase {
sessionFactory.getCache().evictNaturalIdRegions();
}
}
protected boolean isCleanupTestDataRequired(){return false;}
protected boolean isCleanupTestDataRequired() {
return false;
}
protected void cleanupTestData() throws Exception {
Session s = openSession();
s.beginTransaction();