On Apr 6, 2006, at 11:19 PM, Tore Halset wrote:
> Hello!
>
> For any given Persistent object, is it possible to find the
> DataNode used? How?
>
> PS: Looking forward to try out B1!
>
> - Tore.
Hi Tore,
Here is a 1.1-ish solution that assumes that your ObjectContext is a
DataContext:
Persistent object = ..
DataContext context = (DataContext) object.getObjectContext();
DataDomain domain = context.getParentDataDomain();
DataMap map = context.getEntityResolver().getObjEntity
(object.getObjectId().getEntityName()).getDataMap();
DataNode node = domain.lookupDataNode(map);
1.2-ish solution should make no assumptions about the stack
structure, so it will have to do the lookup indirectly via a custom
query. Here is such a query. The trick is to override "route" method,
obtaining QueryEngine from QueryRouter and store it in the query:
public class DataNodeQuery extends AbstractQuery {
protected DataNode node;
protected String entityName;
public DataNodeQuery(Persistent object) {
this.entityName = object.getObjectId().getEntityName();
}
public void route(QueryRouter router, EntityResolver resolver,
Query substitutedQuery) {
DataMap map = resolver.getObjEntity(entityName).getDataMap();
this.node = (DataNode) router.engineForDataMap(map);
}
public SQLAction createSQLAction(SQLActionVisitor visitor) {
throw new UnsupportedOperationException();
}
public DataNode getDataNode() {
return node;
}
}
Execute the query, but ignore returned result:
DataNodeQuery q = new DataNodeQuery(object);
object.getObjectContext().performGenericQuery(q);
DataNode node = q.getDataNode();
Andrus
This archive was generated by hypermail 2.0.0 : Fri Apr 07 2006 - 04:07:01 EDT