All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.mike10004.common.dbhelp.ContextTableUtils Maven / Gradle / Ivy

There is a newer version: 10.0.0
Show newest version
/*
 * (c) 2015 Mike Chaberski 
 */

package com.github.mike10004.common.dbhelp;

import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTableConfig;
import com.j256.ormlite.table.TableUtils;
import java.sql.SQLException;
import java.util.List;

/**
 * Interface for table utils objects that are associated with a specific
 * database context. This interface duplicates the functionality of 
 * {@link TableUtils} but doesn't require the connection source
 * parameter that those methods require.
 * @author mchaberski
 * @see TableUtils
 */
public interface ContextTableUtils {

    /**
     * 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. *

* @param entity type * @param dataClass entity type * @return number of statements executed to perform this action * @throws java.sql.SQLException on errors clearing table data * @see TableUtils#clearTable(com.j256.ormlite.support.ConnectionSource, java.lang.Class) */ int clearTable(Class 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. *

* @param the entity type * @param tableConfig the table config * @return number of statements executed to perform this action * @throws java.sql.SQLException on errors clearing table data */ int clearTable(DatabaseTableConfig tableConfig) throws SQLException; /** * Issue the database statements to create the table associated with a class. * * @param entity type * @param dataClass entity class for which a table will be created. * @return number of statements executed to perform this action * @throws java.sql.SQLException on errors creating the table */ int createTable(Class dataClass) throws SQLException; /** * Issue the database statements to create the table associated with a table configuration. * * @param entity type * @param tableConfig hand or Spring-wired table configuration; if null * then the class must have {@link DatabaseField} annotations. * @return number of statements executed to perform this action * @throws java.sql.SQLException if creating the table fails */ int createTable(DatabaseTableConfig tableConfig) throws SQLException; /** * Create a table if it does not already exist. This is not supported by all databases. * @param entity type * @param dataClass the entity type * @return number of statements executed to perform this action * @throws java.sql.SQLException on errors creating the table */ int createTableIfNotExists(Class dataClass) throws SQLException; /** * Create multiple tables except those which already exist. * @param dataClasses entity classes * @return number of statements executed to perform this action * @throws SQLException on errors creating the tables */ int createAllTablesIfNotExists(Iterable> dataClasses) throws SQLException; /** * Create multiple tables except those which already exist. * @param dataClasses entity classes * @return number of statements executed to perform this action * @throws SQLException on errors creating the tables */ int createAllTables(Iterable> dataClasses) throws SQLException; /** * Create a table if it does not already exist. This is not supported by all databases. * @param the entity type * @param tableConfig the table configuration * @return number of statements executed in performing this action * @throws java.sql.SQLException on errors creating the table */ int createTableIfNotExists(DatabaseTableConfig tableConfig) throws SQLException; /** * Issue the database statements to drop the table associated with a class. * *

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

* * @param entity type * @param primary key type * @param dataClass * The class for which a table will be dropped. * @param ignoreErrors * If set to true then try each statement regardless of {@link SQLException} thrown previously. * @return The number of statements executed to do so. * @throws java.sql.SQLException on errors dropping the table */ int dropTable(Class dataClass, 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. *

* * @param entity type * @param primary key type * @param tableConfig * Hand or spring wired table configuration. If null then the class must have {@link DatabaseField} * annotations. * @param ignoreErrors * If set to true then try each statement regardless of {@link SQLException} thrown previously. * @return The number of statements executed to do so. * @throws java.sql.SQLException on database error */ int dropTable(DatabaseTableConfig tableConfig, boolean ignoreErrors) 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 {@link #createTable}. * * @param entity type * @param primary key type * @param dataClass * The class for which a table will be created. * @return The collection of table create statements. * @throws java.sql.SQLException on database error */ List getCreateTableStatements(Class 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 {@link #createTable}. * * @param entity type * @param primary key type * @param tableConfig * Hand or spring wired table configuration. If null then the class must have {@link DatabaseField} * annotations. * @return The collection of table create statements. * @throws java.sql.SQLException on database error */ List getCreateTableStatements(DatabaseTableConfig tableConfig) throws SQLException; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy