public void setNullable(boolean nullable) { if ( mappingColumn != null ) { mappingColumn.setNullable( nullable ); } else { this.nullable = nullable; } }
public void forceNotNull() { if ( mappingColumn == null ) { throw new CannotForceNonNullableException( "Cannot perform #forceNotNull because internal org.hibernate.mapping.Column reference is null: " + "likely a formula" ); } mappingColumn.setNullable( false ); }
@SuppressWarnings("unchecked") private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) { boolean hasNotNull = false; if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) { // single table inheritance should not be forced to null due to shared state if ( !( property.getPersistentClass() instanceof SingleTableSubclass ) ) { //composite should not add not-null on all columns if ( !property.isComposite() ) { final Iterator<Selectable> itr = property.getColumnIterator(); while ( itr.hasNext() ) { final Selectable selectable = itr.next(); if ( Column.class.isInstance( selectable ) ) { Column.class.cast( selectable ).setNullable( false ); } else { LOG.debugf( "@NotNull was applied to attribute [%s] which is defined (at least partially) " + "by formula(s); formula portions will be skipped", property.getName() ); } } } } hasNotNull = true; } return hasNotNull; }
@Override public void addColumn(Column column) { final Iterator<Column> columnIterator = getTable().getColumnIterator(); while ( columnIterator.hasNext() ) { final Column next = columnIterator.next(); if ( next.getCanonicalName().equals( column.getCanonicalName() ) ) { next.setNullable( false ); log.debugf( "Forcing column [%s] to be non-null as it is part of the primary key for table [%s]", column.getCanonicalName(), getTableNameForLogging( column ) ); } } super.addColumn( column ); }
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; } }
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 ); } } } }
public void setNullable(boolean nullable) { if ( mappingColumn != null ) { mappingColumn.setNullable( nullable ); } else { this.nullable = nullable; } }
public void forceNotNull() { mappingColumn.setNullable( false ); }
this.mappingColumn.setScale( scale ); this.mappingColumn.setNullable( nullable ); this.mappingColumn.setSqlType( sqlType ); this.mappingColumn.setUnique( unique );
/** * 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; }
copy.setValue( key ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() );
private static boolean applyNotNull(Property property, ConstraintDescriptor<?> descriptor) { boolean hasNotNull = false; if ( NotNull.class.equals( descriptor.getAnnotation().annotationType() ) ) { if ( ! ( property.getPersistentClass() instanceof SingleTableSubclass ) ) { //single table should not be forced to null if ( !property.isComposite() ) { //composite should not add not-null on all columns @SuppressWarnings( "unchecked" ) Iterator<Column> iter = (Iterator<Column>) property.getColumnIterator(); while ( iter.hasNext() ) { iter.next().setNullable( false ); hasNotNull = true; } } } hasNotNull = true; } return hasNotNull; }
dialect.getTypeName( Types.VARCHAR, segmentValueLength, 0, 0 ) ); segmentColumn.setNullable( false ); table.addColumn( segmentColumn );
database.getDialect().getTypeName( Types.VARCHAR, keySize, 0, 0 ) ); pkColumn.setNullable( false ); table.addColumn( pkColumn ); table.getPrimaryKey().addColumn( pkColumn );
copy.setValue( manyToOne ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() );
column.setNullable( interpretNullability( columnSource.isNullable(), areColumnsNullableByDefault ) );
public void setNullable(boolean nullable) { if ( mappingColumn != null ) { mappingColumn.setNullable( nullable ); } else { this.nullable = nullable; } }
protected void initMappingColumn( String columnName, String propertyName, int length, int precision, int scale, boolean nullable, String sqlType, boolean unique, boolean applyNamingStrategy) { if ( StringHelper.isNotEmpty( formulaString ) ) { this.formula = new Formula(); this.formula.setFormula( formulaString ); } else { this.mappingColumn = new Column(); redefineColumnName( columnName, propertyName, applyNamingStrategy ); this.mappingColumn.setLength( length ); if ( precision > 0 ) { //revelent precision this.mappingColumn.setPrecision( precision ); this.mappingColumn.setScale( scale ); } this.mappingColumn.setNullable( nullable ); this.mappingColumn.setSqlType( sqlType ); this.mappingColumn.setUnique( unique ); } }
copy.setValue( key ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() );
copy.setValue( manyToOne ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() );