📄 table.java
字号:
} if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) { Iterator ukiter = getUniqueKeyIterator(); while ( ukiter.hasNext() ) { UniqueKey uk = ( UniqueKey ) ukiter.next(); buf.append( ", " ) .append( uk.sqlConstraintString( dialect ) ); } } /*Iterator idxiter = getIndexIterator(); while ( idxiter.hasNext() ) { Index idx = (Index) idxiter.next(); buf.append(',').append( idx.sqlConstraintString(dialect) ); }*/ if ( dialect.supportsTableCheck() ) { Iterator chiter = checkConstraints.iterator(); while ( chiter.hasNext() ) { buf.append( ", check (" ) .append( chiter.next() ) .append( ')' ); } } buf.append( ')' ); if (comment!=null) buf.append( dialect.getTableComment(comment) ); return buf.append( dialect.getTableTypeString() ).toString(); } public String sqlDropString(Dialect dialect, String defaultCatalog, String defaultSchema) { StringBuffer buf = new StringBuffer( "drop table " ); if ( dialect.supportsIfExistsBeforeTableName() ) buf.append( "if exists " ); buf.append( getQualifiedName( dialect , defaultCatalog, defaultSchema ) ) .append( dialect.getCascadeConstraintsString() ); if ( dialect.supportsIfExistsAfterTableName() ) buf.append( " if exists" ); return buf.toString(); } public PrimaryKey getPrimaryKey() { return primaryKey; } public void setPrimaryKey(PrimaryKey primaryKey) { this.primaryKey = primaryKey; } /*public Index createIndex(String indexName, List indexColumns) { if ( indexName == null ) indexName = "IX" + uniqueColumnString( indexColumns.iterator() ); Index idx = getOrCreateIndex( indexName ); idx.addColumns( indexColumns.iterator() ); return idx; }*/ public Index getOrCreateIndex(String indexName) { Index index = ( Index ) indexes.get( indexName ); if ( index == null ) { index = new Index(); index.setName( indexName ); index.setTable( this ); indexes.put( indexName, index ); } return index; } public Index getIndex(String indexName) { return ( Index ) indexes.get( indexName ); } public Index addIndex(Index index) { Index current = ( Index ) indexes.get( index.getName() ); if ( current != null ) { throw new MappingException( "Index " + index.getName() + " already exists!" ); } indexes.put( index.getName(), index ); return index; } public UniqueKey addUniqueKey(UniqueKey uniqueKey) { UniqueKey current = ( UniqueKey ) uniqueKeys.get( uniqueKey.getName() ); if ( current != null ) { throw new MappingException( "UniqueKey " + uniqueKey.getName() + " already exists!" ); } uniqueKeys.put( uniqueKey.getName(), uniqueKey ); return uniqueKey; } public UniqueKey createUniqueKey(List keyColumns) { String keyName = "UK" + uniqueColumnString( keyColumns.iterator() ); UniqueKey uk = getOrCreateUniqueKey( keyName ); uk.addColumns( keyColumns.iterator() ); return uk; } public UniqueKey getUniqueKey(String keyName) { return (UniqueKey) uniqueKeys.get( keyName ); } public UniqueKey getOrCreateUniqueKey(String keyName) { UniqueKey uk = ( UniqueKey ) uniqueKeys.get( keyName ); if ( uk == null ) { uk = new UniqueKey(); uk.setName( keyName ); uk.setTable( this ); uniqueKeys.put( keyName, uk ); } return uk; } public void createForeignKeys() { } public ForeignKey createForeignKey(String keyName, List keyColumns, String referencedEntityName) { Object key = new ForeignKeyKey( keyColumns, referencedEntityName ); ForeignKey fk = ( ForeignKey ) foreignKeys.get( key ); if ( fk == null ) { fk = new ForeignKey(); if ( keyName != null ) { fk.setName( keyName ); } else { fk.setName( "FK" + uniqueColumnString( keyColumns.iterator(), referencedEntityName ) ); //TODO: add referencedClass to disambiguate to FKs on the same // columns, pointing to different tables } fk.setTable( this ); foreignKeys.put( key, fk ); fk.setReferencedEntityName( referencedEntityName ); fk.addColumns( keyColumns.iterator() ); } if ( keyName != null ) fk.setName( keyName ); return fk; } public String uniqueColumnString(Iterator iterator) { return uniqueColumnString(iterator, null); } public String uniqueColumnString(Iterator iterator, String referencedEntityName) { int result = 0; if (referencedEntityName!=null) result += referencedEntityName.hashCode(); while ( iterator.hasNext() ) result += iterator.next().hashCode(); return ( Integer.toHexString( name.hashCode() ) + Integer.toHexString( result ) ).toUpperCase(); } public String getSchema() { return schema; } public void setSchema(String schema) { if ( schema!=null && schema.charAt( 0 ) == '`' ) { schemaQuoted = true; this.schema = schema.substring( 1, schema.length() - 1 ); } else { this.schema = schema; } } public String getCatalog() { return catalog; } public void setCatalog(String catalog) { this.catalog = catalog; } public int getUniqueInteger() { return uniqueInteger; } public void setIdentifierValue(KeyValue idValue) { this.idValue = idValue; } public boolean isQuoted() { return quoted; } public void setQuoted(boolean quoted) { this.quoted = quoted; } public void addCheckConstraint(String constraint) { checkConstraints.add( constraint ); } public boolean containsColumn(Column column) { return columns.containsValue( column ); } public String getRowId() { return rowId; } public void setRowId(String rowId) { this.rowId = rowId; } public String toString() { StringBuffer buf = new StringBuffer().append( getClass().getName() ) .append('('); if ( getCatalog()!=null ) buf.append( getCatalog() + "." ); if ( getSchema()!=null ) buf.append( getSchema()+ "."); buf.append( getName() ).append(')'); return buf.toString(); } public String getSubselect() { return subselect; } public void setSubselect(String subselect) { this.subselect = subselect; } public boolean isSubselect() { return subselect != null; } public boolean isAbstractUnionTable() { return hasDenormalizedTables && isAbstract; } void setHasDenormalizedTables() { hasDenormalizedTables = true; } public boolean hasDenormalizedTables() { return hasDenormalizedTables; } public void setAbstract(boolean isAbstract) { this.isAbstract = isAbstract; } public boolean isAbstract() { return isAbstract; } public boolean isPhysicalTable() { return !isSubselect() && !isAbstractUnionTable(); } public String getComment() { return comment; } public void setComment(String comment) { this.comment = comment; } public Iterator sqlCommentStrings(Dialect dialect, String defaultCatalog, String defaultSchema) { List comments = new ArrayList(); if ( dialect.supportsCommentOn() ) { String tableName = getQualifiedName( dialect , defaultCatalog, defaultSchema ); if ( comment!=null ) { StringBuffer buf = new StringBuffer() .append("comment on table ") .append( tableName ) .append(" is '") .append(comment) .append("'"); comments.add( buf.toString() ); } Iterator iter = getColumnIterator(); while ( iter.hasNext() ) { Column column = (Column) iter.next(); String columnComment = column.getComment(); if ( columnComment!=null ) { StringBuffer buf = new StringBuffer() .append("comment on column ") .append( tableName ) .append('.') .append( column.getQuotedName(dialect) ) .append(" is '") .append(columnComment) .append("'"); comments.add( buf.toString() ); } } } return comments.iterator(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -