Java Code Examples for org.hibernate.dialect.Dialect#supportsNotNullUnique()

The following examples show how to use org.hibernate.dialect.Dialect#supportsNotNullUnique() . 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: UniqueKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
public String sqlConstraintString(Dialect dialect, String constraintName, String defaultCatalog,
								  String defaultSchema) {
	StringBuffer buf = new StringBuffer(
			dialect.getAddPrimaryKeyConstraintString( constraintName )
	).append( '(' );
	Iterator iter = getColumnIterator();
	boolean nullable = false;
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();
		if ( !nullable && column.isNullable() ) nullable = true;
		buf.append( column.getQuotedName( dialect ) );
		if ( iter.hasNext() ) buf.append( ", " );
	}
	return !nullable || dialect.supportsNotNullUnique() ?
			StringHelper.replace( buf.append( ')' ).toString(), "primary key", "unique" ) :
			//TODO: improve this hack!
			null;
}
 
Example 2
Source File: UniqueKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String sqlConstraintString(Dialect dialect) {
	StringBuffer buf = new StringBuffer( "unique (" );
	Iterator iter = getColumnIterator();
	boolean nullable = false;
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();
		if ( !nullable && column.isNullable() ) nullable = true;
		buf.append( column.getQuotedName( dialect ) );
		if ( iter.hasNext() ) buf.append( ", " );
	}
	//do not add unique constraint on DB not supporting unique and nullable columns
	return !nullable || dialect.supportsNotNullUnique() ?
			buf.append( ')' ).toString() :
			null;
}
 
Example 3
Source File: UniqueKey.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public boolean isGenerated(Dialect dialect) {
	if ( dialect.supportsNotNullUnique() ) return true;
	Iterator iter = getColumnIterator();
	while ( iter.hasNext() ) {
		if ( ( (Column) iter.next() ).isNullable() ) {
			return false;
		}
	}
	return true;
}
 
Example 4
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );
			}

			if ( column.isNullable() ) {
				alter.append( dialect.getNullColumnString() );
			}
			else {
				alter.append( " not null" );
			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}
 
Example 5
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );
			}

			if ( column.isNullable() ) {
				alter.append( dialect.getNullColumnString() );
			}
			else {
				alter.append( " not null" );
			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}
 
Example 6
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );
			}

			if ( column.isNullable() ) {
				alter.append( dialect.getNullColumnString() );
			}
			else {
				alter.append( " not null" );
			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}
 
Example 7
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );
			}

			if ( column.isNullable() ) {
				alter.append( dialect.getNullColumnString() );
			}
			else {
				alter.append( " not null" );
			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}
 
Example 8
Source File: Table.java    From Knowage-Server with GNU Affero General Public License v3.0 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );
			}

			if ( column.isNullable() ) {
				alter.append( dialect.getNullColumnString() );
			}
			else {
				alter.append( " not null" );
			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}
 
Example 9
Source File: Table.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
public Iterator sqlAlterStrings(Dialect dialect, Mapping p, TableMetadata tableInfo, String defaultCatalog,
								String defaultSchema)
		throws HibernateException {

	StringBuffer root = new StringBuffer( "alter table " )
			.append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) )
			.append( ' ' )
			.append( dialect.getAddColumnString() );

	Iterator iter = getColumnIterator();
	List results = new ArrayList();
	while ( iter.hasNext() ) {
		Column column = (Column) iter.next();

		ColumnMetadata columnInfo = tableInfo.getColumnMetadata( column.getName() );

		if ( columnInfo == null ) {
			// the column doesnt exist at all.
			StringBuffer alter = new StringBuffer( root.toString() )
					.append( ' ' )
					.append( column.getQuotedName( dialect ) )
					.append( ' ' )
					.append( column.getSqlType( dialect, p ) );

			String defaultValue = column.getDefaultValue();
			if ( defaultValue != null ) {
				alter.append( " default " ).append( defaultValue );

				if ( column.isNullable() ) {
					alter.append( dialect.getNullColumnString() );
				}
				else {
					alter.append( " not null" );
				}

			}

			boolean useUniqueConstraint = column.isUnique() &&
					dialect.supportsUnique() &&
					( !column.isNullable() || dialect.supportsNotNullUnique() );
			if ( useUniqueConstraint ) {
				alter.append( " unique" );
			}

			if ( column.hasCheckConstraint() && dialect.supportsColumnCheck() ) {
				alter.append( " check(" )
						.append( column.getCheckConstraint() )
						.append( ")" );
			}

			String columnComment = column.getComment();
			if ( columnComment != null ) {
				alter.append( dialect.getColumnComment( columnComment ) );
			}

			results.add( alter.toString() );
		}

	}

	return results.iterator();
}