public < T > String tableCreateStatement ( Type < T > type , TableCreationMode mode ) { String tableName = type . getName ( ) ; QueryBuilder qb = createQueryBuilder ( ) ; qb . keyword ( CREATE ) ; if ( type . getTableCreateAttributes ( ) != null ) { for ( String attribute : type . getTableCreateAttributes ( ) ) { qb . append ( attribute , true ) ; } } qb . keyword ( TABLE ) ; if ( mode == TableCreationMode . CREATE_NOT_EXISTS ) { qb . keyword ( IF , NOT , EXISTS ) ; } qb . tableName ( tableName ) ; qb . openParenthesis ( ) ; int index = 0 ; // columns to define first Predicate < Attribute > filter = new Predicate < Attribute > ( ) { @ Override public boolean test ( Attribute value ) { if ( value . isVersion ( ) && ! platform . versionColumnDefinition ( ) . createColumn ( ) ) { return false ; } if ( platform . supportsInlineForeignKeyReference ( ) ) { return ! value . isForeignKey ( ) && ! value . isAssociation ( ) ; } else { return value . isForeignKey ( ) || ! value . isAssociation ( ) ; } } } ; Set < Attribute < T , ? > > attributes = type . getAttributes ( ) ; for ( Attribute attribute : attributes ) { if ( filter . test ( attribute ) ) { if ( index > 0 ) { qb . comma ( ) ; } createColumn ( qb , attribute ) ; index ++ ; } } // foreign keys for ( Attribute attribute : attributes ) { if ( attribute . isForeignKey ( ) ) { if ( index > 0 ) { qb . comma ( ) ; } createForeignKeyColumn ( qb , attribute , true , false ) ; index ++ ; } } // composite primary key if ( type . getKeyAttributes ( ) . size ( ) > 1 ) { if ( index > 0 ) { qb . comma ( ) ; } qb . keyword ( PRIMARY , KEY ) ; qb . openParenthesis ( ) ; qb . commaSeparated ( type . getKeyAttributes ( ) , new QueryBuilder . Appender < Attribute < T , ? > > ( ) { @ Override public void append ( QueryBuilder qb , Attribute < T , ? > value ) { qb . attribute ( value ) ; } } ) ; qb . closeParenthesis ( ) ; } qb . closeParenthesis ( ) ; return qb . toString ( ) ; }
Generates the create table for a specific type .