1 | public String toString() | | 1 | public String sqlCreateString(Dialect dialect, Mapping p, String defaultCatalog, String defaultSchema) { |
2 | { | | 2 | StringBuffer buf = new StringBuffer( hasPrimaryKey() ? dialect.getCreateTableString() : dialect.getCreateMultisetTableString() ) |
3 | StringBuffer buffer = new StringBuffer(); | | 3 | .append( ' ' ) |
4 | | | 4 | .append( getQualifiedName( dialect, defaultCatalog, defaultSchema ) ) |
5 | buffer.append( name + " id: " + nodeID ); | | 5 | .append( " (" ); |
6 | if ( route != null ) { | | 6 | |
7 | buffer.append( " route name: " ).append( route.getName() ).append( " tour name: " ).append( tour.getName() ); | | 7 | boolean identityColumn = idValue != null && idValue.isIdentityColumn( dialect ); |
8 | } | | 8 | |
9 | if ( pickupTransports != null ) { | | 9 | // Try to find out the name of the primary key to create it as identity if the IdentityGenerator is used |
10 | for (Iterator it = pickupTransports.iterator(); it.hasNext();) { | | 10 | String pkname = null; |
11 | buffer.append("Pickup transports: " + it.next()); | | 11 | if ( hasPrimaryKey() && identityColumn ) { |
12 | } | | 12 | pkname = ( (Column) getPrimaryKey().getColumnIterator().next() ).getQuotedName( dialect ); |
13 | } | | 13 | } |
14 | | | 14 | |
15 | if ( deliveryTransports != null ) { | | 15 | Iterator iter = getColumnIterator(); |
16 | for (Iterator it = deliveryTransports.iterator(); it.hasNext();) { | | 16 | while ( iter.hasNext() ) { |
17 | buffer.append("Delviery transports: " + it.next()); | | 17 | Column col = (Column) iter.next(); |
18 | } | | 18 | |
19 | } | | 19 | buf.append( col.getQuotedName( dialect ) ) |
20 | | | 20 | .append( ' ' ); |
21 | return buffer.toString(); | | 21 | |
22 | } | | 22 | if ( identityColumn && col.getQuotedName( dialect ).equals( pkname ) ) { |
| | | 23 | // to support dialects that have their own identity data type |
| | | 24 | if ( dialect.hasDataTypeInIdentityColumn() ) { |
| | | 25 | buf.append( col.getSqlType( dialect, p ) ); |
| | | 26 | } |
| | | 27 | buf.append( ' ' ) |
| | | 28 | .append( dialect.getIdentityColumnString( col.getSqlTypeCode( p ) ) ); |
| | | 29 | } |
| | | 30 | else { |
| | | 31 | |
| | | 32 | buf.append( col.getSqlType( dialect, p ) ); |
| | | 33 | |
| | | 34 | String defaultValue = col.getDefaultValue(); |
| | | 35 | if ( defaultValue != null ) { |
| | | 36 | buf.append( " default " ).append( defaultValue ); |
| | | 37 | } |
| | | 38 | |
| | | 39 | if ( col.isNullable() ) { |
| | | 40 | buf.append( dialect.getNullColumnString() ); |
| | | 41 | } |
| | | 42 | else { |
| | | 43 | buf.append( " not null" ); |
| | | 44 | } |
| | | 45 | |
| | | 46 | } |
| | | 47 | |
| | | 48 | boolean useUniqueConstraint = col.isUnique() && |
| | | 49 | ( !col.isNullable() || dialect.supportsNotNullUnique() ); |
| | | 50 | if ( useUniqueConstraint ) { |
| | | 51 | if ( dialect.supportsUnique() ) { |
| | | 52 | buf.append( " unique" ); |
| | | 53 | } |
| | | 54 | else { |
| | | 55 | UniqueKey uk = getOrCreateUniqueKey( col.getQuotedName( dialect ) + '_' ); |
| | | 56 | uk.addColumn( col ); |
| | | 57 | } |
| | | 58 | } |
| | | 59 | |
| | | 60 | if ( col.hasCheckConstraint() && dialect.supportsColumnCheck() ) { |
| | | 61 | buf.append( " check (" ) |
| | | 62 | .append( col.getCheckConstraint() ) |
| | | 63 | .append( ")" ); |
| | | 64 | } |
| | | 65 | |
| | | 66 | String columnComment = col.getComment(); |
| | | 67 | if ( columnComment != null ) { |
| | | 68 | buf.append( dialect.getColumnComment( columnComment ) ); |
| | | 69 | } |
| | | 70 | |
| | | 71 | if ( iter.hasNext() ) { |
| | | 72 | buf.append( ", " ); |
| | | 73 | } |
| | | 74 | |
| | | 75 | } |
| | | 76 | if ( hasPrimaryKey() ) { |
| | | 77 | buf.append( ", " ) |
| | | 78 | .append( getPrimaryKey().sqlConstraintString( dialect ) ); |
| | | 79 | } |
| | | 80 | |
| | | 81 | if ( dialect.supportsUniqueConstraintInCreateAlterTable() ) { |
| | | 82 | Iterator ukiter = getUniqueKeyIterator(); |
| | | 83 | while ( ukiter.hasNext() ) { |
| | | 84 | UniqueKey uk = (UniqueKey) ukiter.next(); |
| | | 85 | String constraint = uk.sqlConstraintString( dialect ); |
| | | 86 | if ( constraint != null ) { |
| | | 87 | buf.append( ", " ).append( constraint ); |
| | | 88 | } |
| | | 89 | } |
| | | 90 | } |
| | | 91 | /*Iterator idxiter = getIndexIterator(); |
| | | 92 | while ( idxiter.hasNext() ) { |
| | | 93 | Index idx = (Index) idxiter.next(); |
| | | 94 | buf.append(',').append( idx.sqlConstraintString(dialect) ); |
| | | 95 | }*/ |
| | | 96 | |
| | | 97 | if ( dialect.supportsTableCheck() ) { |
| | | 98 | Iterator chiter = checkConstraints.iterator(); |
| | | 99 | while ( chiter.hasNext() ) { |
| | | 100 | buf.append( ", check (" ) |
| | | 101 | .append( chiter.next() ) |
| | | 102 | .append( ')' ); |
| | | 103 | } |
| | | 104 | } |
| | | 105 | |
| | | 106 | buf.append( ')' ); |
| | | 107 | |
| | | 108 | if ( comment != null ) { |
| | | 109 | buf.append( dialect.getTableComment( comment ) ); |
| | | 110 | } |
| | | 111 | |
| | | 112 | return buf.append( dialect.getTableTypeString() ).toString(); |
| | | 113 | } |