• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Batch fetching / raw rows / SQL / full text search
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Batch fetching / raw rows / SQL / full text search


  • Subject: Re: Batch fetching / raw rows / SQL / full text search
  • From: Mark Wardle <email@hidden>
  • Date: Sat, 13 Feb 2010 20:53:49 +0000

I've found that these work for converting arbitrary SQL into enterprise objects.

For my use-case I don't want to batch through the results but need to process the entities immediately.

As such, this may or may not be helpful for people searching for similar stuff...

public static NSArray<? extends EOEnterpriseObject> executeRawSqlToEO(EOEditingContext ec, String entityName, String sql, NSArray<String> columns) {

NSArray<EOGlobalID> gids = executeRawSql(ec, entityName, sql, columns);

return ERXEOGlobalIDUtilities.fetchObjectsWithGlobalIDs(ec, gids);

}

/**

* Executes a raw SQL statement returning an array of EOGlobalIDs.

* The raw SQL should return sufficient columns to allow the raw row to be converted into an

* enterprise object.

* You will usually need to convert column names to attribute names to allow the raw rows

* to be converted properly.

* 

* @param ec - editing context

* @param entityName - name of the entity that the raw rows will be converted to

* @param sql - the raw SQL statement to be executed

* @param columns - array of attribute names to replace the column names that will arrive from the database

* @return

*/

public static NSArray<EOGlobalID> executeRawSql(EOEditingContext ec, String entityName, String sql, NSArray<String> columns) {

NSMutableArray<EOGlobalID> gids = new NSMutableArray<EOGlobalID>();

EOModelGroup modelGroup = ERXEOAccessUtilities.modelGroup(ec);

EOEntity entity = modelGroup.entityNamed(entityName);

String modelName = entity.model().name();

NSArray<NSDictionary<?,?>> rawRows = EOUtilities.rawRowsForSQL(ec, modelName, sql, columns);

for(NSDictionary<?,?> row : rawRows) {

EOGlobalID gid = entity.globalIDForRow(row);

if (gid==null) throw new NullPointerException("Could not fetch global ID for raw row: " + row);

gids.add(gid);

}

return gids;

}


I'm calling this using this ( as a crude example with fixed SQL)


private final static String postgreSQLsearch = "select t_concept.concept_id from t_description,t_concept where to_tsvector('english', term) @@ to_tsquery('english', 'ataxia') and t_concept.concept_id = t_description.concept_id group by t_concept.concept_id;";

private final static NSArray<String> columnMap = new NSArray<String>(new String[] {"conceptId"});

public static NSArray<Concept>search(String terms, EOEditingContext ec) {

return (NSArray<Concept>) executeRawSqlToEO(ec, Concept.ENTITY_NAME, sqlSearchString(terms), columnMap);

}




On 11 February 2010 13:17, Mark Wardle <email@hidden> wrote:
> Thanks for this. I'll digest the code over the weekend when I have
> some free time.
>
> Thanks again,
>
> Mark
>
> On 10 February 2010 09:19, Eugene Khablov <email@hidden> wrote:
>> Hi, Mark!
>>
>> It was pretty simple to extended ERXBatchingDisplayGroup and
>> EODataSource with results from ERXIndexing and then just use them on a
>> page.
>> See attached code.
>>
>> --
>> Eugene Khablov
>> Media Agency "Demax"
>>
>>
>> On Wed, Feb 10, 2010 at 10:11, Mark Wardle <email@hidden> wrote:
>>> Thanks both - I'll have a look at the source for all of those options.
>>>
>>> Perhaps I should also be thinking how to expose full text search in a
>>> database agnostic way to applications but for the present, I'll be
>>> hardcoding some SQL for this specific case.
>>>
>>> Many thanks,
>>>
>>> Mark
>>>
>>>
>>> --
>>> Dr. Mark Wardle
>>> Specialist registrar, Neurology
>>> (Sent from my mobile)
>>>
>>>
>>> On 9 Feb 2010, at 23:40, Mike Schrag <email@hidden> wrote:
>>>
>>>> I suspect there's some fanciness we could expose in
>>>> ERXBatchingDisplayGroup here, too ... It's basically doing exactly the same
>>>> thing you're trying to do under the covers.
>>>>
>>>> ms
>>>>
>>>> On Feb 9, 2010, at 6:39 PM, Q wrote:
>>>>
>>>>>
>>>>> On 10/02/2010, at 9:18 AM, Mark Wardle wrote:
>>>>>
>>>>>> Hi.
>>>>>>
>>>>>> I'm evaluating lucene and postgresql's own full text search with a few
>>>>>> benchmarks.
>>>>>>
>>>>>> I'm now trying to get the results (sometimes lots) as an array of
>>>>>> enterprise objects.
>>>>>>
>>>>>> I can use EOUtilities.objectForRawRaw but it looks like there is a
>>>>>> trip to the database for each EO. I haven't benchmarked this bit of
>>>>>> the process yet, but sometimes I may get >500 results.
>>>>>>
>>>>>> is there a way of efficiently doing this for an array of, say, primary
>>>>>> keys, that I can return from the full-text engine?
>>>>>>
>>>>>
>>>>> Wonder's ERXEOControlUtilities has a few methods that might be useful to
>>>>> you:
>>>>>
>>>>> faultsForRawRowsFromEntity
>>>>> faultsForGlobalIDs
>>>>> objectsForFaults
>>>>> objectsForGlobalIDs
>>>>>
>>>>> --
>>>>> Seeya...Q
>>>>>
>>>>> Quinton Dolan - email@hidden
>>>>> Gold Coast, QLD, Australia (GMT+10)
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> _______________________________________________
>>>>> Do not post admin requests to the list. They will be ignored.
>>>>> Webobjects-dev mailing list      (email@hidden)
>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>
>>>>
>>>>
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Webobjects-dev mailing list      (email@hidden)
>>>
>>> This email sent to email@hidden
>>>
>>
>
>
>
> --
> Dr. Mark Wardle
> Specialist registrar, Neurology
> Cardiff, UK
>



--
Dr. Mark Wardle
Specialist registrar, Neurology
Cardiff, UK


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >Batch fetching / raw rows / SQL / full text search (From: Mark Wardle <email@hidden>)
 >Re: Batch fetching / raw rows / SQL / full text search (From: Q <email@hidden>)
 >Re: Batch fetching / raw rows / SQL / full text search (From: Mike Schrag <email@hidden>)
 >Re: Batch fetching / raw rows / SQL / full text search (From: Mark Wardle <email@hidden>)
 >Re: Batch fetching / raw rows / SQL / full text search (From: Eugene Khablov <email@hidden>)
 >Re: Batch fetching / raw rows / SQL / full text search (From: Mark Wardle <email@hidden>)

  • Prev by Date: Re: session undefined
  • Next by Date: WOLips and JProfiler 6.0.2
  • Previous by thread: Re: Batch fetching / raw rows / SQL / full text search
  • Next by thread: [OT] Fact about Apple Store and WO
  • Index(es):
    • Date
    • Thread