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
clearTable(ConnectionSource connectionSource, Class<T> dataClass)
          Clear all data out of the table.
static
<T> int
clearTable(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig)
          Clear all data out of the table.
static
<T> int
createTable(ConnectionSource connectionSource, Class<T> dataClass)
          Issue the database statements to create the table associated with a class.
static
<T> int
createTable(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig)
          Issue the database statements to create the table associated with a table configuration.
static
<T> int
createTableIfNotExists(ConnectionSource connectionSource, Class<T> dataClass)
          Create a table if it does not already exist.
static
<T> int
createTableIfNotExists(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig)
          Create a table if it does not already exist.
static
<T,ID> int
dropTable(ConnectionSource connectionSource, Class<T> dataClass, boolean ignoreErrors)
          Issue the database statements to drop the table associated with a class.
static
<T,ID> int
dropTable(ConnectionSource connectionSource, DatabaseTableConfig<T> tableConfig, boolean ignoreErrors)
          Issue the database statements to drop the table associated with a table configuration.
static
<T,ID> List<String>
getCreateTableStatements(ConnectionSource connectionSource, Class<T> dataClass)
          Return an ordered collection of SQL statements that need to be run to create a table.
static
<T,ID> List<String>
getCreateTableStatements(ConnectionSource connectionSource, 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(ConnectionSource connectionSource,
                                  Class<T> dataClass)
                       throws SQLException
Issue the database statements to create the table associated with a class.

Parameters:
connectionSource - Associated connection source.
dataClass - The class for which a table will be created.
Returns:
The number of statements executed to do so.
Throws:
SQLException

createTableIfNotExists

public static <T> int createTableIfNotExists(ConnectionSource connectionSource,
                                             Class<T> dataClass)
                                  throws SQLException
Create a table if it does not already exist. This is not supported by all databases.

Throws:
SQLException

createTable

public static <T> int createTable(ConnectionSource connectionSource,
                                  DatabaseTableConfig<T> tableConfig)
                       throws SQLException
Issue the database statements to create the table associated with a table configuration.

Parameters:
connectionSource - connectionSource Associated connection source.
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

createTableIfNotExists

public static <T> int createTableIfNotExists(ConnectionSource connectionSource,
                                             DatabaseTableConfig<T> tableConfig)
                                  throws SQLException
Create a table if it does not already exist. This is not supported by all databases.

Throws:
SQLException

getCreateTableStatements

public static <T,ID> List<String> getCreateTableStatements(ConnectionSource connectionSource,
                                                           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.support.ConnectionSource, java.lang.Class).

Parameters:
connectionSource - Our connect source which is used to get the database type, not to apply the creates.
dataClass - The class for which a table will be created.
Returns:
The collection of table create statements.
Throws:
SQLException

getCreateTableStatements

public static <T,ID> List<String> getCreateTableStatements(ConnectionSource connectionSource,
                                                           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.support.ConnectionSource, java.lang.Class).

Parameters:
connectionSource - Our connect source which is used to get the database type, not to apply the creates.
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,ID> int dropTable(ConnectionSource connectionSource,
                                   Class<T> dataClass,
                                   boolean ignoreErrors)
                     throws SQLException
Issue the database statements to drop the table associated with a class.

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

Parameters:
connectionSource - Associated connection source.
dataClass - The class for which a table will be dropped.
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,ID> int dropTable(ConnectionSource connectionSource,
                                   DatabaseTableConfig<T> tableConfig,
                                   boolean ignoreErrors)
                     throws SQLException
Issue the database statements to drop the table associated with a table configuration.

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

Parameters:
connectionSource - Associated connection source.
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

clearTable

public static <T> int clearTable(ConnectionSource connectionSource,
                                 Class<T> dataClass)
                      throws SQLException
Clear all data out of the table. For certain database types and with large sized tables, which may take a long time. In some configurations, it may be faster to drop and re-create the table.

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

Throws:
SQLException

clearTable

public static <T> int clearTable(ConnectionSource connectionSource,
                                 DatabaseTableConfig<T> tableConfig)
                      throws SQLException
Clear all data out of the table. For certain database types and with large sized tables, which may take a long time. In some configurations, it may be faster to drop and re-create the table.

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

Throws:
SQLException


This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.