Java Code Examples for org.hibernate.mapping.Column#setNullable()
The following examples show how to use
org.hibernate.mapping.Column#setNullable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HbmBinder.java From cacheonix-core with GNU Lesser General Public License v2.1 | 6 votes |
public static void bindColumn(Element node, Column column, boolean isNullable) { Attribute lengthNode = node.attribute( "length" ); if ( lengthNode != null ) column.setLength( Integer.parseInt( lengthNode.getValue() ) ); Attribute scalNode = node.attribute( "scale" ); if ( scalNode != null ) column.setScale( Integer.parseInt( scalNode.getValue() ) ); Attribute precNode = node.attribute( "precision" ); if ( precNode != null ) column.setPrecision( Integer.parseInt( precNode.getValue() ) ); Attribute nullNode = node.attribute( "not-null" ); column.setNullable( nullNode == null ? isNullable : nullNode.getValue().equals( "false" ) ); Attribute unqNode = node.attribute( "unique" ); if ( unqNode != null ) column.setUnique( unqNode.getValue().equals( "true" ) ); column.setCheckConstraint( node.attributeValue( "check" ) ); column.setDefaultValue( node.attributeValue( "default" ) ); Attribute typeNode = node.attribute( "sql-type" ); if ( typeNode != null ) column.setSqlType( typeNode.getValue() ); Element comment = node.element("comment"); if (comment!=null) column.setComment( comment.getTextTrim() ); }
Example 2
Source File: OneToOneSecondPass.java From lams with GNU General Public License v2.0 | 5 votes |
/** * Builds the <code>Join</code> instance for the mapped by side of a <i>OneToOne</i> association using * a join tables. * <p> * Note:<br/> * <ul> * <li>From the mappedBy side we should not create the PK nor the FK, this is handled from the other side.</li> * <li>This method is a dirty dupe of EntityBinder.bindSecondaryTable</i>. * </p> */ private Join buildJoinFromMappedBySide(PersistentClass persistentClass, Property otherSideProperty, Join originalJoin) { Join join = new Join(); join.setPersistentClass( persistentClass ); //no check constraints available on joins join.setTable( originalJoin.getTable() ); join.setInverse( true ); SimpleValue key = new DependantValue( buildingContext, join.getTable(), persistentClass.getIdentifier() ); //TODO support @ForeignKey join.setKey( key ); join.setSequentialSelect( false ); //TODO support for inverse and optional join.setOptional( true ); //perhaps not quite per-spec, but a Good Thing anyway key.setCascadeDeleteEnabled( false ); Iterator mappedByColumns = otherSideProperty.getValue().getColumnIterator(); while ( mappedByColumns.hasNext() ) { Column column = (Column) mappedByColumns.next(); Column copy = new Column(); copy.setLength( column.getLength() ); copy.setScale( column.getScale() ); copy.setValue( key ); copy.setName( column.getQuotedName() ); copy.setNullable( column.isNullable() ); copy.setPrecision( column.getPrecision() ); copy.setUnique( column.isUnique() ); copy.setSqlType( column.getSqlType() ); copy.setCheckConstraint( column.getCheckConstraint() ); copy.setComment( column.getComment() ); copy.setDefaultValue( column.getDefaultValue() ); key.addColumn( copy ); } persistentClass.addJoin( join ); return join; }
Example 3
Source File: MapBinder.java From lams with GNU General Public License v2.0 | 5 votes |
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 ); } } } }
Example 4
Source File: TableGenerator.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void registerExportables(Database database) { final Dialect dialect = database.getJdbcEnvironment().getDialect(); final Namespace namespace = database.locateNamespace( qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName() ); Table table = namespace.locateTable( qualifiedTableName.getObjectName() ); if ( table == null ) { table = namespace.createTable( qualifiedTableName.getObjectName(), false ); // todo : note sure the best solution here. do we add the columns if missing? other? final Column segmentColumn = new ExportableColumn( database, table, segmentColumnName, StringType.INSTANCE, dialect.getTypeName( Types.VARCHAR, segmentValueLength, 0, 0 ) ); segmentColumn.setNullable( false ); table.addColumn( segmentColumn ); // lol table.setPrimaryKey( new PrimaryKey( table ) ); table.getPrimaryKey().addColumn( segmentColumn ); final Column valueColumn = new ExportableColumn( database, table, valueColumnName, LongType.INSTANCE ); table.addColumn( valueColumn ); } // allow physical naming strategies a chance to kick in this.renderedTableName = database.getJdbcEnvironment().getQualifiedObjectNameFormatter().format( table.getQualifiedTableName(), dialect ); table.addInitCommand( generateInsertInitCommand() ); this.selectQuery = buildSelectQuery( dialect ); this.updateQuery = buildUpdateQuery(); this.insertQuery = buildInsertQuery(); }
Example 5
Source File: MultipleHiLoPerTableGenerator.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public void registerExportables(Database database) { final Namespace namespace = database.locateNamespace( qualifiedTableName.getCatalogName(), qualifiedTableName.getSchemaName() ); Table table = namespace.locateTable( qualifiedTableName.getObjectName() ); if ( table == null ) { table = namespace.createTable( qualifiedTableName.getObjectName(), false ); // todo : note sure the best solution here. do we add the columns if missing? other? table.setPrimaryKey( new PrimaryKey( table ) ); final Column pkColumn = new ExportableColumn( database, table, segmentColumnName, StringType.INSTANCE, database.getDialect().getTypeName( Types.VARCHAR, keySize, 0, 0 ) ); pkColumn.setNullable( false ); table.addColumn( pkColumn ); table.getPrimaryKey().addColumn( pkColumn ); final Column valueColumn = new ExportableColumn( database, table, valueColumnName, LongType.INSTANCE ); table.addColumn( valueColumn ); } final JdbcEnvironment jdbcEnvironment = database.getJdbcEnvironment(); // allow physical naming strategies a chance to kick in tableName = jdbcEnvironment.getQualifiedObjectNameFormatter().format( table.getQualifiedTableName(), jdbcEnvironment.getDialect() ); query = "select " + valueColumnName + " from " + jdbcEnvironment.getDialect().appendLockHint( LockMode.PESSIMISTIC_WRITE, tableName ) + " where " + segmentColumnName + " = '" + segmentName + "'" + jdbcEnvironment.getDialect().getForUpdateString(); update = "update " + tableName + " set " + valueColumnName + " = ? where " + valueColumnName + " = ? and " + segmentColumnName + " = '" + segmentName + "'"; insert = "insert into " + tableName + "(" + segmentColumnName + ", " + valueColumnName + ") " + "values('" + segmentName + "', ?)"; }