Skip to content

Commit

Permalink
This adds a way to specify the select part of the query. This is
Browse files Browse the repository at this point in the history
necessary when you need better performance than the current lazy loading
api.  The select simply prepopulates the readCache.   So to use:

1) [ARBase setEnableCache:YES];

2) Then call one of these new methods with the select parameter.
  • Loading branch information
face committed Jan 16, 2009
1 parent 40f281f commit 941653d
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 6 deletions.
59 changes: 58 additions & 1 deletion Source/ARBase+Finders.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
+ (NSArray *)find:(ARFindSpecification)idOrSpecification;
/*! Finds a record based on the find specification, filter and limit using the specified connection.
* @param idOrSpecification The find specification
* @param limit The maximum number of records to retrieve
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification select:(NSString *)selectSQL;
/*! Finds a record based on the find specification, select, filter and limit using the specified connection.
* @param idOrSpecification The find specification
* @param selectSQL A valid SQL SELECT statement (omitting the actual "SELECT")
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification connection:(id<ARConnection>)connection;
/*! Finds a record based on the find specification, filter and limit.
Expand All @@ -52,6 +56,14 @@
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification select:(NSString *)selectSQL connection:(id<ARConnection>)connection;
/*! Finds a record based on the find specification, filter and limit.
* @param idOrSpecification The find specification
* @param selectSQL A valid SQL SELECT statement (omitting the actual "SELECT")
* @param whereSQL A valid SQL WHERE statement (omitting the actual "WHERE")
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
Expand All @@ -64,22 +76,67 @@
* @param limit The maximum number of records to retrieve
* @param connection The connection to use for the record. (Pass nil to use the default connection)
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit;
/*! Finds a record based on the find specification, filter and limit using the specified connection.
* @param idOrSpecification The find specification
* @param whereSQL A valid SQL WHERE statement (omitting the actual "WHERE")
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
* @param connection The connection to use for the record. (Pass nil to use the default connection)
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection;
/*! Finds a record based on the find specification, filter and limit using the specified connection.
* @param idOrSpecification The find specification
* @param selectSQL A valid SQL SELECT statement (omitting the actual "SELECT")
* @param whereSQL A valid SQL WHERE statement (omitting the actual "WHERE")
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
* @param connection The connection to use for the record. (Pass nil to use the default connection)
*/
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection;
/*! Finds ids of records matching the find specification, filter and limit using the specified connection.\n
* You generally won't need to use this method, but it can be useful in cases where you just want to know for example\n
* The number of records matching.
* @param idOrSpecification The find specification
* @param whereSQL A valid SQL WHERE statement (omitting the actual "WHERE")
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
* @param connection The connection to use for the record. (Pass nil to use the default connection)
*/
+ (NSArray *)findIds:(ARFindSpecification)idOrSpecification
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection;
/*! Finds ids of records matching the find specification, filter and limit using the specified connection.\n
* You generally won't need to use this method, but it can be useful in cases where you just want to know for example\n
* The number of records matching.
* @param idOrSpecification The find specification
* @param selectSQL A valid SQL SELECT statement (omitting the actual "SELECT")
* @param whereSQL A valid SQL WHERE statement (omitting the actual "WHERE")
* @param orderSQL A valud SQL ORDER statement (omitting the actual "ORDER BY")
* @param limit The maximum number of records to retrieve
* @param connection The connection to use for the record. (Pass nil to use the default connection)
*/
+ (NSArray *)findIds:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
Expand Down
82 changes: 77 additions & 5 deletions Source/ARBase+Finders.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,55 @@ + (NSArray *)find:(ARFindSpecification)idOrSpecification
return [self find:idOrSpecification
connection:[self defaultConnection]];
}
+ (NSArray *)find:(ARFindSpecification)idOrSpecification connection:(id<ARConnection>)connection
+ (NSArray *)find:(ARFindSpecification)idOrSpecification select:(NSString *)selectSQL
{
return [self find:idOrSpecification
select:selectSQL
connection:[self defaultConnection]];
}
+ (NSArray *)find:(ARFindSpecification)idOrSpecification connection:(id<ARConnection>)aConnection
{
return [self find:idOrSpecification
select:@"id"
filter:nil
join:nil
order:nil
limit:0
connection:connection];
connection:aConnection];
}
+ (NSArray *)find:(ARFindSpecification)idOrSpecification select:(NSString *)selectSQL connection:(id<ARConnection>)aConnection
{
return [self find:idOrSpecification
select:selectSQL
filter:nil
join:nil
order:nil
limit:0
connection:aConnection];
}
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
{
return [self find:idOrSpecification
select:@"id"
filter:whereSQL
join:joinSQL
order:orderSQL
limit:limit
connection:[self defaultConnection]];
}

+ (NSArray *)find:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
{
return [self find:idOrSpecification
select:selectSQL
filter:whereSQL
join:joinSQL
order:orderSQL
Expand All @@ -44,8 +76,25 @@ + (NSArray *)find:(ARFindSpecification)idOrSpecification
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection
{
return [self find:idOrSpecification
select:@"id"
filter:whereSQL
join:joinSQL
order:orderSQL
limit:limit
connection:aConnection];
}
+ (NSArray *)find:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection
{
NSArray *ids = [self findIds:idOrSpecification
select:selectSQL
filter:whereSQL
join:joinSQL
order:orderSQL
Expand All @@ -56,7 +105,10 @@ + (NSArray *)find:(ARFindSpecification)idOrSpecification
for(NSDictionary *match in ids)
{
NSUInteger id = [[match objectForKey:@"id"] unsignedIntValue];
[models addObject:[[[self alloc] initWithConnection:aConnection id:id] autorelease]];
if ( [selectSQL isEqualToString:@"id"] == YES )
[models addObject:[[[self alloc] initWithConnection:aConnection id:id] autorelease]];
else
[models addObject:[[[self alloc] initWithConnection:aConnection id:id readCache:match] autorelease]];
}
return models;
}
Expand All @@ -68,7 +120,27 @@ + (NSArray *)findIds:(ARFindSpecification)idOrSpecification
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection
{
NSMutableString *query = [NSMutableString stringWithFormat:@"SELECT id FROM %@", [self tableName]];
return [self findIds:idOrSpecification
select:@"id"
filter:whereSQL
join:joinSQL
order:orderSQL
limit:limit
connection:aConnection];
}
+ (NSArray *)findIds:(ARFindSpecification)idOrSpecification
select:(NSString *)selectSQL
filter:(NSString *)whereSQL
join:(NSString *)joinSQL
order:(NSString *)orderSQL
limit:(NSUInteger)limit
connection:(id<ARConnection>)aConnection
{
NSMutableString *query;
if ( [selectSQL isEqualToString:@"id"] )
query = [NSMutableString stringWithFormat:@"SELECT id FROM %@", [self tableName]];
else
query = [NSMutableString stringWithFormat:@"SELECT id, %@ FROM %@", selectSQL, [self tableName]];
if(joinSQL)
[query appendFormat:@" %@", joinSQL];

Expand Down

0 comments on commit 941653d

Please sign in to comment.