public String getCreateTableSQL ( ) { StringBuilder builder = new StringBuilder ( ) ; // Add columns for ( Column column : getColumns ( ) ) { addColumn ( builder , column ) ; builder . append ( ", " ) ; } // Add references StringBuilder referencesBuilder = new StringBuilder ( ) ; for ( Column column : getColumns ( ) ) { if ( column . getReference ( ) != null ) { referencesBuilder . append ( "FOREIGN KEY(" ) . append ( column . getColumnName ( ) ) . append ( ") REFERENCES " ) . append ( column . getReference ( ) . getTableName ( ) ) . append ( "(" ) . append ( column . getReference ( ) . getColumn ( ) . getColumnName ( ) ) . append ( ") ON DELETE CASCADE, " ) ; } } // Add unique constraint StringBuilder uniqueBuilder = new StringBuilder ( ) ; boolean first = true ; for ( Column column : getColumns ( ) ) { if ( column . isUnique ( ) ) { if ( ! first ) { uniqueBuilder . append ( ", " ) ; } first = false ; uniqueBuilder . append ( column . getColumnName ( ) ) ; } } return getCreateTableSQL ( builder . toString ( ) , referencesBuilder . toString ( ) , uniqueBuilder . toString ( ) ) ; }
Creates the SQL statement to create the table according columns definitions .