SICDatabaseHelper Class Reference
Inherits from | NSObject |
---|---|
Declared in | SICDatabaseHelper.h SICDatabaseHelper.m |
Overview
It provides utility methods to deal with database. It has methods to create, delete, and perform other common database management tasks.
+ createDatabase:
It is used to create instance of SICIDatabase implementation.
+ (SICDatabaseBundle *)createDatabase:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
Database Descriptor object to create database. |
---|
Return Value
SICDatabaseBundle Database Bundle instance object.
Discussion
It is used to create instance of SICIDatabase implementation.
Declared In
SICDatabaseHelper.h
+ dropDatabase:
It drops the whole database based on database-descriptor.
+ (void)dropDatabase:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
Entity Descriptor object which defines the structure of table. |
---|
Discussion
It drops the whole database based on database-descriptor.
Drop the book table.
SICDatabaseDescriptor *databaseDescriptor = [[[Book alloc] init] getDatabaseDescriptor];
@try {
[SICDatabase dropDatabase:databaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ upgradeDatabase:
Upgrade Existing Database.
+ (void)upgradeDatabase:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
Database Descriptor object. |
---|
Discussion
Upgrade Existing Database.
Declared In
SICDatabaseHelper.h
+ upgradeTable:
Upgrade Table.
+ (void)upgradeTable:(SICEntityDescriptor *)entityDescriptor
Parameters
entityDescriptor |
object related to table. |
---|
Discussion
Upgrade Table.
Exceptions
DatabaseException |
If any exception thrown while upgrading table. |
---|
Declared In
SICDatabaseHelper.h
+ createTables:
Is used to create a new table in an database.
+ (void)createTables:(NSEnumerator *)entityDescriptors
Parameters
entityDescriptors |
Entity Descriptor objects which defines the structure of each table. |
---|
Discussion
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 ENTITY-DESCRIPTOR XML file. And creation of table will be handled by SIMINOV.
SIMINOV will parse each ENTITY-DESCRIPTOR XML defined by developer and create table’s in database.
Example:
<!-- Design Of EntityDescriptor.xml -->
<entity-descriptor>
<!-- General Properties Of Table And Class -->
<!-- Mandatory Field -->
<!-- NAME OF TABLE -->
<property name="table_name">name_of_table</property>
<!-- Mandatory Field -->
<!-- MAPPED CLASS NAME -->
<property name="class_name">mapped_class_name</property>
<!-- Optional Field -->
<attributes>
<!-- Column Properties Required Under This Table -->
<!-- Optional Field -->
<attribute>
<!-- Mandatory Field -->
<!-- COLUMN_NAME: Mandatory Field -->
<property name="column_name">column_name_of_table</property>
<!-- Mandatory Field -->
<!-- VARIABLE_NAME: Mandatory Field -->
<property name="variable_name">class_variable_name</property>
<!-- Mandatory Field -->
<property name="type">java_variable_data_type</property>
<!-- Optional Field (Default is false) -->
<property name="primary_key">true/false</property>
<!-- Optional Field (Default is false) -->
<property name="not_null">true/false</property>
<!-- Optional Field (Default is false) -->
<property name="unique">true/false</property>
<!-- Optional Field -->
<property name="check">condition_to_be_checked (Eg: variable_name 'condition' value; variable_name > 0)</property>
<!-- Optional Field -->
<property name="default">default_value_of_column (Eg: 0.1)</property>
</attribute>
</attributes>
<!-- Optional Field -->
<indexes>
<!-- Index Properties -->
<index>
<!-- Mandatory Field -->
<!-- NAME OF INDEX -->
<property name="name">name_of_index</property>
<!-- Mandatory Field -->
<!-- UNIQUE: Optional Field (Default is false) -->
<property name="unique">true/false</property>
<!-- Optional Field -->
<!-- Name of the column -->
<property name="column">column_name_needs_to_add</property>
</index>
</indexes>
<!-- Map Relationship Properties -->
<!-- Optional Field's -->
<relationships>
<relationship>
<!-- Mandatory Field -->
<!-- Type of Relationship -->
<property name="type">one-to-one|one-to-many|many-to-one|many-to-many</property>
<!-- Mandatory Field -->
<!-- REFER -->
<property name="refer">class_variable_name</property>
<!-- Mandatory Field -->
<!-- REFER TO -->
<property name="refer_to">map_to_class_name</property>
<!-- Optional Field -->
<property name="on_update">cascade/restrict/no_action/set_null/set_default</property>
<!-- Optional Field -->
<property name="on_delete">cascade/restrict/no_action/set_null/set_default</property>
<!-- Optional Field (Default is false) -->
<property name="load">true/false</property>
</relationship>
</relationships>
</entity-descriptor>
Declared In
SICDatabaseHelper.h
+ createTable:
Is used to create a new table in an database.
+ (void)createTable:(SICEntityDescriptor *const)entityDescriptor
Parameters
entityDescriptor |
Entity Descriptor object which defines the structure of table. |
---|
Discussion
Is used to create a new table in an database.
Manually creating table structure using Entity Descriptor mapped class.
Example:
Book *book = [[Book alloc] init];
@try {
[SICDatabase createTables:[book getEntityDescriptor]];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ dropTable:
It drops the table from database based on entity descriptor.
+ (void)dropTable:(SICEntityDescriptor *const)entityDescriptor
Parameters
entityDescriptor |
Entity Descriptor object which defines the structure of table. |
---|
Discussion
It drops the table from database based on entity descriptor.
Drop the book table.
EntityDescriptor *entityDescriptor = [[[Book alloc] init] getEntityDescriptor];
@try {
[SICDatabase dropTable:entityDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ createIndexBasedonIndexObject:index:
Is used to create a new index on a table in database.
+ (void)createIndexBasedonIndexObject:(SICEntityDescriptor *const)entityDescriptor index:(SICIndex *const)index
Parameters
entityDescriptor |
Entity Descriptor object which defines the structure of table. |
---|---|
index |
Index object which defines the structure of index needs to create. |
Discussion
Is used to create a new index on a table in database.
Create Index On book table.
Index *indexOnBook = [[Index alloc] init];
[indexOnBook setName: @"BOOK_INDEX_BASED_ON_AUDITOR"];
[indexOnBook setUnique: true];
//Add Columns on which we need index.
[indexOnBook addColumn: @"LINK"];
SICEntityDescriptor *entityDescriptor = [[[Book alloc] init] getEntityDescriptor];
@try {
[SICDatabase createIndexBasedonIndexObject:entityDescriptor index:indexOnBook);
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ createIndex:indexName:columnNames:isUnique:
Is used to create a new index on a table in database.
+ (void)createIndex:(SICEntityDescriptor *const)entityDescriptor indexName:(id)indexName columnNames:(NSEnumerator *)columnNames isUnique:(bool const)isUnique
Parameters
entityDescriptor |
Entity Descriptor object which defines the structure of table. |
---|---|
indexName |
Name of index. |
columnNames |
Iterator over column names. |
isUnique |
true/false whether index needs to be unique or not. (A unique index guarantees that the index key contains no duplicate values and therefore every row in the table is in some way unique.) |
Discussion
Is used to create a new index on a table in database.
Create Index On book table.
NSString *indexName = @"BOOK_INDEX_BASED_ON_AUDITOR";
BOOL isUnique = true;
NSMutableArray *columnNames = [NSMutableArray alloc] init];
[columnNames add:@"LINK"];
@try {
[[Book alloc] init] createIndex;
new Book().createIndex(indexName, columnNames.iterator(), isUnique);
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ dropIndex:indexName:
Is used to drop a index on a table in database.
+ (void)dropIndex:(SICEntityDescriptor *const)entityDescriptor indexName:(NSString *const)indexName
Parameters
entityDescriptor |
Entity Descriptor object which defines the structure of table. |
---|---|
indexName |
Name of a index needs to be drop. |
Discussion
Is used to drop a index on a table in database.
Create Index On Book table.
NSString *indexName = @"BOOK_INDEX_BASED_ON_AUDITOR";
SICEntityDescriptor *entityDescriptor = [[[Book alloc] init] getEntityDescriptor];
@try {
[SICDatabase dropIndex:entityDescriptor indexName:indexName];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ beginTransaction:
Begins a transaction in EXCLUSIVE mode.
+ (void)beginTransaction:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
DatabaseDescriptor object. |
---|
Discussion
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 Book Object
Book *cBook = [[Book alloc] init];
[cBook setTitle:BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
SICDatabaseDescriptor *databaseDescriptor = [cBook getDatabaseDescriptor];
@try {
[SICDatabase beginTransaction:databaseDescriptor];
[cBook save];
[SICDatabase commitTransaction:databaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log it.
} @finally {
[SICDatabase endTransaction: atabaseDescriptor];
}
Declared In
SICDatabaseHelper.h
+ commitTransaction:
Marks the current transaction as successful.
+ (void)commitTransaction:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
DatabaseDescriptor object. |
---|
Discussion
Marks the current transaction as successful.
Finally it will End a transaction.
Example: Make Beer Object
Book *cBook = [[Book alloc] init];
[cBook setTitle:BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
SICDatabaseDescriptor *databaseDescriptor = [cBook getDatabaseDescriptor];
@try {
[SICDatabase beginTransaction: databaseDescriptor];
[cBook save];
[SICDatabase commitTransaction: databaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log it.
} @finally {
[SICDatabase endTransaction: databaseDescriptor];
}
Declared In
SICDatabaseHelper.h
+ select:query:
Returns all tuples based on manual query from mapped table for invoked class object.
+ (id)select:(id const)object query:(NSString *const)query
Parameters
object |
Class object. |
---|---|
query |
Manual query on which tuples need to be fetched. |
Return Value
Array Of Objects.
Discussion
Returns all tuples based on manual query from mapped table for invoked class object.
Example:
NSString *query = @"SELECT * FROM BOOK";
NSArray *books;
@try {
books = [[[[Book alloc] init] select] execute];
} @catch(SICDatabaseException *de) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ save:
It adds a record to any single table in a relational database.
+ (void)save:(id const)object
Parameters
object |
Class object. |
---|
Discussion
It adds a record to any single table in a relational database.
Example: Make Book Object
Book *cBook = [[Book alloc] init];
[cBook setTitle: BOOK_TYPE_C];
[beer setDescription: @"c_description"];
[beer setAuditor: @"c_auditor"];
[beer setLink: @"beer_link"];
@try {
[cBook save];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ update:
It updates a record to any single table in a relational database.
Example: Make Beer Object
+ (void)update:(id const)object
Parameters
object |
Class object. |
---|
Discussion
It updates a record to any single table in a relational database.
Example: Make Beer Object
Book *cBook = [[Book alloc] init];
[cBook setTitle:BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
@try {
[cBook update];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ saveOrUpdate:
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.
+ (void)saveOrUpdate:(id const)object
Parameters
object |
Class object. |
---|
Discussion
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
Book *cBook = [[Book alloc] init];
[cBook setTitle:BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
@try {
[cBook saveOrUpdate];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getDatabaseDescriptor:
Returns database descriptor object based on the POJO class called.
+ (SICDatabaseDescriptor *)getDatabaseDescriptor:(NSString *const)className
Parameters
className |
Name of class. |
---|
Return Value
Database Descriptor Object.
Discussion
Returns database descriptor object based on the POJO class called.
Example:
@try {
SICDatabaseDescriptor *databaseDescriptor = [[[Book alloc] init] getDatabaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICDatabaseHelper.h
+ getEntityDescriptor:
Returns the actual entity descriptor object mapped for invoked class object.
+ (SICEntityDescriptor *)getEntityDescriptor:(NSString *const)className
Parameters
className |
Name of class. |
---|
Return Value
Entity Descriptor Object
Discussion
Returns the actual entity descriptor object mapped for invoked class object.
Example:
SICEntityDescriptor *entityDescriptor = nil;
@try {
entityDescriptor = [[[Book alloc] init] getEntityDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getTableName:
Returns the mapped table name for invoked class object.
+ (NSString *)getTableName:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
Mapped Table name.
Discussion
Returns the mapped table name for invoked class object.
Example:
NSString *tableName = nil;
@try {
tableName = [[[Book alloc] init] getTableName];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getColumnNames:
Returns all column names of mapped table.
+ (NSEnumerator *)getColumnNames:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All column names of mapped table.
Discussion
Returns all column names of mapped table.
Example:
NSEnumerator *columnNames = nil;
@try {
columnNames = [[[Book alloc] init] getColumnNames];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getColumnValues:
Returns all column values in the same order of column names for invoked class object.
+ (NSMutableDictionary *)getColumnValues:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All column values for invoked object.
Discussion
Returns all column values in the same order of column names for invoked class object.
Example:
NSMutableDictionary *values = nil;
@try {
values = [[[Book alloc] init] getColumnValues];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getColumnTypes:
Returns all columns with there data types for invoked class object.
+ (NSMutableDictionary *)getColumnTypes:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All columns with there data types.
Discussion
Returns all columns with there data types for invoked class object.
Example:
NSMutableDictionary *columnTypes = nil;
@try {
columnTypes = [[[Book alloc] init] getColumnTypes];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getPrimaryKeys:
Returns all primary keys of mapped table for invoked class object.
+ (NSEnumerator *)getPrimaryKeys:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All primary keys.
Discussion
Returns all primary keys of mapped table for invoked class object.
Example:
NSEnumerator *primaryKeys = nil;
@try {
primaryKeys = [[[Book alloc] init] getPrimeryKeys();
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getMandatoryFields:
Returns all mandatory fields which are associated with mapped table for invoked class object.
+ (NSEnumerator *)getMandatoryFields:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All mandatory fields for mapped table.
Discussion
Returns all mandatory fields which are associated with mapped table for invoked class object.
Example:
NSEnumerator *mandatoryFields = null;
@try {
mandatoryFields = [[[Book alloc] init] getMandatoryFields];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getUniqueFields:
Returns all unique fields which are associated with mapped table for invoked class object.
+ (NSEnumerator *)getUniqueFields:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All unique fields for mapped table.
Discussion
Returns all unique fields which are associated with mapped table for invoked class object.
Example:
NSEnumerator *uniqueFields = null;
@try {
uniqueFields = [[[Book alloc] init] getUniqueFields];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ getForeignKeys:
Returns all foreign keys of mapped table for invoked class object.
+ (NSEnumerator *)getForeignKeys:(id const)object
Parameters
object |
Object of class. |
---|
Return Value
All foreign keys of mapped table.
Discussion
Returns all foreign keys of mapped table for invoked class object.
Example:
NSEnumerator *foreignKeys = nil;
@try {
foreignKeys = [[[Book alloc] init] getForeignKeys];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICDatabaseHelper.h
+ parseAndInflateData:parentObject:entityDescriptor:values:
Iterates the provided cursor, and returns tuples in form of actual objects.
+ (NSEnumerator *)parseAndInflateData:(id const)object parentObject:(id)parentObject entityDescriptor:(SICEntityDescriptor *const)entityDescriptor values:(NSEnumerator *const)values
Parameters
entityDescriptor |
object related to table. |
---|---|
values |
Values to parse. |
Discussion
Iterates the provided cursor, and returns tuples in form of actual objects.
Declared In
SICDatabaseHelper.h