What is the difference between GraphDatabaseService or NeoService in neo4j - java

I'm learning to use neo4j, but am a bit confused on its usage. When I'm adding nodes and relationships, I can do it like this:
GraphDatabaseService graphDb = new EmbeddedGraphDatabase("C:/temp/graphdb");
Transaction tx = graphDb.beginTx();
try {
org.neo4j.graphdb.Node node = graphDb.createNode();
...
I could also do it like this:
NeoService neoService = new EmbeddedNeo("C:/temp/graphdb");
Transaction tx = neoService.beginTx();
try {
org.neo4j.api.core.Node node = neoService.createNode();
...
What is the difference here really? Which one should I use? Why are they 2 different mechanisms? Is this just API evolution here? :) I want to use the MetaModel API and it needs a NeoService, so the choice there is clear I guess.

Sorry,
you should use the first one, since in the latest 1.0-RC1 the namespace was moved. This is just naming, the semantics are the same. The second example is outdated and should be removed form the official documentation. Where did you find that?
Cheers,
/peter neubauer

You're spot on with the API evolution comment. The old API is NeoService, so you shouldn't use that. Go with your first snippet. For more information on the API change see e.g. the release mail for the latest rc:
http://www.mail-archive.com/user#lists.neo4j.org/msg02378.html
If you use the latest snapshot (0.7-SNAPSHOT) of the meta-model component, you'll find that it uses the latest API. For our 1.0 release (should be out Real Soon Now :), we're going to make non-SNAPSHOT releases of all components that will use the new API.
-EE

And regarding the meta model, please use the meta-model component (now with the maven artifactId: neo4j-meta-model).
I also notice that the component overview http://components.neo4j.org/neo4j-meta-model/ has some invalid example code and descriptions. I'll try to fix that.

Related

how to make the latest MyBatis Dynamic SQL support pagination for mysql (limit/offset)?

There are some samples on http://www.mybatis.org/mybatis-dynamic-sql/docs/select.html.
I want to implement limit/offset for mysql but failed to see any document on describing how to extend this library to support additional where condition.
here is what i'd like to achieve:
SelectStatementProvider selectStatement = select(id, animalName, bodyWeight, brainWeight)
.from(animalData)
.where(id, isIn(1, 5, 7))
.and(bodyWeight, isBetween(1.0).and(3.0))
.orderBy(id.descending(), bodyWeight)
.limit(1).offset(10)
.build()
.render(RenderingStrategy.MYBATIS3);
There are a couple of resources you can use.
This page - http://www.mybatis.org/mybatis-dynamic-sql/docs/whereClauses.html - shows an example of using standalone where clauses to build a paging query. This is not exactly what you are looking for, but it shows one way to do it.
There is a unit test showing something that is closer to what you are looking for here - https://github.com/mybatis/mybatis-dynamic-sql/tree/master/src/test/java/examples/paging. This code works for MySQL and you could use it as is.
I hope to make this a little easier in a future release.

batch update in play-morphia

I'm using Play framework 1.2.5 and Play-Morphia module.
I want to know if there's a way to update many objects at one Morphia query. I've found this example at https://github.com/greenlaw110/play-morphia/blob/master/documentation/manual/crud.textile, but it seems that I can't use "in" operation in norder to find all the objects which I hold in a list of their IDs.
I'm trying to update the paidInvoiceDocNum filed in each of the objects which their IDs are in the list "itemsIds". This is what I've tried so far:
String q = TransactionItem.find().field("id").in(itemsIds).toString();
TransactionItem.o().set("paidInvoiceDocNum", String.valueOf(docNumber)).update(q);
Without the .toString() it doesn't work either.
Any suggestions?
After long time of experimenting with Play-Morphia, I've found the way to do this update and here it is:
Datastore ds = TransactionItem.ds();
UpdateOperations<TransactionItem> op = ds.createUpdateOperations(TransactionItem.class).set("paidInvoiceDocNum", String.valueOf(docNumber));
Query<TransactionItem> q = (Query<TransactionItem>)TransactionItem.q().filter("id in", itemsIds).getMorphiaQuery();
ds.update(q, op);
Hope It will help...
Can you try this?
TransactionItem.o().set("paidInvoiceDocNum", docNumber).update("id in", itemsIds);
BTW, what's your morphia version. Keep in mind Play has close the updates to modules. Use this to get the latest morphia plugin version: https://gist.github.com/greenlaw110/2868365

Compilation issue with EMF Compare code

Version of EMF Compare: 2.1.0 M6 (2013/03/19 17:50)
I am trying to use standalone compare as explained in this guide. I get the below compilation error
The method setMatchEngine(IMatchEngine) is undefined for the type EMFCompare.Builder
for the below code
// Configure EMF Compare
IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
IMatchEngine matchEngine = new DefaultMatchEngine(matcher, comparisonFactory);
EMFCompare comparator = EMFCompare.builder().setMatchEngine(matchEngine).build();
I see that setMatchEngine is replaced by some other API as shown in the below figure. I am not sure how to specify the new matchEngine using that API.
These APIs have changed for M6 (the API are now in their final 2.1.0 stage as far as removals are concerned). A good source of "how to use the APIs" are the unit tests of EMF Compare if you have the code in your workspace.
For your particular use case, the code would look as such:
IMatchEngine.Factory factory = new MatchEngineFactoryImpl(UseIdentifiers.NEVER);
IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
matchEngineRegistry .add(factory);
EMFCompare comparator = EMFCompare.builder().setMatchEngineFactoryRegistry(matchEngineRegistry).build();
Note that using the default registry (EMFCompare.builder().build();) would be enough in most cases... except when you really can't let EMF Compare use the IDs :p.
[edit: a small note: we have now updated the wiki with accurate information, thanks for the feedback ;)]

Restlet- Beginner Stuff for Client Side - Path, Accept Header, QueryParam

Before I started with Restlet I already wrote a Jersey client. It was very intutiv - it seems like Restlet isnt. There is not much documentation and I can't solve the easiest problems.
Where I am:
service = new ClientResource("http://localhost:8080/com-project-core/rest");
service.setChallengeResponse(ChallengeScheme.HTTP_BASIC, "admin", "geheima");
What I get from documentation:
String myString = service.get(String.class);
or wrapping up a Resource:
ConnectedResourceIF connectedResource = service.wrap(ConnectedResourceIF.class);
Thats working. But what about:
A. When I want to change my service path? In Jersey it was intuitiv like
service.path("foo").path("bar")
for
http://localhost:8080/com-project-core/rest/foo/bar
B. I want to set a acceptHeader. In jersey it was like
service.accept(MediaType.TEXT_PLAIN)
C. I want to set query parameters. In jersey:
service.queryParam("1","foo").queryParam("2","bar")
Sorry, hope someone can solve this beginner problems. I cant find somethign in the restlet documentation.
For A:
service.getChild("/foo/bar", ConnectedResourceIF.class);
For B (need a recent 2.1 RCx version):
service.accept(MediaType.TEXT_PLAIN);
For C (need a recent 2.1 RCx version):
service.setQueryValue("1","foo");
service.setQueryValue("2","bar");
The best place to look for such things is the Javadocs, because those API changes are pretty recent:
http://www.restlet.org/documentation/snapshot/jee/api/org/restlet/resource/ClientResource.html
We are working on a new in-depth tutorial for next 2.2 version. First finishing "Restlet in Action" book :)

ORM tools/framework regarding mongodb for Java

is there any ORM tool/framework for mongoDB with java and also support maven, so that it will be helpful to apply constraints, use of cursers in database operations?
There are some. Start reading:
http://www.mongodb.org/display/DOCS/Java+Language+Center
As for maven support, just look up libraries in mvnrepository.com ( most of them will be there )
This is what you need:
http://www.infoq.com/articles/mongodb-java-orm-bcd
It is maven-based.
See this presenation on slide share http://www.slideshare.net/mongodb/java-persistence-frameworks-for-mongodb
To work with Mongo Db at grass root level I found http://howtodoinjava.com/2014/05/29/mongodb-selectqueryfind-documents-examples/ link very helpful
You can use morphia.
It is a wrapper over mongo-java-driver and works well in the production environment. It is well documented and supports raw queries as well.
Also, well SO community support
try MongoDBExecutor. It will definitely increase the productivity of development. Here is simple sample about CRUD:
#Test
public void test_crud_by_id() {
Account account = createAccount();
account.setId(ObjectId.get().toString());
// create
collExecutor.insert(account);
// read
Account dbAccount = collExecutor.get(Account.class, account.getId());
// update
dbAccount.setFirstName("newFirstName");
collExecutor.update(dbAccount.getId(), N.asMap(FIRST_NAME, dbAccount.getFirstName()));
// delete
collExecutor.delete(dbAccount.getId());
// check
assertFalse(collExecutor.exists(dbAccount.getId()));
}
Declaration: I'm the developer of AbacusUtil

Categories