Produced by Siminov Software Solution LLP

siminov.orm.database
Class Database

java.lang.Object
  extended by siminov.orm.database.Database
All Implemented Interfaces:
Constants

public abstract class Database
extends java.lang.Object
implements Constants

Exposes methods to deal with database. It has methods to create, delete, and perform other common database management tasks.


Field Summary
 
Fields inherited from interface siminov.orm.Constants
ANDROID_METADATA_TABLE_NAME, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTIES_METHOD_GET_PROPERTIES, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_CHECK, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_DEFAULT, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_METHOD_GET_NAME, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_METHOD_GET_VALUE, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_NOT_NULL, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_PRIMARY_KEY, ANNOTATION_DATABASE_MAPPING_COLUMN_PROPERTY_UNIQUE, ANNOTATION_DATABASE_MAPPING_INDEX_COLUMN_METHOD_GET_COLUMN, ANNOTATION_DATABASE_MAPPING_INDEX_METHOD_GET_IS_UNIQUE, ANNOTATION_DATABASE_MAPPING_INDEX_METHOD_GET_NAME, ANNOTATION_DATABASE_MAPPING_INDEX_METHOD_GET_VALUE, ANNOTATION_DATABASE_MAPPING_INDEXES_METHOD_GET_VALUES, ANNOTATION_DATABASE_MAPPING_METHOD_GET_COLUMN_NAME, ANNOTATION_DATABASE_MAPPING_METHOD_GET_TABLE_NAME, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_ON_DELETE_ATTRIBUTE, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_ON_UPDATE_ATTRIBUTE, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_PROPERTIES_METHOD_GET_PROPERTIES, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_PROPERTY_LOAD, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_PROPERTY_METHOD_GET_NAME, ANNOTATION_DATABASE_MAPPING_RELATIONSHIP_PROPERTY_METHOD_GET_VALUE, APPLICATION_DESCRIPTOR_DATABASE_DESCRIPTOR, APPLICATION_DESCRIPTOR_DATABASE_DESCRIPTORS, APPLICATION_DESCRIPTOR_DESCRIPTION, APPLICATION_DESCRIPTOR_EVENT_HANDLER, APPLICATION_DESCRIPTOR_EVENT_HANDLERS, APPLICATION_DESCRIPTOR_FILE_NAME, APPLICATION_DESCRIPTOR_LOAD_INITIALLY, APPLICATION_DESCRIPTOR_NAME, APPLICATION_DESCRIPTOR_PROPERTY, APPLICATION_DESCRIPTOR_SIMINOV, APPLICATION_DESCRIPTOR_VERSION, DATABASE_DESCRIPTOR, DATABASE_DESCRIPTOR_DATABASE_MAPPING, DATABASE_DESCRIPTOR_DATABASE_MAPPINGS, DATABASE_DESCRIPTOR_DATABASE_NAME, DATABASE_DESCRIPTOR_DESCRIPTION, DATABASE_DESCRIPTOR_EXTERNAL_STORAGE, DATABASE_DESCRIPTOR_IS_LOCKING_REQUIRED, DATABASE_DESCRIPTOR_LIBRARIES, DATABASE_DESCRIPTOR_LIBRARY, DATABASE_DESCRIPTOR_PATH, DATABASE_DESCRIPTOR_PROPERTY, DATABASE_DESCRIPTOR_PROPERTY_NAME, DATABASE_DESCRIPTOR_TYPE, DATABASE_DESCRIPTOR_VERSION, DATABASE_MAPPING_DESCRIPTOR_CHECK, DATABASE_MAPPING_DESCRIPTOR_CLASS_NAME, DATABASE_MAPPING_DESCRIPTOR_COLUMN, DATABASE_MAPPING_DESCRIPTOR_COLUMN_NAME, DATABASE_MAPPING_DESCRIPTOR_DATABASE_MAPPING, DATABASE_MAPPING_DESCRIPTOR_DEFAULT_VALUE, DATABASE_MAPPING_DESCRIPTOR_INDEX, DATABASE_MAPPING_DESCRIPTOR_NAME, DATABASE_MAPPING_DESCRIPTOR_NOT_NULL, DATABASE_MAPPING_DESCRIPTOR_NOT_NULL_FALSE, DATABASE_MAPPING_DESCRIPTOR_NOT_NULL_TRUE, DATABASE_MAPPING_DESCRIPTOR_PRIMARY_KEY, DATABASE_MAPPING_DESCRIPTOR_PROPERTY, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_CASCADE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_LOAD, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_LOAD_FALSE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_LOAD_TRUE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_MANY_TO_MANY, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_MANY_TO_ONE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_NO_ACTION, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_ON_DELETE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_ON_UPDATE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_ONE_TO_MANY, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_ONE_TO_ONE, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_REFER, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_REFER_TO, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_RESTRICT, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_SET_DEFAULT, DATABASE_MAPPING_DESCRIPTOR_RELATIONSHIPS_SET_NULL, DATABASE_MAPPING_DESCRIPTOR_TABLE, DATABASE_MAPPING_DESCRIPTOR_TABLE_NAME, DATABASE_MAPPING_DESCRIPTOR_TYPE, DATABASE_MAPPING_DESCRIPTOR_UNIQUE, DATABASE_MAPPING_DESCRIPTOR_UNIQUE_FALSE, DATABASE_MAPPING_DESCRIPTOR_UNIQUE_TRUE, DATABASE_MAPPING_DESCRIPTOR_VARIABLE_NAME, DATABASE_PATH_DATA, DATABASE_PATH_DATABASE, FALSE, FORM_ALTER_ADD_COLUMN_QUERY_COLUMN_NAME_PARAMETER, FORM_ALTER_ADD_COLUMN_QUERY_TABLE_NAME_PARAMETER, FORM_AVG_QUERY_COLUMN_PARAMETER, FORM_AVG_QUERY_GROUP_BYS_PARAMETER, FORM_AVG_QUERY_HAVING_PARAMETER, FORM_AVG_QUERY_TABLE_NAME_PARAMETER, FORM_AVG_QUERY_WHERE_CLAUSE_PARAMETER, FORM_COUNT_QUERY_COLUMN_PARAMETER, FORM_COUNT_QUERY_DISTINCT_PARAMETER, FORM_COUNT_QUERY_GROUP_BYS_PARAMETER, FORM_COUNT_QUERY_HAVING_PARAMETER, FORM_COUNT_QUERY_TABLE_NAME_PARAMETER, FORM_COUNT_QUERY_WHERE_CLAUSE_PARAMETER, FORM_CREATE_INDEX_QUERY_COLUMN_NAMES_PARAMETER, FORM_CREATE_INDEX_QUERY_INDEX_NAME_PARAMETER, FORM_CREATE_INDEX_QUERY_IS_UNIQUE_PARAMETER, FORM_CREATE_INDEX_QUERY_TABLE_NAME_PARAMETER, FORM_CREATE_TABLE_QUERY_CHECKS_PARAMETER, FORM_CREATE_TABLE_QUERY_COLUMN_NAMES_PARAMETER, FORM_CREATE_TABLE_QUERY_COLUMN_TYPES_PARAMETER, FORM_CREATE_TABLE_QUERY_DEFAULT_VALUES_PARAMETER, FORM_CREATE_TABLE_QUERY_FOREIGN_KEYS_PARAMETER, FORM_CREATE_TABLE_QUERY_NOT_NULLS_PARAMETER, FORM_CREATE_TABLE_QUERY_PRIMARY_KEYS_PARAMETER, FORM_CREATE_TABLE_QUERY_TABLE_NAME_PARAMETER, FORM_CREATE_TABLE_QUERY_UNIQUE_COLUMNS_PARAMETER, FORM_DELETE_QUERY_TABLE_NAME_PARAMETER, FORM_DELETE_QUERY_WHERE_CLAUSE_PARAMETER, FORM_DROP_INDEX_QUERY_INDEX_NAME_PARAMETER, FORM_DROP_INDEX_QUERY_TABLE_NAME_PARAMETER, FORM_DROP_TABLE_QUERY_TABLE_NAME_PARAMETER, FORM_FOREIGN_KEYS_DATABASE_DESCRIPTOR_PARAMETER, FORM_GROUP_CONCAT_QUERY_COLUMN_PARAMETER, FORM_GROUP_CONCAT_QUERY_DELIMITER_PARAMETER, FORM_GROUP_CONCAT_QUERY_GROUP_BYS_PARAMETER, FORM_GROUP_CONCAT_QUERY_HAVING_PARAMETER, FORM_GROUP_CONCAT_QUERY_TABLE_NAME_PARAMETER, FORM_GROUP_CONCAT_QUERY_WHERE_CLAUSE_PARAMETER, FORM_MAX_QUERY_COLUMN_PARAMETER, FORM_MAX_QUERY_GROUP_BYS_PARAMETER, FORM_MAX_QUERY_HAVING_PARAMETER, FORM_MAX_QUERY_TABLE_NAME_PARAMETER, FORM_MAX_QUERY_WHERE_CLAUSE_PARAMETER, FORM_MIN_QUERY_COLUMN_PARAMETER, FORM_MIN_QUERY_GROUP_BYS_PARAMETER, FORM_MIN_QUERY_HAVING_PARAMETER, FORM_MIN_QUERY_TABLE_NAME_PARAMETER, FORM_MIN_QUERY_WHERE_CLAUSE_PARAMETER, FORM_SAVE_BIND_QUERY_COLUMN_NAMES_PARAMETER, FORM_SAVE_BIND_QUERY_TABLE_NAME_PARAMETER, FORM_SELECT_QUERY_COLUMN_NAMES_PARAMETER, FORM_SELECT_QUERY_DISTINCT_PARAMETER, FORM_SELECT_QUERY_GROUP_BYS_PARAMETER, FORM_SELECT_QUERY_HAVING_PARAMETER, FORM_SELECT_QUERY_LIMIT_PARAMETER, FORM_SELECT_QUERY_ORDER_BYS_PARAMETER, FORM_SELECT_QUERY_TABLE_NAME_PARAMETER, FORM_SELECT_QUERY_WHERE_CLAUSE_PARAMETER, FORM_SELECT_QUERY_WHICH_ORDER_BY_PARAMETER, FORM_SUM_QUERY_COLUMN_PARAMETER, FORM_SUM_QUERY_GROUP_BYS_PARAMETER, FORM_SUM_QUERY_HAVING_PARAMETER, FORM_SUM_QUERY_TABLE_NAME_PARAMETER, FORM_SUM_QUERY_WHERE_CLAUSE_PARAMETER, FORM_TABLE_INFO_QUERY_NAME, FORM_TABLE_INFO_QUERY_TABLE_NAME_PARAMETER, FORM_TABLE_NAMES_NAME, FORM_TOTAL_QUERY_COLUMN_PARAMETER, FORM_TOTAL_QUERY_GROUP_BYS_PARAMETER, FORM_TOTAL_QUERY_HAVING_PARAMETER, FORM_TOTAL_QUERY_TABLE_NAME_PARAMETER, FORM_TOTAL_QUERY_WHERE_CLAUSE_PARAMETER, FORM_UPDATE_BIND_QUERY_COLUMN_NAMES_PARAMETER, FORM_UPDATE_BIND_QUERY_TABLE_NAME_PARAMETER, FORM_UPDATE_BIND_QUERY_WHERE_CLAUSE_PARAMETER, FORM_UPDATE_DATABASE_VERSION_QUERY_DATABASE_VERSION_PARAMETER, LIBRARY_DESCRIPTOR_DATABASE_MAPPING, LIBRARY_DESCRIPTOR_DATABASE_MAPPINGS, LIBRARY_DESCRIPTOR_DESCRIPTION, LIBRARY_DESCRIPTOR_FILE_NAME, LIBRARY_DESCRIPTOR_LIBRARY, LIBRARY_DESCRIPTOR_NAME, LIBRARY_DESCRIPTOR_PATH, LIBRARY_DESCRIPTOR_PROPERTY, QUERY_BUILDER_CASCADE, QUERY_BUILDER_IS_NULL, QUERY_BUILDER_NO_ACTION, QUERY_BUILDER_ON_DELETE, QUERY_BUILDER_ON_UPDATE, QUERY_BUILDER_RESTRICT, QUERY_BUILDER_SET_DEFAULT, QUERY_BUILDER_SET_NULL, SIMINOV_DESCRIPTOR_EXTENSION, SQLITE_DATABASE, SQLITE_DATABASE_BEGIN_TRANSACTION, SQLITE_DATABASE_COMMIT_TRANSACTION, SQLITE_DATABASE_ENABLE_LOCKING, SQLITE_DATABASE_END_TRANSACTION, SQLITE_DATABASE_EXTENSION, SQLITE_DATABASE_QUERY_TO_ENABLE_FOREIGN_KEYS_MAPPING, TRUE, XML_FILE_EXTENSION
 
Constructor Summary
Database()
           
 
Method Summary
 IAverage avg()
          Returns the average based on column name provided.
static void beginTransaction(DatabaseDescriptor databaseDescriptor)
          Begins a transaction in EXCLUSIVE mode.
static void commitTransaction(DatabaseDescriptor databaseDescriptor)
          Marks the current transaction as successful.
 ICount count()
          Returns the count of rows based on information provided.
static DatabaseBundle createDatabase(DatabaseDescriptor databaseDescriptor)
          It is used to create instance of IDatabase implementation.
 void createIndex(DatabaseMappingDescriptor.Index index)
          Is used to create a new index on a table in database.
static void createIndex(DatabaseMappingDescriptor databaseMappingDescriptor, DatabaseMappingDescriptor.Index index)
          Is used to create a new index on a table in database.
static void createTable(DatabaseMappingDescriptor databaseMappingDescriptor)
          Is used to create a new table in an database.
static void createTables(java.util.Iterator<DatabaseMappingDescriptor> databaseMappings)
          Is used to create a new table in an database.
 IDelete delete()
          It deletes a record to any single table in a relational database.
static void dropDatabase(DatabaseDescriptor databaseDescriptor)
          It drop's the whole database based on database-descriptor.
 void dropIndex(DatabaseMappingDescriptor.Index index)
          Is used to drop a index on a table in database.
static void dropIndex(DatabaseMappingDescriptor databaseMapping, DatabaseMappingDescriptor.Index index)
           
static void dropIndex(DatabaseMappingDescriptor databaseMappingDescriptor, java.lang.String indexName)
          Is used to drop a index on a table in database.
 void dropIndex(java.lang.String indexName)
           
 void dropTable()
          It drop's the table from database
static void dropTable(DatabaseMappingDescriptor databaseMappingDescriptor)
          It drop's the table from database based on database-mapping.
static void endTransaction(DatabaseDescriptor databaseDescriptor)
          End the current transaction.
 java.util.Iterator<java.lang.String> getColumnNames()
          Returns all column names of mapped table.
 java.util.Map<java.lang.String,java.lang.String> getColumnTypes()
          Returns all columns with there data types for invoked class object.
 java.util.Map<java.lang.String,java.lang.Object> getColumnValues()
          Returns all column values in the same order of column names for invoked class object.
 DatabaseDescriptor getDatabaseDescriptor()
          Returns database descriptor object based on the POJO class called.
static DatabaseDescriptor getDatabaseDescriptor(java.lang.String className)
           
 DatabaseMappingDescriptor getDatabaseMappingDescriptor()
          Returns the actual database mapping object mapped for invoked class object.
 java.util.Iterator<java.lang.String> getForeignKeys()
          Returns all foreign keys of mapped table for invoked class object.
 java.util.Iterator<java.lang.String> getMandatoryFields()
          Returns all mandatory fields which are associated with mapped table for invoked class object.
 java.util.Iterator<java.lang.String> getPrimaryKeys()
          Returns all primary keys of mapped table for invoked class object.
 java.lang.String getTableName()
          Returns the mapped table name for invoked class object.
 java.util.Iterator<java.lang.String> getUniqueFields()
          Returns all unique fields which are associated with mapped table for invoked class object.
 IGroupConcat groupConcat()
          Returns the group concat based on column name provided.
 IMax max()
          Returns the minimum based on column name provided.
 IMin min()
          Returns the minimum based on column name provided.
 void save()
          It adds a record to any single table in a relational database.
 void saveOrUpdate()
          It finds out whether tuple exists in table or not.
 ISelect select()
          Fetch tuples from table.
 java.lang.Object[] select(java.lang.String query)
          Returns all tuples based on manual query from mapped table for invoked class object.
 ISum sum()
          Returns the sum based on column name provided.
 ITotal total()
          Returns the total based on column name provided.
 void update()
          It updates a record to any single table in a relational database.
static void upgradeDatabase(DatabaseDescriptor databaseDescriptor)
          Upgrade Existing Database.
static void upgradeTable(DatabaseMappingDescriptor databaseMappingDescriptor)
          Upgrade Table.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Database

public Database()
Method Detail

createDatabase

public static DatabaseBundle createDatabase(DatabaseDescriptor databaseDescriptor)
                                     throws DatabaseException
It is used to create instance of IDatabase implementation.

Parameters:
databaseDescriptor -
Returns:
Throws:
DatabaseException

upgradeDatabase

public static void upgradeDatabase(DatabaseDescriptor databaseDescriptor)
                            throws DatabaseException
Upgrade Existing Database.

Parameters:
databaseDescriptor -
Throws:
DatabaseException - throws If any exception thrown.

upgradeTable

public static void upgradeTable(DatabaseMappingDescriptor databaseMappingDescriptor)
                         throws DatabaseException
Upgrade Table.

Parameters:
databaseMappingDescriptor - object related to table.
Throws:
DatabaseException - If any exception thrown while upgrating table.

createTables

public static void createTables(java.util.Iterator<DatabaseMappingDescriptor> databaseMappings)
                         throws DatabaseException
Is used to create a new table in an database.

Using SIMINOV there are three ways to create table in database.

 
                        
  • Describing table structure in form of DATABASE-MAPPING-DESCRIPTOR XML file. And creation of table will be handled by SIMINOV.

    SIMINOV will parse each DATABASE-MAPPING-DESCRIPTOR XML defined by developer and create table's in database. Example: <database-mapping> <table table_name="LIQUOR" class_name="com.core.template.model.Liquor"> <column variable_name="liquorType" column_name="LIQUOR_TYPE"> <property name="type">TEXT</property> <property name="primary_key">true</property> <property name="not_null">true</property> <property name="unique">true</property> </column> <column variable_name="description" column_name="DESCRIPTION"> <property name="type">TEXT</property> </column> <column variable_name="history" column_name="HISTORY"> <property name="type">TEXT</property> </column> <column variable_name="link" column_name="LINK"> <property name="type">TEXT</property> <property name="default">www.wikipedia.org</property> </column> <column variable_name="alcholContent" column_name="ALCHOL_CONTENT"> <property name="type">TEXT</property> </column> <maps> <map map="liquorBrands" map_to="com.core.template.model.LiquorBrand"> <property name="load">false</property> <property name="relationship_type">ONE-TO-MANY</property> </map> </maps> <index name="LIQUOR_INDEX_BASED_ON_LINK" unique="true"> <column>HISTORY</column> </index> </table> </database-mapping>

  • Describing table through Defining Annotations in Java POJO. And creation of table will be handled by SIMINOV.

    SIMINOV will read each class Annotations defined by developer and create table's in database. Example:

    Parameters:
    databaseMappings - Database-mapping objects which defines the structure of each table.
    Throws:
    DatabaseException - If not able to create table in SQLite.

createTable

public static void createTable(DatabaseMappingDescriptor databaseMappingDescriptor)
                        throws DatabaseException
Is used to create a new table in an database.

 Manually creating table structure using DatabaseMapping POJO class. 

        Example: 

                //Defines structure for Liquor table.
                DatabaseMapping databaseMapping = new DatabaseMapping();
                databaseMapping.setTableName("LIQUOR");
                databaseMapping.setClassName(Liquor.class.getName());

                //Add Liquor Type.
                DatabaseMapping.Column liquorType = databaseMapping.new Column();
                liquorType.setVariableName("liquorType");
                liquorType.setColumnName("LIQUOR_TYPE");

                liquorType.setType("TEXT");

                liquorType.setPrimaryKey(true);
                liquorType.setNotNull(true);
                liquorType.setUnique(false);

                liquorType.setGetterMethodName("getLiquorType");
                liquorType.setSetterMethodName("setLiquorType");

                databaseMapping.addColumn(liquorType);

                //Add Liquor Description.
                DatabaseMapping.Column description = databaseMapping.new Column();
                description.setVariableName("description");
                description.setColumnName("DESCRIPTION");

                description.setType("TEXT");

                description.setGetterMethodName("getDescription");
                description.setSetterMethodName("setDescription");

                databaseMapping.addColumn(description);

                //Add History.
                DatabaseMapping.Column history = databaseMapping.new Column();
                history.setVariableName("history");
                history.setColumnName("HISTORY");

                history.setType("TEXT");

                history.setGetterMethodName("getHistory");
                history.setSetterMethodName("setHistory");

                databaseMapping.addColumn(history);

                //Add Link.
                DatabaseMapping.Column link = databaseMapping.new Column();
                link.setVariableName("history");
                link.setColumnName("HISTORY");

                link.setType("TEXT");
                link.setDefault("www.wikipedia.org");

                link.setGetterMethodName("getLink");
                link.setSetterMethodName("setLink");

                databaseMapping.addColumn(link);

                //Add Alchol Content.
                DatabaseMapping.Column alcholContent = databaseMapping.new Column();
                alcholContent.setVariableName("alcholContent");
                alcholContent.setColumnName("ALCHOL_CONTENT");

                alcholContent.setType("TEXT");

                alcholContent.setGetterMethodName("getAlcholContent");
                alcholContent.setSetterMethodName("setAlcholContent");

                databaseMapping.addColumn(alcholContent);

                //Create Index On Liquor table.
                DatabaseMapping.Index indexOnLiquor = databaseMapping.new Index();
                indexOnLiquor.setName("LIQUOR_INDEX_BASED_ON_LINK");
                indexOnLiquor.setUnique(true);

                //Add Columns on which we need index.
                indexOnLiquor.addColumn("LINK");

                databaseMapping.addIndex(indexOnLiquor);

                try {
                        Database.createTables(databaseMapping);
                } catch(DatabaseException databaseException) {
                        //Log It.
                }

                
                        

Parameters:
databaseMappingDescriptor - Database-mapping object which defines the structure of table.
Throws:
DatabaseException - If not able to create table in SQLite.

dropTable

public void dropTable()
               throws DatabaseException
It drop's the table from database

 

        try {
                new Liquor().dropTable();
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
                        

Throws:
DatabaseException - If not able to drop table.

dropTable

public static void dropTable(DatabaseMappingDescriptor databaseMappingDescriptor)
                      throws DatabaseException
It drop's the table from database based on database-mapping.

 Drop the Liquor table.

        DatabaseMapping databaseMapping = new Liquor().getDatabaseMapping();

        try {
                Database.dropTable(databaseMapping);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        

                        

Parameters:
databaseMappingDescriptor - Database-mapping object which defines the structure of table.
Throws:
DatabaseException - If not able to drop table.

createIndex

public static void createIndex(DatabaseMappingDescriptor databaseMappingDescriptor,
                               DatabaseMappingDescriptor.Index index)
                        throws DatabaseException
Is used to create a new index on a table in database.

 Create Index On Liquor table.

        DatabaseMapping.Index indexOnLiquor = databaseMapping.new Index();
        indexOnLiquor.setName("LIQUOR_INDEX_BASED_ON_LINK");
        indexOnLiquor.setUnique(true);

        //Add Columns on which we need index.
        indexOnLiquor.addColumn("LINK");

        DatabaseMapping databaseMapping = new Liquor().getDatabaseMapping();

        try {
                Database.createIndex(databaseMapping, indexOnLiquor);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
                        

Parameters:
databaseMappingDescriptor - Database-mapping object which defines the structure of table.
index - Index object which defines the structure of index needs to create.
Throws:
DatabaseException - If not able to create index on table.

createIndex

public void createIndex(DatabaseMappingDescriptor.Index index)
                 throws DatabaseException
Is used to create a new index on a table in database.

 Create Index On Liquor table.

        DatabaseMapping.Index indexOnLiquor = databaseMapping.new Index();
        indexOnLiquor.setName("LIQUOR_INDEX_BASED_ON_LINK");
        indexOnLiquor.setUnique(true);

        //Add Columns on which we need index.
        indexOnLiquor.addColumn("LINK");

        try {
                new Liquor().createIndex(indexOnLiquor);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        

                        

Parameters:
index - Index object which defines the structure of index needs to create.
Throws:
DatabaseException - If not able to create index on table.

dropIndex

public void dropIndex(DatabaseMappingDescriptor.Index index)
               throws DatabaseException
Is used to drop a index on a table in database.

 Create Index On Liquor table.

        String indexName = "LIQUOR_INDEX_BASED_ON_LINK";

        try {
                new Liquor().dropIndex(indexName);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
                        

Parameters:
index - Name of a index needs to be drop.
Throws:
DatabaseException - If not able to drop index on table.

dropIndex

public void dropIndex(java.lang.String indexName)
               throws DatabaseException
Throws:
DatabaseException

dropIndex

public static void dropIndex(DatabaseMappingDescriptor databaseMapping,
                             DatabaseMappingDescriptor.Index index)
                      throws DatabaseException
Throws:
DatabaseException

dropIndex

public static void dropIndex(DatabaseMappingDescriptor databaseMappingDescriptor,
                             java.lang.String indexName)
                      throws DatabaseException
Is used to drop a index on a table in database.

 Create Index On Liquor table.

        String indexName = "LIQUOR_INDEX_BASED_ON_LINK";
        DatabaseMapping databaseMapping = new Liquor().getDatabaseMapping();

        try {
                Database.dropIndex(databaseMapping, indexName);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
                        

Parameters:
databaseMappingDescriptor - Database-mapping object which defines the structure of table.
indexName - Name of a index needs to be drop.
Throws:
DatabaseException - If not able to drop index on table.

dropDatabase

public static void dropDatabase(DatabaseDescriptor databaseDescriptor)
                         throws DatabaseException
It drop's the whole database based on database-descriptor.

 Drop the Liquor table.

        DatabaseDescriptor databaseDescriptor = new Liquor().getDatabaseDescriptor();

        try {
                Database.dropDatabase(databaseDescriptor);
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
                        

Parameters:
databaseMapping - Database-mapping object which defines the structure of table.
Throws:
DatabaseException - If not able to drop database.

beginTransaction

public static void beginTransaction(DatabaseDescriptor databaseDescriptor)
                             throws DatabaseException
Begins a transaction in EXCLUSIVE mode.

Transactions can be nested. When the outer transaction is ended all of the work done in that transaction and all of the nested transactions will be committed or rolled back. The changes will be rolled back if any transaction is ended without being marked as clean(by calling commitTransaction). Otherwise they will be committed.


Example: Make Beer Object

        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        DatabaseDescriptor databaseDescriptor = beer.getDatabaseDescriptor();

        try {
                Database.beginTransaction(databaseDescriptor);

                beer.save();

                Database.commitTransaction(databaseDescriptor);
        } catch(DatabaseException de) {
                //Log it.
        } finally {
                Database.endTransaction(databaseDescriptor);
        }

                                
           

Throws:
DatabaseException - If beginTransaction does not starts.

commitTransaction

public static void commitTransaction(DatabaseDescriptor databaseDescriptor)
                              throws DatabaseException
Marks the current transaction as successful.

Finally it will End a transaction.


Example: Make Beer Object
        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        DatabaseDescriptor databaseDescriptor = beer.getDatabaseDescriptor();

        try {
                Database.beginTransaction(databaseDescriptor);

                beer.save();

                Database.commitTransaction(databaseDescriptor);
        } catch(DatabaseException de) {
                //Log it.
        } finally {
                Database.endTransaction(databaseDescriptor);
        }

        

            

Throws:
DatabaseException - If not able to commit the transaction.

endTransaction

public static void endTransaction(DatabaseDescriptor databaseDescriptor)
End the current transaction.

Example:
        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        DatabaseDescriptor databaseDescriptor = beer.getDatabaseDescriptor();

        try {
                Database.beginTransaction(databaseDescriptor);

                beer.save();

                Database.commitTransaction(databaseDescriptor);
        } catch(DatabaseException de) {
                //Log it.
        } finally {
                Database.endTransaction(databaseDescriptor);
        }

        
        

Parameters:
databaseDescriptor - Database Descriptor Object.

select

public ISelect select()
               throws DatabaseException
Fetch tuples from table.

Example:
        Liquor[] liquor =  new Liquor().select()
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .and(Liquor.ALCHOL_CONTENT).equalTo("90%")
                                        .fetch();

        
        

Returns:
ISelect to provide extra information based on which tuples will be fetched from table.
Throws:
DatabaseException - if any error occur while fetching tuples from table.

select

public java.lang.Object[] select(java.lang.String query)
                          throws DatabaseException
Returns all tuples based on manual query from mapped table for invoked class object.

Example:

        String query = "SELECT * FROM LIQUOR";

        Liquor[] liquors = null;
        try {
                liquors = new Liquor().select(query);
        } catch(DatabaseException de) {
                //Log it.
        }

                                
                

Parameters:
query - Manual query on which tuples need to be fetched.
Returns:
Array Of Objects.
Throws:
DatabaseException - If any error occur while getting tuples from a single table.

save

public void save()
          throws DatabaseException
It adds a record to any single table in a relational database.

Example: Make Liquor Object

        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        try {
                beer.save();
        } catch(DatabaseException de) {
                //Log it.
        }

        

            

Throws:
DatabaseException - If any error occurs while saving tuples in database.

update

public void update()
            throws DatabaseException
It updates a record to any single table in a relational database.

Example: Make Beer Object

        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        try {
                beer.update();
        } catch(DatabaseException de) {
                //Log it.
        }

        
            

Throws:
DatabaseException - If any error occurs while saving tuples in database.

saveOrUpdate

public void saveOrUpdate()
                  throws DatabaseException
It finds out whether tuple exists in table or not. IF NOT EXISTS: adds a record to any single table in a relational database. ELSE: updates a record to any single table in a relational database.

Example: Make Beer Object

        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        try {
                beer.saveOrUpdate();
        } catch(DatabaseException de) {
                //Log it.
        }

                                

            

Throws:
DatabaseException - If any error occurs while saving tuples in database.

delete

public IDelete delete()
               throws DatabaseException
It deletes a record to any single table in a relational database.

Example:

        Liquor beer = new Liquor();
        beer.setLiquorType(Liquor.LIQUOR_TYPE_BEER);
        beer.setDescription(applicationContext.getString(R.string.beer_description));
        beer.setHistory(applicationContext.getString(R.string.beer_history));
        beer.setLink(applicationContext.getString(R.string.beer_link));
        beer.setAlcholContent(applicationContext.getString(R.string.beer_alchol_content));

        try {
                beer.delete();
        } catch(DatabaseException de) {
                //Log it.
        }

        OR

        try {
                new Liquor().delete();
        } catch(DatabaseException de) {
                //Log It.
        }

        

            

Throws:
DatabaseException - If any error occurs while saving tuples in database.

count

public ICount count()
             throws DatabaseException
Returns the count of rows based on information provided.

Example:
        int count = 0;

        try {
                count = new Liquor().count().
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

        

    

Returns:
ICount to provide extra information based on which count will be calculated.
Throws:
DatabaseException - If any error occur while find count.

avg

public IAverage avg()
             throws DatabaseException
Returns the average based on column name provided.

Example:
        int average = 0;

        try {
                average = new Liquor().avg()
                                        .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

        
            

Returns:
IAverage to provide extra information based on which average will be calculated.
Throws:
DatabaseException - If any error occur while finding average.

sum

public ISum sum()
         throws DatabaseException
Returns the sum based on column name provided.

Example:
        int sum = 0;

        try {
                sum = new Liquor().sum()
                                        .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

                                
            

Returns:
ISum to provide extra information based on which sum will be calculated.
Throws:
DatabaseException - If any error occur while finding sum.

total

public ITotal total()
             throws DatabaseException
Returns the total based on column name provided.

Example:
        int total = 0;

        try {
                total = new Liquor().total()
                                        .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

            
            

Returns:
ITotal to provide extra information based on which total will be calculated.
Throws:
DatabaseException - If any error occur while finding total.

min

public IMin min()
         throws DatabaseException
Returns the minimum based on column name provided.

Example:
        int minimum = 0;

        try {
                minimum = new Liquor().min()
                                        .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

        

            

Returns:
IMin to provide extra information based on which minimum will be calculated.
Throws:
DatabaseException - If any error occur while finding minimum.

max

public IMax max()
         throws DatabaseException
Returns the minimum based on column name provided.

        Example:
        int maximum = 0;

        try {
                maximum = new Liquor().max()
                                        .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                        .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                        .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

        

            

Returns:
IMax to provide extra information based on which maximum will be calculated.
Throws:
DatabaseException - If any error occur while finding minimum.

groupConcat

public IGroupConcat groupConcat()
                         throws DatabaseException
Returns the group concat based on column name provided.

Example:
        int groupConcat = 0;

        try {
                groupConcat = new Liquor().groupConcat()
                                                .column(Liquor.COLUMN_NAME_WHICH_CONTAIN_NUMBRIC_VALUE)
                                                .where(Liquor.LIQUOR_TYPE).equalTo("RUM")
                                                .execute();

        } catch(DatabaseException de) {
                //Log it.
        }

        
            

Returns:
IGroupConcat to provide extra information based on which group concat will be calculated.
Throws:
DatabaseException - If any error occur while finding group concat.

getDatabaseDescriptor

public DatabaseDescriptor getDatabaseDescriptor()
                                         throws DatabaseException
Returns database descriptor object based on the POJO class called.
Example:

        try {
                DatabaseDescriptor databaseDescriptor = new Liquor().getDatabaseDescriptor();
        } catch(DatabaseException databaseException) {
                //Log It.
        }

        
        

Returns:
Database Descriptor Object.
Throws:
DatabaseException - If any error occur while getting database descriptor object.

getDatabaseDescriptor

public static DatabaseDescriptor getDatabaseDescriptor(java.lang.String className)
                                                throws DatabaseException
Throws:
DatabaseException

getDatabaseMappingDescriptor

public DatabaseMappingDescriptor getDatabaseMappingDescriptor()
                                                       throws DatabaseException
Returns the actual database mapping object mapped for invoked class object.

Example:
        DatabaseMapping databaseMapping = null;
        try {
                databaseMapping = new Liquor().getDatabaseMapping();
        } catch(DatabaseException de) {
                //Log it.
        }

                                

                

Returns:
DatabaseMapping Object
Throws:
DatabaseException - If database mapping object not mapped for invoked class object.

getTableName

public java.lang.String getTableName()
                              throws DatabaseException
Returns the mapped table name for invoked class object.

Example:

        String tableName = null;
        try {
                tableName = new Liquor().getTableName();
        } catch(DatabaseException de) {
                //Log it.
        }

        

                

Returns:
Mapped Table name.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getColumnNames

public java.util.Iterator<java.lang.String> getColumnNames()
                                                    throws DatabaseException
Returns all column names of mapped table.

Example:

        Iterator<String> columnNames = null;
        try {
                columnNames = new Liquor().getColumnNames();
        } catch(DatabaseException de) {
                //Log it.
        }

                                
                

Returns:
All column names of mapped table.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getColumnValues

public java.util.Map<java.lang.String,java.lang.Object> getColumnValues()
                                                                 throws DatabaseException
Returns all column values in the same order of column names for invoked class object.

Example:
        Map<String, Object> values = null;
        try {
                values = new Liquor().getColumnValues();
        } catch(DatabaseException de) {
                //Log it.
        }

                
                

Returns:
All column values for invoked object.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getColumnTypes

public java.util.Map<java.lang.String,java.lang.String> getColumnTypes()
                                                                throws DatabaseException
Returns all columns with there data types for invoked class object.

Example:

        Map<String, String> columnTypes = null;
        try {
                columnTypes = new Liquor().getColumnTypes();
        } catch(DatabaseException de) {
                //Log it.
        }	

                        
                

Returns:
All columns with there data types.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getPrimaryKeys

public java.util.Iterator<java.lang.String> getPrimaryKeys()
                                                    throws DatabaseException
Returns all primary keys of mapped table for invoked class object.

Example:

        Iterator<String> primaryKeys = null;
        try {
                primaryKeys = new Liquor().getPrimeryKeys();
        } catch(DatabaseException de) {
                //Log it.
        }

                
                

Returns:
All primary keys.
Throws:
DatabaseException - If not mapped table found for invoked class object.

getMandatoryFields

public java.util.Iterator<java.lang.String> getMandatoryFields()
                                                        throws DatabaseException
Returns all mandatory fields which are associated with mapped table for invoked class object.

Example:

        Iterator<String> mandatoryFields = null;
        try {
                mandatoryFields = new Liquor().getMandatoryFields();
        } catch(DatabaseException de) {
                //Log it.
        }

                                
                

Returns:
All mandatory fields for mapped table.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getUniqueFields

public java.util.Iterator<java.lang.String> getUniqueFields()
                                                     throws DatabaseException
Returns all unique fields which are associated with mapped table for invoked class object.

Example:

        Iterator<String> uniqueFields = null;
        try {
                uniqueFields = new Liquor().getUniqueFields();
        } catch(DatabaseException de) {
                //Log it.
        }

                                
                

Returns:
All unique fields for mapped table.
Throws:
DatabaseException - If no mapped table found for invoked class object.

getForeignKeys

public java.util.Iterator<java.lang.String> getForeignKeys()
                                                    throws DatabaseException
Returns all foreign keys of mapped table for invoked class object.

Example:

        Iterator<String> foreignKeys = null;
        try {
                foreignKeys = new Liquor().getForeignKeys();
        } catch(DatabaseException de) {
                //Log it.
        }

                                

                

Returns:
All foreign keys of mapped table.
Throws:
DatabaseException - If no mapped table found for invoked class object.

Apache License 2.0

Copyright 2013