Database Manager Action pack all data and settings to perform some database operation. More...
#import <JPDBManagerAction.h>
Properties | |
NSString * | entity |
The entity to perform this action. | |
NSString * | fetchTemplate |
The Fetch Template to perform this action. | |
NSMutableDictionary * | variablesListAndValues |
Values to replace on the pre formatted Fetch Template. | |
NSMutableArray * | sortDescriptors |
Array of Sort Descriptors (NSSortDescriptor) to sort the result of this acion. | |
JPDBManager * | manager |
Instance of the Manager to perform this Database Action. | |
BOOL | commitTransaction |
Set if the Manager should commit this transaction immediatelly or not. | |
BOOL | returnObjectsAsFault |
Define if the Result objects of some query should be as Core Data Fault. | |
BOOL | ascendingOrder |
Define if the order of the results of some query should be Ascending or Descending. | |
BOOL | returnActionAsArray |
Set if the Result of this action should be an NSArray or an NSFetchedResultsController object. | |
Init Methods | |
(id) | + initWithManager: |
Init with an Database Manager to process this Database Action. | |
(id) | - initWithManager: |
Init with an Database Manager to process this Database Action. | |
Set Query Limits | |
int | startFetchInLine |
Set the initial row result to return from Query Methods results. | |
int | limitFetchResults |
Set the maximum rows to return from Query Methods results. | |
(void) | - setStartFetchInLine:setLimitFetchResults: |
Convenient method to set the startFetchInLine and limitFetchResults properties at the same time. | |
(void) | - resetFetchLimits |
Reset the default Fetch Limits values. | |
(void) | - resetDefaultValues |
Reset this Action Settings to default values. | |
Action Data Methods | |
(id) | - applyEntity: |
Set an Entity to perform this action. | |
(id) | - applyFetchTemplate: |
Set an Fetch Template name to perform this action. | |
(id) | - applyFetchReplaceWithDictionary: |
Set the Values to replace on the pre formatted Fetch Template. | |
(id) | - applyFetchReplaceWithVariables: |
Set the Values to replace on the pre formatted Fetch Template. | |
(id) | - applyPredicate: |
(id) | - runAction |
Run this action on the associated JPDBManager Database Manager. | |
Order Keys Methods | |
(id) | - applyArrayOfSortDescriptors: |
Set the Key attributes to sort the result of this acion. | |
(id) | - applyOrderKeys: |
Set the Key attributes to sort the result of this acion. | |
(id) | - applyOrderKey: |
Set the Key attribute to sort the result of this acion. | |
(id) | - addOrderKey: |
Add a new Key attribute to sort the result of this action. | |
(void) | - removeOrderKey: |
Remove an Key attribute from the sorter list. | |
Query All Data Methods | |
(id) | - queryAllDataFromEntity: |
Query all data of the specified Entity. | |
(id) | - queryAllDataFromEntity:orderWithKey: |
Query all data of the specified Entity. | |
(id) | - queryAllDataFromEntity:orderWithKeys: |
Query all data of the specified Entity. | |
Query Data With Fetch Templates Methods | |
(id) | - queryEntity:withFetchTemplate: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:orderWithKey: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:orderWithKeys: |
Query specified Entity using one specified Fetch Template name. | |
Query Data With Fetch Templates and Fetch Parameters Methods | |
(id) | - queryEntity:withFetchTemplate:withVariables: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:orderWithKey:withVariables: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:replaceFetchWithDictionary: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:replaceFetchWithDictionary:orderWithKey: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:replaceFetchWithDictionary:orderWithKeys: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:replaceFetchWithDictionary:arrayOfSortDescriptors: |
Query specified Entity using one specified Fetch Template name. | |
(id) | - queryEntity:withFetchTemplate:replaceFetchWithDictionary:arrayOfSortDescriptors:customPredicate: |
Query Data Methods With Custom Predicates | |
(id) | - queryEntity:withPredicate: |
Query specified Entity using one custom NSPredicate Object. | |
(id) | - queryEntity:withPredicate:orderWithKey: |
Query specified Entity using one custom NSPredicate Object. | |
(id) | - queryEntity:withPredicate:orderWithKeys: |
Query specified Entity using one custom NSPredicate Object. | |
(id) | - queryEntity:withPredicate:arrayOfSortDescriptors: |
Query specified Entity using one custom NSPredicate Object. | |
Remove Data Methods | |
(void) | - deleteRecord: |
Delete specified Record from his Entity on the Database. | |
(void) | - deleteRecord:andCommit: |
Delete specified Record from his Entity on the Database. | |
(void) | - deleteRecordsFromEntity:withFetchTemplate: |
Delete all records queried by the specified Fetch Template. | |
(void) | - deleteAllRecordsFromEntity: |
Delete all Records from specified Entity. | |
Write Data Methods | |
(id) | - createNewRecordForEntity: |
Create and return a new record for specified Entity. |
Database Manager Action pack all data and settings to perform some database operation.
Database operations isn't called directy to the manager. Instead we create one instance of the JPDBManagerAction class, configure the data and settings to perform some CRUD operation and finally run this action. Yes, looks like a lot of work, but actually is not. Let's see some examples:
id newRecord = [JPDatabaseManager createNewRecordForEntity:@"MyEntity"];
This is was really simple, isn't? Let's see this same operation on a more custom fashion:
JPDBManagerAction *anAction = [[JPDBManagerSingleton sharedInstance] getDatabaseAction]; [anAction setCommitTransaction:YES]; id newRecord = [anAction createNewRecordForEntity:@"MyEntity"];
Well this looks a litle bit more complicated. Let's understand this two processes: The first one uses the JPDatabaseManager convenient macro shortcut that returns an JPDBManagerAction instance and perform this method in only one pass, is pure convenience. This macro is declared in the JPDBManagerDefinitions.h file.
The second way needs more steps, but you should use that way when you need more control of the all process, for example, you can configure if you want to automatically commit the operation or create some more dinamically code on your database operations.
+ (id) initWithManager: | (JPDBManager*) | anManager |
Init with an Database Manager to process this Database Action.
anManager | An Database Manager An autoreleseable instance. |
- (id) initWithManager: | (JPDBManager *) | anManager |
Init with an Database Manager to process this Database Action.
anManager | An Database Manager An retained instance. |
- (id) applyEntity: | (NSString*) | anEntity |
Set an Entity to perform this action.
anEntityName | The Entity Name. |
- (id) applyFetchTemplate: | (NSString*) | anFetchTemplate |
Set an Fetch Template name to perform this action.
anFetchRequest | An Fetch Template to perform the query. |
- (id) applyFetchReplaceWithDictionary: | (NSDictionary*) | anDictionary |
Set the Values to replace on the pre formatted Fetch Template.
anDictionary | An Dictionary with Keys and Values to replace on the pre formatted Fetch Template |
- (id) applyFetchReplaceWithVariables: | (id) | variableList | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Set the Values to replace on the pre formatted Fetch Template.
variableList | Keys and Values to replace on the pre formatted Fetch Template. Example: [anAction applyFetchReplaceWithVariables:@"value1", @"key1", @"value2", @"key2", nil]; |
- (id) applyArrayOfSortDescriptors: | (NSArray*) | anArray |
Set the Key attributes to sort the result of this acion.
anArrayOfSortDescriptors | An Array with defined NSSortDescriptors to sort the result. |
An | JPDBManagerActionException exception if the array contains an objects that doesn't is an NSSortDescriptors. See Handling Errors for more informations. |
- (id) applyOrderKeys: | (id) | listOfKeys | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Set the Key attributes to sort the result of this acion.
listOfKeys | Accept one or more Key Attributes to sort the result. Doesn't forget to terminate the list with an 'nil' token. |
An | JPDBManagerActionException exception if the entity property isn't defined. See Handling Errors for more informations. |
- (id) applyOrderKey: | (id) | anKey |
Set the Key attribute to sort the result of this acion.
anKey | An Key Attribute to sort the result. |
An | JPDBManagerActionException exception if the entity property isn't defined. See Handling Errors for more informations. |
- (id) addOrderKey: | (id) | anKey |
Add a new Key attribute to sort the result of this action.
anKey | An Key Attribute to sort the result. |
An | JPDBManagerActionException exception if the entity property isn't defined. See Handling Errors for more informations. |
- (void) removeOrderKey: | (id) | anKey |
Remove an Key attribute from the sorter list.
anKey | An Key Attribute to remove. |
- (id) queryAllDataFromEntity: | (NSString*) | anEntityName |
Query all data of the specified Entity.
anEntityName | The Entity Name. |
- (id) queryAllDataFromEntity: | (NSString*) | anEntityName | |
orderWithKey: | (id) | anKey | |
Query all data of the specified Entity.
The #defaultOrderIsAscending property determines if is an Ascending or Descending order.
anEntityName | The Entity Name. |
anKey | One Key attribute to sort the result. |
- (id) queryAllDataFromEntity: | (NSString*) | anEntityName | |
orderWithKeys: | (id) | listOfKeys | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query all data of the specified Entity.
anEntityName | The Entity Name. |
listOfKeys | Accept one or more Key Attributes to sort the result. Doesn't forget to terminate the list with an 'nil' token. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
orderWithKey: | (id) | anKey | |
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
anKey | One Key attribute to sort the result. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
orderWithKeys: | (id) | listOfKeys | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
listOfKeys | Accept one or more Key Attributes to sort the result. Doesn't forget to terminate the list with an 'nil' token. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
withVariables: | (id) | variableList | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
variableList | Keys and Values to replace on the pre formatted Fetch Template. Example: [manager queryEntity:@"Entity" withFetchTemplate:@"FetchAll" withVariables:@"value1", @"key1", @"value2", @"key2", nil]; |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
orderWithKey: | (id) | anKey | |
withVariables: | (id) | variableList | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
anKey | One Key attribute to sort the result. |
variableList | Keys and Values to replace on the pre formatted Fetch Template. Example: [manager queryEntity:@"Entity" withFetchTemplate:@"FetchAll" orderWithKey:@"id" withVariables:@"value1", @"key1", @"value2", @"key2", nil]; |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
replaceFetchWithDictionary: | (NSDictionary*) | variablesListAndValues | |
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
variablesListAndValues | An Dictionary with Keys and Values to replace on the pre formatted Fetch Template. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
replaceFetchWithDictionary: | (NSDictionary*) | variablesListAndValues | |
orderWithKey: | (id) | anKey | |
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
variablesListAndValues | An Dictionary with Keys and Values to replace on the pre formatted Fetch Template. |
anKey | One Key attribute to sort the result. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
replaceFetchWithDictionary: | (NSDictionary*) | variablesListAndValues | |
orderWithKeys: | (id) | listOfKeys | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
variablesListAndValues | An Dictionary with Keys and Values to replace on the pre formatted Fetch Template. |
listOfKeys | Accept one or more Key Attributes to sort the result. Doesn't forget to terminate the list with an 'nil' token. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
replaceFetchWithDictionary: | (NSDictionary*) | variablesListAndValues | |
arrayOfSortDescriptors: | (NSArray*) | anArrayOfSortDescriptors | |
Query specified Entity using one specified Fetch Template name.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
variablesListAndValues | An Dictionary with Keys and Values to replace on the pre formatted Fetch Template. |
anArrayOfSortDescriptors | An Array of Key attributes to sort the result. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withPredicate: | (NSPredicate*) | anPredicate | |
Query specified Entity using one custom NSPredicate Object.
anEntityName | The Entity Name. @ |
anPredicate | An NSPredicate object defining the query. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withPredicate: | (NSPredicate*) | anPredicate | |
orderWithKey: | (id) | anKey | |
Query specified Entity using one custom NSPredicate Object.
anEntityName | The Entity Name. |
anPredicate | An NSPredicate object defining the query. |
anKey | One Key attribute to sort the result. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withPredicate: | (NSPredicate*) | anPredicate | |
orderWithKeys: | (id) | listOfKeys | |
, | NS_REQUIRES_NIL_TERMINATION | ||
Query specified Entity using one custom NSPredicate Object.
anEntityName | The Entity Name. |
anPredicate | An NSPredicate object defining the query. |
listOfKeys | Accept one or more Key Attributes to sort the result. Doesn't forget to terminate the list with an 'nil' token. |
- (id) queryEntity: | (NSString*) | anEntityName | |
withPredicate: | (NSPredicate*) | anPredicate | |
arrayOfSortDescriptors: | (NSArray*) | anArrayOfSortDescriptors | |
Query specified Entity using one custom NSPredicate Object.
anEntityName | The Entity Name. |
anPredicate | An NSPredicate object defining the query. |
anArrayOfSortDescriptors | An Array of Key attributes to sort the result. |
- (void) deleteRecord: | (id) | anObject |
Delete specified Record from his Entity on the Database.
This method will use the commitTransaction property to decide if commit automatically this change.
anObject | Record object to delete. |
- (void) deleteRecord: | (id) | anObject | |
andCommit: | (BOOL) | commit | |
Delete specified Record from his Entity on the Database.
anObject | Record object to delete. |
commit | Specify if you want to commit or not this operation immediattelly. |
- (void) deleteRecordsFromEntity: | (NSString*) | anEntityName | |
withFetchTemplate: | (NSString*) | anFetchName | |
Delete all records queried by the specified Fetch Template.
This method will use the commitTransaction property to decide if commit automatically this change.
anEntityName | The Entity Name. |
anFetchName | An Fetch Template to perform the query. |
- (void) deleteAllRecordsFromEntity: | (NSString*) | anEntityName |
Delete all Records from specified Entity.
This could be a consuming operation on large databases.
anEntityName | The Entity Name. |
- (id) createNewRecordForEntity: | (NSString*) | anEntityName |
Create and return a new record for specified Entity.
anEntityName | The Entity Name. |
- (BOOL) commitTransaction [read, write, assign] |
Set if the Manager should commit this transaction immediatelly or not.
Default value is NO.
- (BOOL) returnObjectsAsFault [read, write, assign] |
Define if the Result objects of some query should be as Core Data Fault.
Default value is NO.
- (BOOL) ascendingOrder [read, write, assign] |
Define if the order of the results of some query should be Ascending or Descending.
Note that by performance you should set this value before apply any Key sort attribute. You can do it after, but the manager will recreate every sort key again. Default value is YES.
- (BOOL) returnActionAsArray [read, write, assign] |
Set if the Result of this action should be an NSArray or an NSFetchedResultsController object.
Default value is YES.
- (int) startFetchInLine [read, write, assign] |
Set the initial row result to return from Query Methods results.
Combine this set with the limitFetchResults property.
Default value is 0.
- (int) limitFetchResults [read, write, assign] |
Set the maximum rows to return from Query Methods results.
Combine this set with the startFetchInLine property.
Default value is 0, it means that all rows in the Entity will be retrieved.