private void alignColumns(Table referencedTable) { final int referencedPkColumnSpan = referencedTable.getPrimaryKey().getColumnSpan(); if ( referencedPkColumnSpan != getColumnSpan() ) { StringBuilder sb = new StringBuilder(); sb.append( "Foreign key (" ).append( getName() ).append( ":" ) .append( getTable().getName() ) .append( " [" ); appendColumns( sb, getColumnIterator() ); sb.append( "])" ) .append( ") must have same number of columns as the referenced primary key (" ) .append( referencedTable.getName() ) .append( " [" ); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); sb.append( "])" ); throw new MappingException( sb.toString() ); } Iterator fkCols = getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); while ( pkCols.hasNext() ) { ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() ); } }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey( getCollectionTable() ); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Object selectable = iter.next(); if ( selectable instanceof Column ) { Column col = (Column) selectable; if ( !col.isNullable() ) { pk.addColumn( col ); } else { return; } } } if ( pk.getColumnSpan() == getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getCollectionTable().setPrimaryKey( pk ); } } else { //create an index on the key columns?? } }
if ( numberOfColumns != foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan() ) { throw new AssertionFailure( String.format( COLUMN_MISMATCH_MSG, numberOfColumns, foreignKey.getReferencedTable().getPrimaryKey().getColumnSpan(), foreignKey.getName(), foreignKey.getTable().getName(),
private void alignColumns(Table referencedTable) { if ( referencedTable.getPrimaryKey().getColumnSpan()!=getColumnSpan() ) { StringBuffer sb = new StringBuffer(); sb.append("Foreign key (") .append( getName() + ":") .append( getTable().getName() ) .append(" ["); appendColumns( sb, getColumnIterator() ); sb.append("])") .append(") must have same number of columns as the referenced primary key (") .append( referencedTable.getName() ) .append(" ["); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); sb.append("])"); throw new MappingException( sb.toString() ); } Iterator fkCols = getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); while ( pkCols.hasNext() ) { ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() ); } }
private void alignColumns(Table referencedTable) { if ( referencedTable.getPrimaryKey().getColumnSpan()!=getColumnSpan() ) { StringBuffer sb = new StringBuffer(); sb.append("Foreign key (") .append( getName() + ":") .append( getTable().getName() ) .append(" ["); appendColumns( sb, getColumnIterator() ); sb.append("])") .append(") must have same number of columns as the referenced primary key (") .append( referencedTable.getName() ) .append(" ["); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); sb.append("])"); throw new MappingException( sb.toString() ); } Iterator fkCols = getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); while ( pkCols.hasNext() ) { ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() ); } }
private void alignColumns(Table referencedTable) { if ( referencedTable.getPrimaryKey().getColumnSpan()!=getColumnSpan() ) { StringBuffer sb = new StringBuffer(); sb.append("Foreign key (") .append( getName() + ":") .append( getTable().getName() ) .append(" ["); appendColumns( sb, getColumnIterator() ); sb.append("])") .append(") must have same number of columns as the referenced primary key (") .append( referencedTable.getName() ) .append(" ["); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); sb.append("])"); throw new MappingException( sb.toString() ); } Iterator fkCols = getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); while ( pkCols.hasNext() ) { ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() ); } }
/** * Validates that columnspan of the foreignkey and the primarykey is the same. * * Furthermore it aligns the length of the underlying tables. * @param referencedTable */ private void alignColumns(Table referencedTable) { if ( referencedTable.getPrimaryKey().getColumnSpan()!=getColumnSpan() ) { StringBuffer sb = new StringBuffer(); sb.append("Foreign key (") .append( getName() + ":") .append( getTable().getName() ) .append(" ["); appendColumns( sb, getColumnIterator() ); sb.append("])") .append(") must have same number of columns as the referenced primary key (") .append( referencedTable.getName() ) .append(" ["); appendColumns( sb, referencedTable.getPrimaryKey().getColumnIterator() ); sb.append("])"); throw new MappingException( sb.toString() ); } Iterator fkCols = getColumnIterator(); Iterator pkCols = referencedTable.getPrimaryKey().getColumnIterator(); while ( pkCols.hasNext() ) { ( (Column) fkCols.next() ).setLength( ( (Column) pkCols.next() ).getLength() ); } }
@Test public void testCompositeKeys() { Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "MULTIKEYED")); PrimaryKey primaryKey = table.getPrimaryKey(); Assert.assertEquals( 2, primaryKey.getColumnSpan() ); }
@Test public void testCompositeKeys() { Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "MULTIKEYED")); PrimaryKey primaryKey = table.getPrimaryKey(); Assert.assertEquals(2, primaryKey.getColumnSpan()); }
@Test public void testCompositeKeys() { Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "MULTIKEYED")); PrimaryKey primaryKey = table.getPrimaryKey(); Assert.assertEquals( 2, primaryKey.getColumnSpan() ); }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey(); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Column col = (Column) iter.next(); if ( !col.isNullable() ) { pk.addColumn(col); } } if ( pk.getColumnSpan()==getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getCollectionTable().setPrimaryKey(pk); } } else { //create an index on the key columns?? } }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey(); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Object selectable = iter.next(); if ( selectable instanceof Column ) { Column col = (Column) selectable; if ( !col.isNullable() ) { pk.addColumn(col); } } } if ( pk.getColumnSpan()==getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getCollectionTable().setPrimaryKey(pk); } } else { //create an index on the key columns?? } }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey(); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Object selectable = iter.next(); if ( selectable instanceof Column ) { Column col = (Column) selectable; if ( !col.isNullable() ) { pk.addColumn(col); } } } if ( pk.getColumnSpan()==getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getCollectionTable().setPrimaryKey(pk); } } else { //create an index on the key columns?? } }
void createPrimaryKey() { if ( !isOneToMany() ) { PrimaryKey pk = new PrimaryKey(); pk.addColumns( getKey().getColumnIterator() ); Iterator iter = getElement().getColumnIterator(); while ( iter.hasNext() ) { Object selectable = iter.next(); if ( selectable instanceof Column ) { Column col = (Column) selectable; if ( !col.isNullable() ) { pk.addColumn(col); } } } if ( pk.getColumnSpan()==getKey().getColumnSpan() ) { //for backward compatibility, allow a set with no not-null //element columns, using all columns in the row locater SQL //TODO: create an implicit not null constraint on all cols? } else { getCollectionTable().setPrimaryKey(pk); } } else { //create an index on the key columns?? } }
@Test public void testBasic() throws SQLException { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC")); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName())); Assert.assertEquals(2, table.getColumnSpan()); Column basicColumn = table.getColumn(0); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName())); PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull("There should be a primary key!", key); Assert.assertEquals(key.getColumnSpan(), 1); Column column = key.getColumn(0); Assert.assertTrue(column.isUnique()); Assert.assertSame(basicColumn, column); }
@Test public void testBasic() { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC" ) ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName())); Assert.assertEquals( 2, table.getColumnSpan() ); Column basicColumn = table.getColumn( 0 ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName())); // TODO: we cannot call getSqlType(dialect,cfg) without a // MappingassertEquals("INTEGER", basicColumn.getSqlType() ); // at // least on hsqldb // assertEquals(22, basicColumn.getLength() ); // at least on oracle PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull( "There should be a primary key!", key ); Assert.assertEquals( key.getColumnSpan(), 1 ); Column column = key.getColumn( 0 ); Assert.assertTrue( column.isUnique() ); Assert.assertSame( basicColumn, column ); }
@Test public void testBasic() throws SQLException { JUnitUtil.assertIteratorContainsExactly( "There should be three tables!", metadata.getEntityBindings().iterator(), 3); Table table = HibernateUtil.getTable( metadata, JdbcUtil.toIdentifier(this, "BASIC" ) ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "BASIC"), JdbcUtil.toIdentifier(this, table.getName()) ); Assert.assertEquals( 2, table.getColumnSpan() ); Column basicColumn = table.getColumn( 0 ); Assert.assertEquals( JdbcUtil.toIdentifier(this, "A"), JdbcUtil.toIdentifier(this, basicColumn.getName() )); // TODO: we cannot call getSqlType(dialect,cfg) without a // MappingassertEquals("INTEGER", basicColumn.getSqlType() ); // at // least on hsqldb // assertEquals(22, basicColumn.getLength() ); // at least on oracle PrimaryKey key = table.getPrimaryKey(); Assert.assertNotNull( "There should be a primary key!", key ); Assert.assertEquals( key.getColumnSpan(), 1 ); Column column = key.getColumn( 0 ); Assert.assertTrue( column.isUnique() ); Assert.assertSame( basicColumn, column ); }