private static < T , ID > void addCreateTableStatements ( DatabaseType databaseType , TableInfo < T , ID > tableInfo , List < String > statements , List < String > queriesAfter , boolean ifNotExists , boolean logDetails ) throws SQLException { StringBuilder sb = new StringBuilder ( 256 ) ; if ( logDetails ) { logger . info ( "creating table '{}'" , tableInfo . getTableName ( ) ) ; } sb . append ( "CREATE TABLE " ) ; if ( ifNotExists && databaseType . isCreateIfNotExistsSupported ( ) ) { sb . append ( "IF NOT EXISTS " ) ; } databaseType . appendEscapedEntityName ( sb , tableInfo . getTableName ( ) ) ; sb . append ( " (" ) ; List < String > additionalArgs = new ArrayList < String > ( ) ; List < String > statementsBefore = new ArrayList < String > ( ) ; List < String > statementsAfter = new ArrayList < String > ( ) ; // our statement will be set here later boolean first = true ; for ( FieldType fieldType : tableInfo . getFieldTypes ( ) ) { // skip foreign collections if ( fieldType . isForeignCollection ( ) ) { continue ; } else if ( first ) { first = false ; } else { sb . append ( ", " ) ; } String columnDefinition = fieldType . getColumnDefinition ( ) ; if ( columnDefinition == null ) { // we have to call back to the database type for the specific create syntax databaseType . appendColumnArg ( tableInfo . getTableName ( ) , sb , fieldType , additionalArgs , statementsBefore , statementsAfter , queriesAfter ) ; } else { // hand defined field databaseType . appendEscapedEntityName ( sb , fieldType . getColumnName ( ) ) ; sb . append ( ' ' ) . append ( columnDefinition ) . append ( ' ' ) ; } } // add any sql that sets any primary key fields databaseType . addPrimaryKeySql ( tableInfo . getFieldTypes ( ) , additionalArgs , statementsBefore , statementsAfter , queriesAfter ) ; // add any sql that sets any unique fields databaseType . addUniqueComboSql ( tableInfo . getFieldTypes ( ) , additionalArgs , statementsBefore , statementsAfter , queriesAfter ) ; for ( String arg : additionalArgs ) { // we will have spat out one argument already so we don't have to do the first dance sb . append ( ", " ) . append ( arg ) ; } sb . append ( ") " ) ; databaseType . appendCreateTableSuffix ( sb ) ; statements . addAll ( statementsBefore ) ; statements . add ( sb . toString ( ) ) ; statements . addAll ( statementsAfter ) ; addCreateIndexStatements ( databaseType , tableInfo , statements , ifNotExists , false , logDetails ) ; addCreateIndexStatements ( databaseType , tableInfo , statements , ifNotExists , true , logDetails ) ; }
Generate and return the list of statements to create a database table and any associated features .