本文整理汇总了Java中org.hibernate.mapping.Table.getForeignKeyIterator方法的典型用法代码示例。如果您正苦于以下问题:Java Table.getForeignKeyIterator方法的具体用法?Java Table.getForeignKeyIterator怎么用?Java Table.getForeignKeyIterator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.mapping.Table
的用法示例。
在下文中一共展示了Table.getForeignKeyIterator方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTableName
import org.hibernate.mapping.Table; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private void addTableName(MetadataImplementor metadata, ArrayList<String> tables, Table table, String aSchemaName) {
String name = (null == aSchemaName) ? "" : aSchemaName + ".";
name += table.getName();
if (tables.contains(name)) {
return;
}
final Collection<Table> ts = metadata.collectTableMappings();
for (Table t : ts) {
if (t.equals(table)) {
continue;
}
Iterator<ForeignKey> relationships = t.getForeignKeyIterator();
while (relationships.hasNext()) {
ForeignKey fk = relationships.next();
if (fk.getReferencedTable().equals(table)) {
addTableName(metadata, tables, fk.getTable(), aSchemaName);
}
}
}
tables.add(name);
}
示例2: secondPassCompileForeignKeys
import org.hibernate.mapping.Table; //导入方法依赖的package包/类
protected void secondPassCompileForeignKeys(Table table, Set<ForeignKey> done) throws MappingException {
table.createForeignKeys();
Iterator iter = table.getForeignKeyIterator();
while ( iter.hasNext() ) {
ForeignKey fk = (ForeignKey) iter.next();
if ( !done.contains( fk ) ) {
done.add( fk );
final String referencedEntityName = fk.getReferencedEntityName();
if ( referencedEntityName == null ) {
throw new MappingException(
"An association from the table " +
fk.getTable().getName() +
" does not specify the referenced entity"
);
}
LOG.debugf( "Resolving reference to class: %s", referencedEntityName );
PersistentClass referencedClass = classes.get( referencedEntityName );
if ( referencedClass == null ) {
throw new MappingException(
"An association from the table " +
fk.getTable().getName() +
" refers to an unmapped class: " +
referencedEntityName
);
}
if ( referencedClass.isJoinedSubclass() ) {
secondPassCompileForeignKeys( referencedClass.getSuperclass().getTable(), done );
}
fk.setReferencedTable( referencedClass.getTable() );
fk.alignColumns();
}
}
}
示例3: getAddIndexesAndConstraintsForColumns
import org.hibernate.mapping.Table; //导入方法依赖的package包/类
@SuppressWarnings({"unchecked"})
public List<String> getAddIndexesAndConstraintsForColumns(String tableName, boolean includeForeignKeyConstraints,
String... columnNames)
{
Set<Column> colSet = new HashSet<Column>();
for( String columnName : columnNames )
{
colSet.add(new Column(columnName));
}
List<String> sqlStrings = new ArrayList<String>();
Table table = findTable(tableName);
if( !extDialect.supportsModifyWithConstraints() )
{
for( Column col : colSet )
{
Column realCol = table.getColumn(col);
if( realCol.isUnique() )
{
table.createUniqueKey(Collections.singletonList(realCol));
}
}
}
Iterator<UniqueKey> keyIter = table.getUniqueKeyIterator();
if( dialect.supportsUniqueConstraintInCreateAlterTable() )
{
while( keyIter.hasNext() )
{
UniqueKey uk = keyIter.next();
if( !Collections.disjoint(uk.getColumns(), colSet) )
{
StringBuilder buf = new StringBuilder("alter table ");
buf.append(table.getQualifiedName(dialect, defaultCatalog, defaultSchema));
buf.append(" add constraint ");
buf.append(extDialect.getRandomIdentifier());
buf.append(' ');
String constraint = uk.sqlConstraintString(dialect);
if( constraint != null )
{
buf.append(constraint);
sqlStrings.add(buf.toString());
}
}
}
}
else
{
while( keyIter.hasNext() )
{
UniqueKey ukey = keyIter.next();
if( !Collections.disjoint(ukey.getColumns(), colSet) )
{
sqlStrings.add(ukey.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
}
}
}
addIndexSQL(sqlStrings, table, colSet);
// Caller may opt to skip foreign key constraints
if( includeForeignKeyConstraints )
{
Iterator<ForeignKey> fkeyIter = table.getForeignKeyIterator();
while( fkeyIter.hasNext() )
{
ForeignKey fkey = fkeyIter.next();
if( !Collections.disjoint(fkey.getColumns(), colSet) )
{
sqlStrings.add(fkey.sqlCreateString(dialect, mapping, defaultCatalog, defaultSchema));
}
}
}
return sqlStrings;
}