Andrus,
thanks for the tip. Unfortunately it does not work. Just now I replaced the
code which fetches the two objects from shared to local datacontext with two
queries which return the two objects in question (localMot and localTown)
into the same datacontext.
I commented the code which was "transfering" the two objects from shared
data context before. This is how it looks now:
// MapObjectType mot =
persistenceService.findMapObjectType(MapObjectTypeEnum.STREET);
// System.out.println("mot dc:" + mot.getDataContext());
// // mot lives in shared datacontext so we need a copy
// MapObjectType localMot = (MapObjectType)
dataContext.localObject(mot.getObjectId(), null);
// System.out.println("localMot dc:" +
localMot.getDataContext());
Expression e =
ExpressionFactory.matchExp(MapObjectType.TYPE_PROPERTY,
MapObjectTypeEnum.STREET);
SelectQuery query = new SelectQuery(MapObjectType.class, e);
List list = dataContext.performQuery(query);
MapObjectType localMot = null;
if (list.size() > 0) {
localMot = (MapObjectType) list.get(0);
} else {
return false;
}
while (featureIterator.hasNext()) {
SimpleFeature feature = (SimpleFeature)
featureIterator.next();
Integer mid =
Integer.parseInt(feature.getAttribute("UL_MID").toString());
String rawname = (String) feature.getAttribute("UL_UIME");
// prettyPrintHex(rawname.getBytes());
MapObject mapObject =
dataContext.newObject(MapObject.class);
Street street = dataContext.newObject(Street.class);
street.setMid(mid);
street.setName(rawname);
Integer townMid =
Integer.parseInt(feature.getAttribute("NA_MID").toString());
// Town town = persistenceService.findTownByMid(townMid);
// System.out.println("town dc:" + town.getDataContext());
// if (town == null) {
// logger.error("Street with mid {} has no town
associated.", street.getMid());
// return false; // TODO tell why (each street must have
a town)
// }
// // town lives in shared datacontext so we need a copy
// Town localTown = (Town)
dataContext.localObject(town.getObjectId(), null);
// System.out.println("localTown dc:" +
localTown.getDataContext());
// logger.debug("localTown: " + localTown);
Expression e1 =
ExpressionFactory.matchExp(Town.MID_PROPERTY, townMid);
SelectQuery query1 = new SelectQuery(Town.class, e1);
List list1 = dataContext.performQuery(query1);
Town localTown = null;
if (list1.size() > 0) {
localTown = (Town) list1.get(0);
} else {
return false;
}
*street.setTown(localTown);*
//localTown.addToStreets(street);
mapObject.setStreet(street);
mapObject.setMapObjectType(localMot);
counter++;
printDataContext(dataContext);
logger.debug("Will import Street: " + street);
dataContext.commitChanges();
}
But the* town_mid is still NULL* while the other relationship
(mapObject.setStreet(street)) is set correctly.
[2010/10/14 09:57:16.327] INFO
[AppModule.ImportService:getShapeFileFromClasspath]: Importing Street from
jar:file:/C:/Users/borutb/.m2/repository/si/planet9/maps-geodata/0.0.2-SNAPSHOT/maps-geodata-0.0.2-SNAPSHOT.jar!/geodata/UL.shp
[2010/10/14 09:57:16.361] DEBUG
[AppModule.ImportService:getFeatureIteratorForShapeResource]: Setting Shape
file encoding: windows-1250
[2010/10/14 09:57:16.586] INFO [access.QueryLogger:logQueryStart]: --- will
run 1 query.
[2010/10/14 09:57:16.589] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:16.590] INFO [access.QueryLogger:logQuery]: SELECT t0.id,
t0.type FROM maps.map_object_type t0 WHERE t0.type = ? [bind:
1->type:STREET=3]
[2010/10/14 09:57:16.593] INFO [access.QueryLogger:logSelectCount]: ===
returned 1 row. - took 3 ms.
[2010/10/14 09:57:16.594] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
[2010/10/14 09:57:16.619] INFO [access.QueryLogger:logQueryStart]: --- will
run 1 query.
[2010/10/14 09:57:16.622] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:16.623] INFO [access.QueryLogger:logQuery]: SELECT
t0.name, t0.id, t0.mid, t0.label_y, t0.label_x FROM maps.town t0 WHERE
t0.mid = ? [bind: 1->mid:10083931]
[2010/10/14 09:57:16.625] INFO [access.QueryLogger:logSelectCount]: ===
returned 1 row. - took 3 ms.
[2010/10/14 09:57:16.627] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
NEW objects
{<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BE35CB1188>}]}
DELETED objects
MODIFIED objects
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
labelX=>416031.93]}
UNCOMMITED objects
{<ObjectId:MapObjectType, id=4>; modified; [mapObjects=>(..); type=>STREET]}
{<ObjectId:Town, id=446>; modified; [name=>Ajdovščina; mapObjects=>?;
streets=>(..); mid=>10083931; labelY=>85131.71; houseNumbers=>?;
labelX=>416031.93]}
{<ObjectId:Street, TEMP:000001BE35CB1188>; new; [name=>Ulica Milana
Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town, id=446>};
mid=>19568962; houseNumbers=>(..)]}
{<ObjectId:MapObject, TEMP:000000BE35C71188>; new;
[mapObjectType=>{<ObjectId:MapObjectType, id=4>}; street=>{<ObjectId:Street,
TEMP:000001BE35CB1188>}]}
[2010/10/14 09:57:16.633] DEBUG [AppModule.ImportService:importStreetsData]:
Will import Street: {<ObjectId:Street, TEMP:000001BE35CB1188>; new;
[name=>Ulica Milana Klemenčiča; mapObjects=>(..); town=>{<ObjectId:Town,
id=446>}; mid=>19568962; houseNumbers=>(..)]}
[2010/10/14 09:57:21.709] INFO [access.QueryLogger:logQueryStart]: --- will
run 2 queries.
[2010/10/14 09:57:21.718] INFO [access.QueryLogger:logBeginTransaction]:
--- transaction started.
[2010/10/14 09:57:21.734] INFO [access.QueryLogger:logQuery]: INSERT INTO
maps.street (mid, name, town_mid) VALUES (?, ?, ?)
[2010/10/14 09:57:21.742] INFO [access.QueryLogger:logQueryParameters]:
[bind: 1->mid:19568962, 2->name:'Ulica Milana Klemenčiča', *3->town_mid:NULL
*]
[2010/10/14 09:57:21.756] INFO [access.QueryLogger:logGeneratedKey]:
Generated PK: street.id = 1
[2010/10/14 09:57:21.763] INFO [access.QueryLogger:logUpdateCount]: ===
updated 1 row.
[2010/10/14 09:57:21.770] INFO [access.QueryLogger:logQuery]: INSERT INTO
maps.map_object (company_id, house_number_id, map_object_type_id, poi_id,
post_office_id, street_id, town_id) VALUES (?, ?, ?, ?, ?, ?, ?)
[2010/10/14 09:57:21.778] INFO [access.QueryLogger:logQueryParameters]:
[bind: 1->company_id:NULL, 2->house_number_id:NULL, *3->map_object_type_id:4
*, 4->poi_id:NULL, 5->post_office_id:NULL, 6->street_id:1, 7->town_id:NULL]
[2010/10/14 09:57:21.787] INFO [access.QueryLogger:logGeneratedKey]:
Generated PK: map_object.id = 15997
[2010/10/14 09:57:21.794] INFO [access.QueryLogger:logUpdateCount]: ===
updated 1 row.
[2010/10/14 09:57:21.831] INFO [access.QueryLogger:logCommitTransaction]:
+++ transaction committed.
If this is a bug, what would you recomend?
Thanks,
Borut
2010/10/13 Andrus Adamchik <andru..bjectstyle.org>
> Hi Borut,
>
> On Oct 13, 2010, at 12:02 PM, Borut Bolčina wrote:
>
> > MapObjectType localMot = (MapObjectType)
> > dataContext.localObject(mot.getObjectId(), mot);
>
> Not sure if there's anything else involved, but the use of 'localObject' is
> suspect. Try using null as the second argument:
>
> MapObjectType localMot = (MapObjectType)
> dataContext.localObject(mot.getObjectId(), null);
>
> This is a piece of less intuitive API in Cayenne. I really wish to replace
> it with something more explicit...
>
> Andrus
>
>
This archive was generated by hypermail 2.0.0 : Thu Oct 14 2010 - 08:03:40 UTC