下面列出了怎么用org.hibernate.tool.schema.spi.Exporter的API类实例代码及写法,或者点击链接到github查看源代码。
protected void applyIndexes(
Table table,
TableInformation tableInformation,
Dialect dialect,
Metadata metadata,
Formatter formatter,
ExecutionOptions options,
GenerationTarget... targets) {
final Exporter<Index> exporter = dialect.getIndexExporter();
final Iterator<Index> indexItr = table.getIndexIterator();
while ( indexItr.hasNext() ) {
final Index index = indexItr.next();
if ( !StringHelper.isEmpty( index.getName() ) ) {
IndexInformation existingIndex = null;
if ( tableInformation != null ) {
existingIndex = findMatchingIndex( index, tableInformation );
}
if ( existingIndex == null ) {
applySqlStrings(
false,
exporter.getSqlCreateStrings( index, metadata ),
formatter,
options,
targets
);
}
}
}
}
protected void applyForeignKeys(
Table table,
TableInformation tableInformation,
Dialect dialect,
Metadata metadata,
Formatter formatter,
ExecutionOptions options,
GenerationTarget... targets) {
if ( dialect.hasAlterTable() ) {
final Exporter<ForeignKey> exporter = dialect.getForeignKeyExporter();
@SuppressWarnings("unchecked")
final Iterator<ForeignKey> fkItr = table.getForeignKeyIterator();
while ( fkItr.hasNext() ) {
final ForeignKey foreignKey = fkItr.next();
if ( foreignKey.isPhysicalConstraint() && foreignKey.isCreationEnabled() ) {
boolean existingForeignKeyFound = false;
if ( tableInformation != null ) {
existingForeignKeyFound = checkForExistingForeignKey(
foreignKey,
tableInformation
);
}
if ( !existingForeignKeyFound ) {
// todo : shouldn't we just drop+recreate if FK exists?
// this follows the existing code from legacy SchemaUpdate which just skipped
// in old SchemaUpdate code, this was the trigger to "create"
applySqlStrings(
false,
exporter.getSqlCreateStrings( foreignKey, metadata ),
formatter,
options,
targets
);
}
}
}
}
}
@Override
public Exporter<Table> getTableExporter() {
return this.spannerTableExporter;
}
@Override
public Exporter<ForeignKey> getForeignKeyExporter() {
return this.spannerForeignKeyExporter;
}
@Override
public Exporter<Sequence> getSequenceExporter() {
return NOOP_EXPORTER;
}
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
);
}
}
}
}
@Override
public Exporter<Index> getIndexExporter() {
return TeraIndexExporter;
}
@Override
public Exporter<Table> getTableExporter() {
return this.hanaTableExporter;
}
public Exporter<Table> getTableExporter() {
return tableExporter;
}
public Exporter<Sequence> getSequenceExporter() {
return sequenceExporter;
}
public Exporter<Index> getIndexExporter() {
return indexExporter;
}
public Exporter<ForeignKey> getForeignKeyExporter() {
return foreignKeyExporter;
}
public Exporter<Constraint> getUniqueKeyExporter() {
return uniqueKeyExporter;
}
public Exporter<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectExporter() {
return auxiliaryObjectExporter;
}
@Override
public Exporter<Table> getTableExporter() {
return getInstance().getTableExporter();
}
@Override
public Exporter<Sequence> getSequenceExporter() {
return getInstance().getSequenceExporter();
}
@Override
public Exporter<Index> getIndexExporter() {
return getInstance().getIndexExporter();
}
@Override
public Exporter<ForeignKey> getForeignKeyExporter() {
return getInstance().getForeignKeyExporter();
}
@Override
public Exporter<Constraint> getUniqueKeyExporter() {
return getInstance().getUniqueKeyExporter();
}
@Override
public Exporter<AuxiliaryDatabaseObject> getAuxiliaryDatabaseObjectExporter() {
return getInstance().getAuxiliaryDatabaseObjectExporter();
}