@Test public void testRevEntityTableCreation() { for ( Table table : metadata().collectTableMappings() ) { if ( "REVCHANGES".equals( table.getName() ) ) { assert table.getColumnSpan() == 2; assert table.getColumn( new Column( "REV" ) ) != null; assert table.getColumn( new Column( "ENTITYNAME" ) ) != null; return; } } assert false; }
private void assertSameTableUsed(Metadata metadata) { Collection inputs1Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs1" ); assertEquals( "ptx_input", inputs1Mapping.getCollectionTable().getName() ); Collection inputs2Mapping = metadata.getCollectionBinding( Ptx.class.getName() + ".inputs2" ); assertEquals( "ptx_input", inputs2Mapping.getCollectionTable().getName() ); assertSame( inputs1Mapping.getCollectionTable(), inputs2Mapping.getCollectionTable() ); // NOTE : here so that tester can more easily see the produced table. It is only dumped to stdout new SchemaExport().create( EnumSet.of( TargetType.STDOUT ), metadata ); for ( int i = 0; i < inputs1Mapping.getCollectionTable().getColumnSpan(); i++ ) { final Column column = inputs1Mapping.getCollectionTable().getColumn( i ); // this, coupled with JPA saying the 2 collections implicitly map to the same table, // is the crux of the problem: all columns are null, so we effectively can never // insert rows into it. assertFalse( column.isNullable() ); } }
private void checkTableColumns(Set<String> expectedColumns, Set<String> unexpectedColumns, Table table) { for ( String columnName : expectedColumns ) { // Check whether expected column exists. Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. Assert.assertNull( table.getColumn( new Column( columnName ) ) ); } }
protected void checkDefaultJoinTableAndAllColumnNames( Metadata metadata, Class<?> ownerEntityClass, String ownerCollectionPropertyName, String expectedCollectionTableName, String ownerForeignKeyNameExpected, String[] columnNames) { final org.hibernate.mapping.Collection collection = metadata.getCollectionBinding( ownerEntityClass.getName() + '.' + ownerCollectionPropertyName ); final org.hibernate.mapping.Table table = collection.getCollectionTable(); assertEquals( expectedCollectionTableName, table.getName() ); // The default owner and inverse join columns can only be computed if they have PK with 1 column. assertEquals( 1, collection.getOwner().getKey().getColumnSpan() ); assertEquals( ownerForeignKeyNameExpected, collection.getKey().getColumnIterator().next().getText() ); int columnNumber = table.getColumnSpan(); for ( int i = 0; i < columnNumber; i++ ) { assertEquals( columnNames[i], table.getColumn( i + 1 ).getName()); } }
@Test public void testAuditedProperty() { Assert.assertNotNull( classAuditedTable.getColumn( new Column( "number1" ) ) ); Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str1" ) ) ); Assert.assertNotNull( classAuditedTable.getColumn( new Column( "str2" ) ) ); Assert.assertNotNull( classNotAuditedTable.getColumn( new Column( "str2" ) ) ); }
public void addColumn(Column column) { Column old = getColumn( column ); if ( old == null ) { if ( primaryKey != null ) { for ( Column c : primaryKey.getColumns() ) { if ( c.getCanonicalName().equals( column.getCanonicalName() ) ) { column.setNullable( false ); log.debugf( "Forcing column [%s] to be non-null as it is part of the primary key for table [%s]", column.getCanonicalName(), getNameIdentifier().getCanonicalName() ); } } } this.columns.put( column.getCanonicalName(), column ); column.uniqueInteger = this.columns.size(); } else { column.uniqueInteger = old.uniqueInteger; } }
@Test public void testNotAuditedProperty() { Assert.assertNull( mixedTable.getColumn( new Column( "str1" ) ) ); }
@Test public void testNotAuditedProperty() { Assert.assertNull( propertyTable.getColumn( new Column( "str1" ) ) ); }
@Test public void testAuditTableColumns() { Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA1" ) ) ); Assert.assertNotNull( uniquePropsAudit.getTable().getColumn( new Column( "DATA2" ) ) ); Assert.assertNotNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA1" ) ) ); Assert.assertNull( uniquePropsNotAuditedAudit.getTable().getColumn( new Column( "DATA2" ) ) ); }
private void addConstraintToColumn(final String columnName ) { Column column = table.getColumn( new Column( buildingContext.getMetadataCollector().getPhysicalColumnName( table, columnName ) ) ); if ( column == null ) { throw new AnnotationException( "@Index references a unknown column: " + columnName ); } if ( unique ) { table.getOrCreateUniqueKey( indexName ).addColumn( column ); } else { table.getOrCreateIndex( indexName ).addColumn( column ); } }
@Test public void testColumnScalePrecision() { Column testColumn = new Column( "wholeNumber" ); Column scalePrecisionAuditColumn = auditTable.getColumn( testColumn ); Column scalePrecisionColumn = originalTable.getColumn( testColumn ); Assert.assertNotNull( scalePrecisionAuditColumn ); Assert.assertEquals( scalePrecisionColumn.getPrecision(), scalePrecisionAuditColumn.getPrecision() ); Assert.assertEquals( scalePrecisionColumn.getScale(), scalePrecisionAuditColumn.getScale() ); }
@Test public void testCreatedAuditTable() { Set<String> expectedColumns = TestTools.makeSet( "child", "parent", "relation_id", "grandparent", "id" ); Set<String> unexpectedColumns = TestTools.makeSet( "notAudited" ); Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildMultipleParentsEntity_AUD" ).getTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. Assert.assertNull( table.getColumn( new Column( columnName ) ) ); } }
@Test public void testCreatedAuditTable() { Set<String> expectedColumns = TestTools.makeSet( "child", "grandparent", "id" ); Set<String> unexpectedColumns = TestTools.makeSet( "parent", "relation_id", "notAudited" ); Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.ChildSingleParentEntity_AUD" ).getTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. Assert.assertNull( table.getColumn( new Column( columnName ) ) ); } }
@Test public void testCreatedAuditTable() { Set<String> expectedColumns = TestTools.makeSet( "baby", "child", "parent", "relation_id", "grandparent", "id" ); Set<String> unexpectedColumns = TestTools.makeSet( "notAudited" ); Table table = metadata().getEntityBinding( "org.hibernate.envers.test.integration.superclass.auditparents.BabyCompleteEntity_AUD" ).getTable(); for ( String columnName : expectedColumns ) { // Check whether expected column exists. Assert.assertNotNull( table.getColumn( new Column( columnName ) ) ); } for ( String columnName : unexpectedColumns ) { // Check whether unexpected column does not exist. Assert.assertNull( table.getColumn( new Column( columnName ) ) ); } }