SICDatabase Class Reference
Inherits from | NSObject |
---|---|
Conforms to | SICIDatabase |
Declared in | SICDatabase.h SICDatabase.m |
Overview
Exposes methods to interact with database. It has methods to create, delete, and perform other common database management tasks.
Other Methods
+ dropDatabase:
It drops the whole database based on database name.
+ (void)dropDatabase:(NSString *)databaseName
Parameters
databaseName |
Entity-Descriptor object which defines the structure of table. |
---|
Discussion
It drops the whole database based on database name.
Drop the book table.
SICDatabaseDescriptor *databaseDescriptor = [[[Book alloc]init] getDatabaseDescriptor];
@try { [SICDatabase dropDatabase:[databaseDescriptor getDatabaseName]]; } @catch(SICDatabaseException *databaseException) { //Log It. }
Declared In
SICDatabase.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 Beer Object
Book *cBook = [[Book alloc] init];
[cBook setTitle:BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuthor: @"c_author"];
[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
SICDatabase.h
+ commitTransaction:
Marks the current transaction as successful.
+ (void)commitTransaction:(SICDatabaseDescriptor *const)databaseDescriptor
Parameters
databaseDescriptor |
Database Descriptor 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 setAuthor: @"c_author"];
[cBook setLink: @"beer_link"];
DatabaseDescriptor *databaseDescriptor = [cBook getDatabaseDescriptor];
@try {
[SICDatabase beginTransaction:databaseDescriptor]; [cBook save]; [SICDatabase commitTransaction:databaseDescriptor]; } @catch(SICDatabaseException *databaseException) { //Log it. } @finally { [SICDatabase endTransaction:databaseDescriptor]; }
Declared In
SICDatabase.h
Protocol Methods
– createTable
Is used to create a new table in an database.
- (void)createTable
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
SICIDatabase.h
– dropTable
It drop’s the table from database based on entity-descriptor.
- (void)dropTable
Discussion
It drop’s the table from database based on entity-descriptor.
Drop the Book table.
Book *book = [[Book alloc] init];
@try {
[book dropTable];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICIDatabase.h
– dropIndex:
Is used to drop a index on a table in database.
- (void)dropIndex:(NSString *)indexName
Parameters
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";
Book *book = [[Book alloc] init];
@try {
[book dropIndex:indexName];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICIDatabase.h
– select
Returns all tuples based on query from mapped table for invoked class object.
- (id<SICISelect>)select
Return Value
SICISelect object.
Discussion
Returns all tuples based on query from mapped table for invoked class object.
Example:
NSArray *books;
@try {
books = [[[[Book alloc] init] select] execute];
} @catch(SICDatabaseException de) {
//Log it.
}
Declared In
SICIDatabase.h
– select:
Returns all tuples based on manual query from mapped table for invoked class object.
- (id)select:(NSString *)query
Parameters
query |
Query to get tuples from database. |
---|
Return Value
SICISelect object.
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:query];
} @catch(SICDatabaseException *de) {
//Log it.
}
Declared In
SICIDatabase.h
– save
It adds a record to any single table in a relational database.
- (void)save
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];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
@try {
[cBook save];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– update
It updates a record to any single table in a relational database.
- (void)update
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: @"beer_link"];
@try {
[cBook update];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.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
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 setHistory: @"c_auditor"];
[cBook setLink: @"c_link"];
@try {
[cBook saveOrUpdate];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– delete
It deletes a record from single table in a relational database.
- (id<SICIDelete>)delete
Discussion
It deletes a record from 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 delete];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– count
Returns the count of rows based on where clause provided.
- (id<SICICount>)count
Discussion
Returns the count of rows based on where clause provided.
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"];
int noOfBooks = 0;
@try {
noOfBooks = [[cBook count] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– avg
Returns the average based on where clause provided.
- (id<SICIAverage>)avg
Discussion
Returns the average based on where clause provided.
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"];
int noOfBooks = 0;
@try {
noOfBooks = [[beer avg] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– sum
Returns the sum based on where clause provided.
- (id<SICISum>)sum
Discussion
Returns the sum based on where clause provided.
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"];
int noOfBooks = 0;
@try {
noOfBooks = [[cBook sum] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– total
Returns the total based on where clause provided.
- (id<SICITotal>)total
Discussion
Returns the total based on where clause provided.
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"];
int totalBooks = 0;
@try {
totalBooks = [[cBook avg] execute];
}
@catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– min
Returns the min based on where clause provided.
- (id<SICIMin>)min
Discussion
Returns the min based on where clause provided.
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"];
int minBooks = 0;
@try {
minBooks = [[cBook min] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– max
Returns the max based on where clause provided.
- (id<SICIMax>)max
Discussion
Returns the max based on where clause provided.
Example: Make Beer Object
Book *cBook = [[Book alloc] init];
[cBook setTitle: Book.BOOK_TYPE_C];
[cBook setDescription: @"c_description"];
[cBook setAuditor: @"c_auditor"];
[cBook setLink: @"c_link"];
int maxBooks = 0;
@try {
maxBooks = [[cBook max] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– groupConcat
Returns the group concat based on where clause provided.
- (id<SICIGroupConcat>)groupConcat
Discussion
Returns the group concat based on where clause provided.
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"];
int groupConcatBooks = 0;
@try {
groupConcatBooks = [[cBook groupConcat] execute];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– getDatabaseDescriptor
Returns database descriptor object based on the mapped class called.
- (SICDatabaseDescriptor *)getDatabaseDescriptor
Return Value
Database Descriptor Object.
Discussion
Returns database descriptor object based on the mapped class called.
Example:
@try {
SICDatabaseDescriptor *databaseDescriptor = [[[Book alloc] init] getDatabaseDescriptor];
} @catch(SICDatabaseException *databaseException) {
//Log It.
}
Declared In
SICIDatabase.h
– getEntityDescriptor
Returns the actual entity descriptor object mapped for invoked class object.
- (SICEntityDescriptor *)getEntityDescriptor
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
SICIDatabase.h
– getTableName
Returns the mapped table name for invoked class object.
- (NSString *)getTableName
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
SICIDatabase.h
– getColumnNames
Returns all column names of mapped table.
- (NSEnumerator *)getColumnNames
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
SICIDatabase.h
– getColumnValues
Returns all column values in the same order of column names for invoked class object.
- (NSDictionary *)getColumnValues
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:
NSDictionary *values = nil;
@try {
values = [[[Book alloc] init] getColumnValues];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– getColumnTypes
Returns all columns with there data types for invoked class object.
- (NSDictionary *)getColumnTypes
Return Value
All columns with there data types.
Discussion
Returns all columns with there data types for invoked class object.
Example:
NSDictionary columnTypes = nil; @try { columnTypes = [[[Book alloc] init] getColumnTypes]; } @catch(SICDatabaseException databaseException) { //Log it. }
Declared In
SICIDatabase.h
– getPrimaryKeys
Returns all primary keys of mapped table for invoked class object.
- (NSEnumerator *)getPrimaryKeys
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] getPrimaryKeys];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– getMandatoryFields
Returns all mandatory fields which are associated with mapped table for invoked class object.
- (NSEnumerator *)getMandatoryFields
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 = nil;
@try {
mandatoryFields = [[[Book alloc] init] getMandatoryFields];
} @catch(SICDatabaseException *databaseException) {
//Log it.
}
Declared In
SICIDatabase.h
– getUniqueFields
Returns all unique fields which are associated with mapped table for invoked class object.
- (NSEnumerator *)getUniqueFields
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
SICIDatabase.h
– getForeignKeys
Returns all foreign keys of mapped table for invoked class object.
- (NSEnumerator *)getForeignKeys
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
SICIDatabase.h