private boolean hasNullable(org.hibernate.mapping.UniqueKey uniqueKey) { final Iterator<org.hibernate.mapping.Column> iter = uniqueKey.columnIterator(); while ( iter.hasNext() ) { if ( iter.next().isNullable() ) { return true; } } return false; } }
public boolean isNullable() { return isFormula() ? true : mappingColumn.isNullable(); }
public boolean isNullable() { Iterator itr = getColumnIterator(); while ( itr.hasNext() ) { final Object selectable = itr.next(); if ( selectable instanceof Formula ) { // if there are *any* formulas, then the Value overall is // considered nullable return true; } else if ( !( (Column) selectable ).isNullable() ) { // if there is a single non-nullable column, the Value // overall is considered non-nullable. return false; } } // nullable by default return true; }
protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) { final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment(); final Dialect dialect = jdbcEnvironment.getDialect(); StringBuilder buffer = new StringBuilder( getIdTableSupport().getCreateIdTableCommand() ) .append( ' ' ) .append( jdbcEnvironment.getQualifiedObjectNameFormatter().format( idTable.getQualifiedTableName(), dialect ) ) .append( " (" ); Iterator itr = idTable.getColumnIterator(); while ( itr.hasNext() ) { final Column column = (Column) itr.next(); buffer.append( column.getQuotedName( dialect ) ).append( ' ' ); buffer.append( column.getSqlType( dialect, metadata ) ); if ( column.isNullable() ) { buffer.append( dialect.getNullColumnString() ); } else { buffer.append( " not null" ); } if ( itr.hasNext() ) { buffer.append( ", " ); } } buffer.append( ") " ); if ( getIdTableSupport().getCreateIdTableStatementOptions() != null ) { buffer.append( getIdTableSupport().getCreateIdTableStatementOptions() ); } return buffer.toString(); }
if ( column.isNullable() ) { alter.append( dialect.getNullColumnString() );
if ( col.isNullable() ) { buf.append( dialect.getNullColumnString() );
@Test public void testNotNullOnlyAppliedIfEmbeddedIsNotNullItself() throws Exception { PersistentClass classMapping = metadata().getEntityBinding( Tv.class.getName() ); Property property = classMapping.getProperty( "tuner.frequency" ); Column serialColumn = (Column) property.getColumnIterator().next(); assertEquals( "Validator annotations are applied on tuner as it is @NotNull", false, serialColumn.isNullable() ); property = classMapping.getProperty( "recorder.time" ); serialColumn = (Column) property.getColumnIterator().next(); assertEquals( "Validator annotations are applied on tuner as it is @NotNull", true, serialColumn.isNullable() ); }
@Test public void testDDLDisabled() { PersistentClass classMapping = metadata().getEntityBinding( Address.class.getName() ); Column countryColumn = (Column) classMapping.getProperty( "country" ).getColumnIterator().next(); assertTrue( "DDL constraints are applied", countryColumn.isNullable() ); }
@Test public void testApplyOnManyToOne() throws Exception { PersistentClass classMapping = metadata().getEntityBinding( TvOwner.class.getName() ); Column serialColumn = (Column) classMapping.getProperty( "tv" ).getColumnIterator().next(); assertEquals( "Validator annotations not applied on associations", false, serialColumn.isNullable() ); }
@Test public void testSingleTableAvoidNotNull() throws Exception { PersistentClass classMapping = metadata().getEntityBinding( Rock.class.getName() ); Column serialColumn = (Column) classMapping.getProperty( "bit" ).getColumnIterator().next(); assertTrue( "Notnull should not be applied on single tables", serialColumn.isNullable() ); }
if ( col.isNullable() ) { buf.append( dialect.getNullColumnString() );
@Test @TestForIssue( jiraKey = "HHH-7797" ) public void testUniqueConstraints() { Column column = (Column) metadata().getEntityBinding( DataPoint.class.getName() ) .getProperty( "foo1" ).getColumnIterator().next(); assertFalse( column.isNullable() ); assertTrue( column.isUnique() ); column = (Column) metadata().getEntityBinding( DataPoint.class.getName() ) .getProperty( "foo2" ).getColumnIterator().next(); assertTrue( column.isNullable() ); assertTrue( column.isUnique() ); column = (Column) metadata().getEntityBinding( DataPoint.class.getName() ) .getProperty( "id" ).getColumnIterator().next(); assertFalse( column.isNullable() ); assertTrue( column.isUnique() ); }
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?? } }
private void makeOneToManyMapKeyColumnNullableIfNotInProperty( final XProperty property) { final org.hibernate.mapping.Map map = (org.hibernate.mapping.Map) this.collection; if ( map.isOneToMany() && property.isAnnotationPresent( MapKeyColumn.class ) ) { final Value indexValue = map.getIndex(); if ( indexValue.getColumnSpan() != 1 ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn does not have 1 column" ); } final Selectable selectable = indexValue.getColumnIterator().next(); if ( selectable.isFormula() ) { throw new AssertionFailure( "Map key mapped by @MapKeyColumn is a Formula" ); } Column column = (Column) map.getIndex().getColumnIterator().next(); if ( !column.isNullable() ) { final PersistentClass persistentClass = ( ( OneToMany ) map.getElement() ).getAssociatedClass(); // check if the index column has been mapped by the associated entity to a property; // @MapKeyColumn only maps a column to the primary table for the one-to-many, so we only // need to check "un-joined" properties. if ( !propertyIteratorContainsColumn( persistentClass.getUnjoinedPropertyIterator(), column ) ) { // The index column is not mapped to an associated entity property so we can // safely make the index column nullable. column.setNullable( true ); } } } }
@Test public void testBasicDDL() { PersistentClass classMapping = metadata().getEntityBinding( Address.class.getName() ); Column stateColumn = (Column) classMapping.getProperty( "state" ).getColumnIterator().next(); assertEquals( stateColumn.getLength(), 3 ); Column zipColumn = (Column) classMapping.getProperty( "zip" ).getColumnIterator().next(); assertEquals( zipColumn.getLength(), 5 ); assertFalse( zipColumn.isNullable() ); }
/** * used for mappedBy cases */ public void linkValueUsingAColumnCopy(Column column, SimpleValue value) { initMappingColumn( //column.getName(), column.getQuotedName(), null, column.getLength(), column.getPrecision(), column.getScale(), getMappingColumn().isNullable(), column.getSqlType(), getMappingColumn().isUnique(), false //We do copy no strategy here ); linkWithValue( value ); }
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() ); } }
fieldMetadata.setScale(column.getScale()); fieldMetadata.setPrecision(column.getPrecision()); fieldMetadata.setRequired(!column.isNullable()); fieldMetadata.setUnique(column.isUnique());
public void linkValueUsingDefaultColumnNaming( Column referencedColumn, PersistentClass referencedEntity, SimpleValue value) { String logicalReferencedColumn = getBuildingContext().getMetadataCollector().getLogicalColumnName( referencedEntity.getTable(), referencedColumn.getQuotedName() ); String columnName = buildDefaultColumnName( referencedEntity, logicalReferencedColumn ); //yuk side effect on an implicit column setLogicalColumnName( columnName ); setReferencedColumn( logicalReferencedColumn ); initMappingColumn( columnName, null, referencedColumn.getLength(), referencedColumn.getPrecision(), referencedColumn.getScale(), getMappingColumn() != null ? getMappingColumn().isNullable() : false, referencedColumn.getSqlType(), getMappingColumn() != null ? getMappingColumn().isUnique() : false, false ); linkWithValue( value ); }
copy.setValue( key ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() );