com.j256.ormlite.table
Class TableUtils

java.lang.Object
  extended by com.j256.ormlite.table.TableUtils

public class TableUtils
extends Object

Couple utility methods for the creating, dropping, and maintenance of tables.

Author:
graywatson

Method Summary
static
<T> int
createTable(DatabaseType databaseType, DataSource dataSource, Class<T> dataClass)
          Issue the database statements to create the table associated with a class.
static
<T> int
createTable(DatabaseType databaseType, DataSource dataSource, DatabaseTableConfig<T> tableConfig)
          Issue the database statements to create the table associated with a class.
static
<T> int
dropTable(DatabaseType databaseType, DataSource dataSource, Class<T> dataClass, boolean ignoreErrors)
          Issue the database statements to create the table associated with a class.
static
<T> int
dropTable(DatabaseType databaseType, DataSource dataSource, DatabaseTableConfig<T> tableConfig, boolean ignoreErrors)
          Issue the database statements to create the table associated with a class.
static
<T> List<String>
getCreateTableStatements(DatabaseType databaseType, Class<T> dataClass)
          Return an ordered collection of SQL statements that need to be run to create a table.
static
<T> List<String>
getCreateTableStatements(DatabaseType databaseType, DatabaseTableConfig<T> tableConfig)
          Return an ordered collection of SQL statements that need to be run to create a table.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createTable

public static <T> int createTable(DatabaseType databaseType,
                                  DataSource dataSource,
                                  Class<T> dataClass)
                       throws SQLException
Issue the database statements to create the table associated with a class. Most likely this will be done only when a database is configured or in unit tests.

Parameters:
databaseType - Our database type.
dataSource - Associated DataSource.
dataClass - The class for which a table will be created.
Returns:
The number of statements executed to do so.
Throws:
SQLException

createTable

public static <T> int createTable(DatabaseType databaseType,
                                  DataSource dataSource,
                                  DatabaseTableConfig<T> tableConfig)
                       throws SQLException
Issue the database statements to create the table associated with a class. Most likely this will be done only when a database is configured or in unit tests.

Parameters:
databaseType - Our database type.
dataSource - Associated DataSource.
tableConfig - Hand or spring wired table configuration. If null then the class must have DatabaseField annotations.
Returns:
The number of statements executed to do so.
Throws:
SQLException

getCreateTableStatements

public static <T> List<String> getCreateTableStatements(DatabaseType databaseType,
                                                        Class<T> dataClass)
                                             throws SQLException
Return an ordered collection of SQL statements that need to be run to create a table. To do the work of creating, you should call createTable(com.j256.ormlite.db.DatabaseType, javax.sql.DataSource, java.lang.Class).

Parameters:
databaseType - Our database type.
dataClass - The class for which a table will be created.
Returns:
The collection of table create statements.
Throws:
SQLException

getCreateTableStatements

public static <T> List<String> getCreateTableStatements(DatabaseType databaseType,
                                                        DatabaseTableConfig<T> tableConfig)
                                             throws SQLException
Return an ordered collection of SQL statements that need to be run to create a table. To do the work of creating, you should call createTable(com.j256.ormlite.db.DatabaseType, javax.sql.DataSource, java.lang.Class).

Parameters:
databaseType - Our database type.
tableConfig - Hand or spring wired table configuration. If null then the class must have DatabaseField annotations.
Returns:
The collection of table create statements.
Throws:
SQLException

dropTable

public static <T> int dropTable(DatabaseType databaseType,
                                DataSource dataSource,
                                Class<T> dataClass,
                                boolean ignoreErrors)
                     throws SQLException
Issue the database statements to create the table associated with a class. Most likely this will be done only in unit tests.

WARNING: This is [obviously] very destructive and unrecoverable.

Parameters:
databaseType - Our database type.
dataSource - Associated DataSource.
dataClass - The class for which a table will be created.
ignoreErrors - If set to true then try each statement regardless of SQLException thrown previously.
Returns:
The number of statements executed to do so.
Throws:
SQLException

dropTable

public static <T> int dropTable(DatabaseType databaseType,
                                DataSource dataSource,
                                DatabaseTableConfig<T> tableConfig,
                                boolean ignoreErrors)
                     throws SQLException
Issue the database statements to create the table associated with a class. Most likely this will be done only in unit tests.

WARNING: This is [obviously] very destructive and unrecoverable.

Parameters:
databaseType - Our database type.
dataSource - Associated DataSource.
tableConfig - Hand or spring wired table configuration. If null then the class must have DatabaseField annotations.
ignoreErrors - If set to true then try each statement regardless of SQLException thrown previously.
Returns:
The number of statements executed to do so.
Throws:
SQLException


Copyright © 2010. All Rights Reserved.