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 ) { 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 @Override
public String defaultName() { 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 ) { 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 ) { private void bindUniqueConstraints( final EntityBinding entityBinding, final EntitySource entitySource ) {
int uniqueIndexPerTable = 0;
for ( final ConstraintSource constraintSource : entitySource.getConstraints() ) { for ( final ConstraintSource constraintSource : entitySource.getConstraints() ) {
if ( UniqueConstraintSource.class.isInstance( constraintSource ) ) { if ( UniqueConstraintSource.class.isInstance( constraintSource ) ) {
final TableSpecification table = entityBinding.locateTable( constraintSource.getTableName() ); final TableSpecification table = entityBinding.locateTable( constraintSource.getTableName() );
final String constraintName = constraintSource.name(); uniqueIndexPerTable++;
if ( constraintName == null ) { final String constraintName = StringHelper.isEmpty( constraintSource.name() )
throw new NotYetImplementedException( "create default constraint name" ); ? "key" + uniqueIndexPerTable
} : constraintSource.name();
final UniqueKey uniqueKey = table.getOrCreateUniqueKey( constraintName ); final UniqueKey uniqueKey = table.getOrCreateUniqueKey( constraintName );
for ( final String columnName : constraintSource.columnNames() ) { for ( final String columnName : constraintSource.columnNames() ) {
uniqueKey.addColumn( table.locateOrCreateColumn( quotedIdentifier( columnName ) ) ); uniqueKey.addColumn( table.locateOrCreateColumn( quotedIdentifier( columnName ) ) );
@ -1808,6 +1816,18 @@ public class Binder {
entityClassName, entityClassName,
bindingContext.makeClassReference( entityClassName ), bindingContext.makeClassReference( entityClassName ),
superEntityBinding == null ? null : superEntityBinding.getEntity() ) ); 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 // Create relational table
if ( superEntityBinding != null && inheritanceType == InheritanceType.SINGLE_TABLE ) { if ( superEntityBinding != null && inheritanceType == InheritanceType.SINGLE_TABLE ) {
entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() ); entityBinding.setPrimaryTable( superEntityBinding.getPrimaryTable() );
@ -1851,18 +1871,7 @@ public class Binder {
entitySource.getMetaAttributeSources(), entitySource.getMetaAttributeSources(),
true, true,
metadata.getGlobalMetaAttributeContext() ) ); 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 ) { if ( entitySource.getSynchronizedTableNames() != null ) {
entityBinding.addSynchronizedTableNames( entitySource.getSynchronizedTableNames() ); entityBinding.addSynchronizedTableNames( entitySource.getSynchronizedTableNames() );
} }

View File

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

View File

@ -30,8 +30,6 @@ import java.util.GregorianCalendar;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.hibernate.HibernateException; import org.hibernate.HibernateException;
@ -39,9 +37,7 @@ import org.hibernate.Query;
import org.hibernate.Session; import org.hibernate.Session;
import org.hibernate.StaleStateException; import org.hibernate.StaleStateException;
import org.hibernate.Transaction; import org.hibernate.Transaction;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.hibernate.type.StandardBasicTypes; import org.hibernate.type.StandardBasicTypes;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
@ -52,14 +48,17 @@ import static org.junit.Assert.fail;
/** /**
* @author Emmanuel Bernard * @author Emmanuel Bernard
*/ */
@FailureExpectedWithNewMetamodel
public class EntityTest extends BaseCoreFunctionalTestCase { public class EntityTest extends BaseCoreFunctionalTestCase {
private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); private DateFormat df = SimpleDateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG);
protected boolean isCleanupTestDataRequired() {
return true;
}
@Test @Test
public void testLoad() throws Exception { public void testLoad() throws Exception {
//put an object in DB //put an object in DB
if ( isMetadataUsed ) {
assertEquals( "Flight", getEntityBinding( Flight.class ).getPrimaryTableName() ); assertEquals( "Flight", getEntityBinding( Flight.class ).getPrimaryTableName() );
}
Session s = openSession(); Session s = openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
@ -314,7 +313,9 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
@Test @Test
public void testEntityName() throws Exception { public void testEntityName() throws Exception {
if ( isMetadataUsed ) {
assertEquals( "Corporation", getEntityBinding( Company.class ).getPrimaryTableName() ); assertEquals( "Corporation", getEntityBinding( Company.class ).getPrimaryTableName() );
}
Session s = openSession(); Session s = openSession();
Transaction tx = s.beginTransaction(); Transaction tx = s.beginTransaction();
Company comp = new Company(); Company comp = new Company();
@ -421,27 +422,5 @@ public class EntityTest extends BaseCoreFunctionalTestCase {
Sky.class 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.Session;
import org.hibernate.collection.internal.PersistentBag; import org.hibernate.collection.internal.PersistentBag;
import org.hibernate.testing.FailureExpectedWithNewMetamodel;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase; import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test; import org.junit.Test;
@ -38,7 +37,6 @@ import org.junit.Test;
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@FailureExpectedWithNewMetamodel( jiraKey = "HHH-7680" )
public class PersistentBagTest extends BaseCoreFunctionalTestCase { public class PersistentBagTest extends BaseCoreFunctionalTestCase {
@Override @Override
public String[] getMappings() { public String[] getMappings() {

View File

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

View File

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

View File

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

View File

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