I started simple CRUD sample to learn how persistence works in qi and
running into some strange behavior. I have code like this:
public void activate() throws Exception {
UnitOfWork uow = uowf.newUnitOfWork();
for (String [] sampleCountry : sampleCountries) {
String isoCode = sampleCountry[0];
String name = sampleCountry[1];
Country country = cr.findByIsoCode(isoCode);
if (country != null) {
System.err.println("Found country ... isoCode :
'" + isoCode + "'; name: '" + name + "'");
}
else {
System.err.println("Creating country ... isoCode:
'" + isoCode + "'; name: '" + name + "'");
cf.create(isoCode,name);
}
}
uow.complete();
uow = uowf.newUnitOfWork();
Iterator<Country> countries = cr.findAll().iterator();
while (countries.hasNext()) {
Country c = countries.next();
System.err.println("Retrieved ... isoCode: '" +
c.isoCode() + "'; name: '" + c.name() + "'" );
}
uow.complete();
}
cr and cf are services. both of which use uowf.currentUOW() to get to
the current UOW.
I use jdbm extension to save data and rdf to fetch it. Now, when I run
this code with a fresh
start (I delete db files) I get output like this:
JDBM store:/var/tmp/sample.data
Creating new index
Creating new registry
Creating country ... isoCode: 'DEU'; name: 'Germany'
Creating country ... isoCode: 'AUT'; name: 'Austria'
Creating country ... isoCode: 'HUN'; name: 'Hungary'
Creating country ... isoCode: 'USA'; name: 'United States'
Query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ns0: <urn:qi4j:entity:org.qi4j.api.entity.Identity#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?entityType ?identity
WHERE {
?entityType rdfs:subClassOf
<urn:qi4j:entity:net.groovysips.persistent.domain.country.Country>.
?entity rdf:type ?entityType.
?entity ns0:identity ?identity.
}
186 [main] INFO org.openrdf.query.parser.QueryParserRegistry -
Registered service class
org.openrdf.query.parser.serql.SeRQLParserFactory
188 [main] INFO org.openrdf.query.parser.QueryParserRegistry -
Registered service class
org.openrdf.query.parser.sparql.SPARQLParserFactory
Retrieved ... isoCode: 'USA'; name: 'United States'
Retrieved ... isoCode: 'DEU'; name: 'Germany'
Retrieved ... isoCode: 'AUT'; name: 'Austria'
Retrieved ... isoCode: 'HUN'; name: 'Hungary'
-----------------------
If however I run this over an existing DB I get the following output:
JDBM store:/var/tmp/sample.data
Using existing index
Using existing registry
Found country ... isoCode : 'DEU'; name: 'Germany'
Found country ... isoCode : 'AUT'; name: 'Austria'
Found country ... isoCode : 'HUN'; name: 'Hungary'
Found country ... isoCode : 'USA'; name: 'United States'
Query:
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ns0: <urn:qi4j:entity:org.qi4j.api.entity.Identity#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
SELECT DISTINCT ?entityType ?identity
WHERE {
?entityType rdfs:subClassOf
<urn:qi4j:entity:net.groovysips.persistent.domain.country.Country>.
?entity rdf:type ?entityType.
?entity ns0:identity ?identity.
}
146 [main] INFO org.openrdf.query.parser.QueryParserRegistry -
Registered service class
org.openrdf.query.parser.serql.SeRQLParserFactory
148 [main] INFO org.openrdf.query.parser.QueryParserRegistry -
Registered service class
org.openrdf.query.parser.sparql.SPARQLParserFactory
Somehow the query for all entities works only the first time around
(note no output for countries print-out). But trying to find by ID
works.
Anyone has any ideas on what might be wrong?
Thanks,
Alex.
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev