org.hibernate.mapping.Constraint Java Examples

The following examples show how to use org.hibernate.mapping.Constraint. 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: SpannerTableExporter.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Processes the columns of the table and creates Unique Constraints for columns
 * annotated with @Column(unique = true).
 */
private static void initializeUniqueConstraints(Table table) {
  Iterator<Column> colIterator = table.getColumnIterator();
  while (colIterator.hasNext()) {
    Column col = colIterator.next();
    if (col.isUnique()) {
      String name = Constraint.generateName("UK_", table, col);
      UniqueKey uk = table.getOrCreateUniqueKey(name);
      uk.addColumn(col);
    }
  }
}
 
Example #2
Source File: StandardUniqueKeyExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getSqlCreateStrings(Constraint constraint, Metadata metadata) {
	return new String[] {
			dialect.getUniqueDelegate().getAlterTableToAddUniqueKeyCommand(
					(UniqueKey) constraint,
					metadata
			)
	};
}
 
Example #3
Source File: StandardUniqueKeyExporter.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String[] getSqlDropStrings(Constraint constraint, Metadata metadata) {
	return new String[] {
			dialect.getUniqueDelegate().getAlterTableToDropUniqueKeyCommand(
					(UniqueKey) constraint,
					metadata
			)
	};
}
 
Example #4
Source File: AbstractSchemaMigrator.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
protected void applyUniqueKeys(
		Table table,
		TableInformation tableInfo,
		Dialect dialect,
		Metadata metadata,
		Formatter formatter,
		ExecutionOptions options,
		GenerationTarget... targets) {
	if ( uniqueConstraintStrategy == null ) {
		uniqueConstraintStrategy = determineUniqueConstraintSchemaUpdateStrategy( metadata );
	}

	if ( uniqueConstraintStrategy != UniqueConstraintSchemaUpdateStrategy.SKIP ) {
		final Exporter<Constraint> exporter = dialect.getUniqueKeyExporter();

		final Iterator ukItr = table.getUniqueKeyIterator();
		while ( ukItr.hasNext() ) {
			final UniqueKey uniqueKey = (UniqueKey) ukItr.next();
			// Skip if index already exists. Most of the time, this
			// won't work since most Dialects use Constraints. However,
			// keep it for the few that do use Indexes.
			IndexInformation indexInfo = null;
			if ( tableInfo != null && StringHelper.isNotEmpty( uniqueKey.getName() ) ) {
				indexInfo = tableInfo.getIndex( Identifier.toIdentifier( uniqueKey.getName() ) );
			}
			if ( indexInfo == null ) {
				if ( uniqueConstraintStrategy == UniqueConstraintSchemaUpdateStrategy.DROP_RECREATE_QUIETLY ) {
					applySqlStrings(
							true,
							exporter.getSqlDropStrings( uniqueKey, metadata ),
							formatter,
							options,
							targets
					);
				}

				applySqlStrings(
						true,
						exporter.getSqlCreateStrings( uniqueKey, metadata ),
						formatter,
						options,
						targets
				);
			}
		}
	}
}
 
Example #5
Source File: Dialect.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public Exporter<Constraint> getUniqueKeyExporter() {
	return uniqueKeyExporter;
}
 
Example #6
Source File: DelegatingDialect.java    From keycloak with Apache License 2.0 4 votes vote down vote up
@Override
public Exporter<Constraint> getUniqueKeyExporter() {
    return getInstance().getUniqueKeyExporter();
}