@Override protected void augmentIdTableDefinition(Table idTable) { Column sessionIdColumn = new Column( Helper.SESSION_ID_COLUMN_NAME ); sessionIdColumn.setSqlType( "CHAR(36)" ); sessionIdColumn.setComment( "Used to hold the Hibernate Session identifier" ); idTable.addColumn( sessionIdColumn ); }
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 ) ) ); } }
@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" ) ) ); }
@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; }
@Test public void testNotAuditedProperty() { Assert.assertNull( propertyTable.getColumn( new Column( "str1" ) ) ); }
@Test public void testNotAuditedProperty() { Assert.assertNull( mixedTable.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 testDefaultValue() throws Exception { Join join = (Join) metadata().getEntityBinding( Life.class.getName() ).getJoinClosureIterator().next(); assertEquals( "ExtendedLife", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); owner.setName( "LIFE_ID" ); assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); Life life = new Life(); life.duration = 15; life.fullDescription = "Long long description"; s.persist( life ); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Query q = s.createQuery( "from " + Life.class.getName() ); life = (Life) q.uniqueResult(); assertEquals( "Long long description", life.fullDescription ); tx.commit(); s.close(); }
@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( "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 testCompositePK() throws Exception { Join join = (Join) metadata().getEntityBinding( Dog.class.getName() ).getJoinClosureIterator().next(); assertEquals( "DogThoroughbred", join.getTable().getName() ); org.hibernate.mapping.Column owner = new org.hibernate.mapping.Column(); owner.setName( "OWNER_NAME" ); assertTrue( join.getTable().getPrimaryKey().containsColumn( owner ) ); Session s = openSession(); Transaction tx = s.beginTransaction(); Dog dog = new Dog(); DogPk id = new DogPk(); id.name = "Thalie"; id.ownerName = "Martine"; dog.id = id; dog.weight = 30; dog.thoroughbredName = "Colley"; s.persist( dog ); tx.commit(); s.close(); s = openSession(); tx = s.beginTransaction(); Query q = s.createQuery( "from Dog" ); dog = (Dog) q.uniqueResult(); assertEquals( "Colley", dog.thoroughbredName ); tx.commit(); s.close(); }
foreignKey.addColumn( new Column( "id" ) ); foreignKey.setReferencedTable( new Table( "table2" ) );
@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 ) ) ); } }
@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() ); }
/** * Shallow copy, the value is not copied */ @Override public Column clone() { Column copy = new Column(); copy.setLength( length ); copy.setScale( scale ); copy.setValue( value ); copy.setTypeIndex( typeIndex ); copy.setName( getQuotedName() ); copy.setNullable( nullable ); copy.setPrecision( precision ); copy.setUnique( unique ); copy.setSqlType( sqlType ); copy.setSqlTypeCode( sqlTypeCode ); copy.uniqueInteger = uniqueInteger; //usually useless copy.setCheckConstraint( checkConstraint ); copy.setComment( comment ); copy.setDefaultValue( defaultValue ); copy.setCustomRead( customRead ); copy.setCustomWrite( customWrite ); return copy; }