本文整理汇总了Java中org.hibernate.mapping.ForeignKey类的典型用法代码示例。如果您正苦于以下问题:Java ForeignKey类的具体用法?Java ForeignKey怎么用?Java ForeignKey使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ForeignKey类属于org.hibernate.mapping包,在下文中一共展示了ForeignKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addTableName
import org.hibernate.mapping.ForeignKey; //导入依赖的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: matches
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
public boolean matches(ForeignKey fk) {
if ( refTable.equalsIgnoreCase( fk.getReferencedTable().getName() ) ) {
if ( fk.getColumnSpan() == references.size() ) {
List fkRefs;
if ( fk.isReferenceToPrimaryKey() ) {
fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
}
else {
fkRefs = fk.getReferencedColumns();
}
for ( int i = 0; i < fk.getColumnSpan(); i++ ) {
Column column = fk.getColumn( i );
Column ref = ( Column ) fkRefs.get( i );
if ( !hasReference( column, ref ) ) {
return false;
}
}
return true;
}
}
return false;
}
示例3: testForeignKeyCreation
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
public void testForeignKeyCreation() {
PersistentClass classMapping = getCfg().getClassMapping("org.hibernate.test.propertyref.basic.Account");
Iterator foreignKeyIterator = classMapping.getTable().getForeignKeyIterator();
boolean found = false;
while ( foreignKeyIterator.hasNext() ) {
ForeignKey element = (ForeignKey) foreignKeyIterator.next();
if(element.getReferencedEntityName().equals(Person.class.getName() ) ) {
if(!element.isReferenceToPrimaryKey() ) {
List referencedColumns = element.getReferencedColumns();
Column column = (Column) referencedColumns.get(0);
if(column.getName().equals("person_userid") ) {
found = true; // extend test to include the columns
}
}
}
}
assertTrue("Property ref foreign key not found",found);
}
示例4: matches
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
public boolean matches(ForeignKey fk) {
if (refTable.equalsIgnoreCase(fk.getReferencedTable().getName())) {
if (fk.getColumnSpan() == references.size()) {
List fkRefs;
if (fk.isReferenceToPrimaryKey()) {
fkRefs = fk.getReferencedTable().getPrimaryKey().getColumns();
} else {
fkRefs = fk.getReferencedColumns();
}
for (int i = 0; i < fk.getColumnSpan(); i++) {
Column column = fk.getColumn(i);
Column ref = (Column)fkRefs.get(i);
if (!hasReference(column, ref)) {
return false;
}
}
return false;
}
}
return false;
}
示例5: secondPassCompileForeignKeys
import org.hibernate.mapping.ForeignKey; //导入依赖的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();
}
}
}
示例6: getForeignKeyMetadata
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
Iterator it = foreignKeys.values().iterator();
while ( it.hasNext() ) {
ForeignKeyMetadata existingFk = ( ForeignKeyMetadata ) it.next();
if ( existingFk.matches( fk ) ) {
return existingFk;
}
}
return null;
}
示例7: secondPassCompileForeignKeys
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
protected void secondPassCompileForeignKeys(Table table, Set 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"
);
}
if ( log.isDebugEnabled() ) {
log.debug( "resolving reference to class: " + referencedEntityName );
}
PersistentClass referencedClass = (PersistentClass) 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();
}
}
}
示例8: normalizeForeignKeys
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void normalizeForeignKeys(Table table, String entityName) {
Iterator iterator = table.getForeignKeyIterator();
while (iterator.hasNext()) {
ForeignKey fk = (ForeignKey) iterator.next();
String name = strategy.foreignKeyName(entityName, table.getName(),
fk.getReferencedEntityName(), fk.getReferencedTable().getName());
fk.setName(name);
}
}
示例9: validateForeignKeys
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@SuppressWarnings("rawtypes")
private void validateForeignKeys(Table table) {
Iterator iterator = table.getForeignKeyIterator();
while (iterator.hasNext()) {
ForeignKey fk = (ForeignKey) iterator.next();
validateMaxLength(fk.getName());
}
}
示例10: getForeignKeyMetadata
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
public ForeignKeyMetadata getForeignKeyMetadata(ForeignKey fk) {
Iterator iterator = foreignKeys.values().iterator();
while (iterator.hasNext()) {
ForeignKeyMetadata existingFk = (ForeignKeyMetadata)iterator.next();
if (existingFk.matches(fk)) {
return existingFk;
}
}
return null;
}
示例11: getSqlCreateStrings
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@Override
public String[] getSqlCreateStrings(ForeignKey exportable, Metadata metadata)
{
return NO_COMMANDS;
}
示例12: getSqlDropStrings
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@Override
public String[] getSqlDropStrings(ForeignKey exportable, Metadata metadata)
{
return NO_COMMANDS;
}
示例13: getForeignKeyExporter
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@Override
public Exporter<ForeignKey> getForeignKeyExporter()
{
return foreignKeyExporter;
}
示例14: getAddIndexesAndConstraintsForColumns
import org.hibernate.mapping.ForeignKey; //导入依赖的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;
}
示例15: includeForeignKey
import org.hibernate.mapping.ForeignKey; //导入依赖的package包/类
@Override
public boolean includeForeignKey(Table table, ForeignKey fk)
{
return includeTable(table);
}