ORM tools/framework regarding mongodb for Java - 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

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.

Elasticsearch Java API from 2.x to 5.x issues

I've updated to elasticsearch java library version 5.2.0.
In 2.x,
I was using SearchRequestBuilder.addField() in order to add a field to the search request. Nevertheless, It seems to be replaced. I've written the available methods intellisense is showing me. Which of them do I need to pick?
addDocValueField
addFieldDataField
addScriptField
addStoredField
storedFields
fields
SearchRequestBuilder.setNoFields is also removed. Which would be the alternative?
Currently, I'm calling scripts from Java using this code. Is there any more elegant way to call it in 5.x Java API?
Code:
return AggregationBuilders
.terms(this.getName())
.field(this.getName())
.script(new Script(
ScriptType.FILE,
"painless",
"year",
ImmutableMap.of("field", this.getName())
)
);
As you can see I setting field as script parameter. Nevertheless, I don't quite understand how to get it from script code.
Thanks.
When in doubt, go to the source
use setFetchSource(String[] includes, String[] excludes) instead
use setFetchSource(false) instead
if you need to execute this script for each document, you can use addScriptField()

Wicket: Get Browser Information

How do I get information about the browser in a Java/Wicket/Maven Project?
Greetings
You can capture the browser information using the following code
getApplication().getRequestCycleSettings().setGatherExtendedBrowserInfo(true);
WebClientInfo w = (WebClientInfo)getWebRequestCycle().getClientInfo();
ClientProperties cp = w.getProperties();
// do something with the data
cp.getNavigatorAppName();
cp.getNavigatorAppCodeName();
cp.getNavigatorAppVersion();
cp.getBrowserVersionMajor();
cp.getBrowserVersionMinor();
Exerpt taken from WICKET Documentation
EDIT
Updated from comments.
The above code is for Wicket 1.4.x. For newer versions of Wicket replace getWebRequestCycle() with getRequestCycle()
If there is no getClientInfo() on getRequestCycle() (like there wasn't for me either), you could try the answer to this question:
Checking User Agent in Wicket
WebSession.get().getClientInfo();
It worked for me.
Wicket 6.x also provides org.apache.wicket.ajax.AjaxClientInfoBehavior. A demo of it can be seen at: http://www.wicket-library.com/wicket-examples-6.0.x/ajaxhellobrowser/

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

What is the difference between GraphDatabaseService or NeoService in neo4j

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.

Categories