• 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: Which way is more efficient to get particular EOEnterpriseObject
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Which way is more efficient to get particular EOEnterpriseObject


  • Subject: Re: Which way is more efficient to get particular EOEnterpriseObject
  • From: Pierre Bernard <email@hidden>
  • Date: Thu, 16 Aug 2007 23:12:26 +0200

I mean:

Rather than saying this.getToMany() you can say EOFetchSpecification (other, inverseToOne = this, null)

public static String inverseRelationshipNameForRelationshipNameAndEntityName(
String relationshipName,
String entityName)
{


		EOEntity entity = EOModelGroup.defaultGroup().entityNamed(entityName);

EORelationship relationship = entity.relationshipNamed (relationshipName);

EORelationship inverseRelationship = relationship.inverseRelationship();

		return inverseRelationship.name();

	}

public static EOFetchSpecification fetchSpecificationForRelationshipWithKey(
EOEnterpriseObject anObject,
String aKey)
{
if (anObject != null)
anObject.willRead();
if (anObject == null || aKey == null)
return null;
anObject.willRead();
String anEntityName = anObject.entityName();
EOEntity anEntity = EOModelGroup.defaultGroup().entityNamed (anEntityName);
EORelationship aRelationship = anEntity.relationshipNamed(aKey);
if (aRelationship == null)
return null;
EOEditingContext anEditingContext = anObject.editingContext();
EOGlobalID aGlobalID = anEditingContext.globalIDForObject(anObject);
String aModelName = anEntity.model().name();
EODatabaseContext aDatabaseContext =
EOUtilities.databaseContextForModelNamed(anEditingContext, aModelName);
aDatabaseContext.lock();
NSDictionary row = aDatabaseContext.snapshotForGlobalID(aGlobalID);
aDatabaseContext.unlock();
if (row == null)
return null;
EOQualifier aQualifier = aRelationship.qualifierWithSourceRow(row);
if (aQualifier == null)
return null;
EOEntity aDestinationEntity = aRelationship.destinationEntity();
String aDestinationEntityName = aDestinationEntity.name();
EOFetchSpecification fetchSpec =
new EOFetchSpecification(aDestinationEntityName, aQualifier, null);
fetchSpec.setIsDeep(aDestinationEntity.isAbstractEntity());
cat.debug("fetchSpec = " + fetchSpec);
return fetchSpec;
}


On Aug 16, 2007, at 11:00 PM, Paolo Sommaruga wrote:

Hi Pierre,

please,

Il giorno 16/ago/07, alle ore 19:18, Pierre Bernard ha scritto:

[...]
- just fetch required object regarding mentioned relationship as just one
of attributes involved

A to-many is always the inverse of a to-one. You could qualify objects using that to-one.

how one can you "qualify objects using that to-one" ? Can you explain a little more ?


Regards

Paolo Sommaruga


I have done this on relationships having 300000-500000 objects. For 100 it is overkill in both code to write and IO accesses.

- index that array converting it into actual multi-dimensional as
mentioned above (using pure Java multidimensional arrays or nesting
NSArrays/NSDictionaries)

I would recommend this if you need to get multiple objects from the same relationship or if you repeatedly need to get to the object. There is no point in scanning the array over and again.


You can listen to EOF notifications to see when your cache goes stale.

Pierre



- - - Houdah Software s. à r. l. http://www.houdah.com

HoudahGeo: One-stop photo geocoding
HoudahSpot: Powerful Spotlight frontend



_______________________________________________
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: 
 >Which way is more efficient to get particular EOEnterpriseObject (From: "Gennady Kushnir" <email@hidden>)
 >Re: Which way is more efficient to get particular EOEnterpriseObject (From: Pierre Bernard <email@hidden>)
 >Re: Which way is more efficient to get particular EOEnterpriseObject (From: Paolo Sommaruga <email@hidden>)

  • Prev by Date: Re: Which way is more efficient to get particular EOEnterpriseObject
  • Next by Date: Looking for an update foo set bar = bar + 1 solution for WO
  • Previous by thread: Re: Which way is more efficient to get particular EOEnterpriseObject
  • Next by thread: WebSphere connection pool and EOModeler
  • Index(es):
    • Date
    • Thread