Sunday, February 17, 2013
Possible ways to use MongoDB in next Servlet based project
Hibernate OGM
No JPQL query support,
must use raw Mongo query language directly and as a result
getting back Mongo Objects, not entities
To solve this the project integrates with Hibernate Search which uses
Lucene as a search engine.
When you insert/update an entity the data is also added to the search engine
This is pretty good for a full text search capabilities
and later can use JPQL against the Lucene instead of against MongoDB
This means that must install/configure and depend on Lucene
Upside: relatively easy to setup without upgrading anything on Application server
Can find entity by _id easily
Downside: either depend on Lucene OR use only native MongoDB queries
====================
EclipseLink NoSQL
Support for JPQL
Mongo document will be a normal entity
Can also use native MongoDB queries if JPQL just cannot do certain queries
Overall this is the most convenient way and pretty sweet
The downside is that Application Server may not include the latest version of the
EclipseLink jpa libriries and as a result must update the jar files directly in the
application server, which may not be possible in case of cloud hosting
===========
No dependencies on anything - just use MongoDB drivers
directly - no entities.
Get cursor back, iterate over results manually, add to collection,
then return collection
Write classes that know how to deal with BasicDBObject from mongo
For example when creating new Question a class QuestionParser will
take the request object, generate SubmittedQuestgionWWW, get all
data from it, put data into BasicObject
and then save BasicObject into DB
Must create indexes using "EnsureIndex" or something like that.
https://openshift.redhat.com/community/blogs/spatial-jee6-jax-rs-cdi-mongodb-on-paas
Something like this: (Requires CDI support)
@Named
@ApplicationScoped
public class DBConnection {
private DB mongoDB;
@PostConstruct
public void afterCreate() {
…
}
…
}
Most likely no JEE server is required, so Tomcat with CDI support
is all it takes
=========================
Mongo JEE
https://github.com/angelozerr/mongo-jee
Has good support for pagination
and integration with JAX RS
Also maps mongo cursor directly to
output stream json - no need to
create List from mongo cursor manually
Looks like will work on just about any server
that has CDI, most likely
inside tomcat container, no JEE application server
required.
============================
Saturday, February 16, 2013
MongoDB in EJB project with EclipseLink
First you need to update persistense related jar files
in Glassfish modules folder
Update 7 persistence related jar files
in glassfish/modules
This folder in my PC is located
in c:\Program Files\glassfish-3.1.2.2\glassfish\modules
first backup current files just in case - create a new sub-folder _backup
move the files from modules to this new folder:
org.eclipse.persistence.antlr.jar
org.eclipse.persistence.jpa.jar
org.eclipse.persistence.asm.jar
org.eclipse.persistence.jpa.modelgen.jar
org.eclipse.persistence.core.jar
org.eclipse.persistence.oracle.jar
javax.persistence.jar
Then from eclipselink website download new zip file,
look for OSGI bundle:
http://www.eclipse.org/eclipselink/downloads/index.php#2.4
unzip that downloaded zip into some directory like
c:\javalibs
Then copy the updated versions on the same 7 .jar files
to
glassfish\modules directory
In case here:
c:\Program Files\glassfish-3.1.2.2\glassfish\modules
and then rename each of these .jar files to remove the versioning part of
file name, for example
org.eclipse.persistence.asm_3.3.1.v201206041142.jar
should be renamed to
org.eclipse.persistence.asm.jar
Do the same of the other updated files
Finally add these 2 .jar files to your project libs via NetBeans:
org.eclipse.persistense.nosql_xxxxxxx.jar (xxxxx is a version string like _2.4.1.v20121003-ad44345.jar
and also download the java client .jar from mongodb download site
and also add the mongo-java-driver-2.6.2.jar to your project library (the actual latest version may
be greater than 2.6.2 by now)
Restart Glassfish server, this can be done from inside NetBeans
The mongodb can be used now, so a regular @Entity annotation can be used
to persist data to mongo
So far so good.
Mongodb does not have transaction support so you will be use translation-type="RESOURCE_LOCAL"
in the persistence-unit section in persistence.xml
Then you have to provide your own transaction support in the classes
Some examples and basic documentation
is here
http://wiki.eclipse.org/EclipseLink/Examples/JPA/NoSQL
Sunday, January 27, 2013
My answer to "linking linkedin accounts"
This is my answer to a Question on Support site for LampCMS project
I know. I just found yesterday about changes to LinkedIN API. I wrote an answer about that, here:
http://support.lampcms.com/viewquestion/quest2274/LinkedIn-posts-do-not-work
Basically LinkedIN did not provide email address when user connects with LInkedIN API, but after the recent changes to their API they started providing email address.
I am making changes to the logic so that we can detect (using email address) when existing user is adding a LinkedIn account.
Saturday, January 26, 2013
My answer to "Search AutoComplete Behavior Broken?, Inconsistant with Code Comments"
This is my answer to a Question on Support site for LampCMS project
OK, I just looked at the javascript in qa.js again and it looks like it's not a bug
The behavior that you described (in the comments) applies only to autocomplete in the "title" of the questions form.
When you asking a new questions there is another auto-complete form that searches for similar questions as you typing the title of your question. That autocomplete will take you to the question when you click on one of the suggested results.
The search form's autocomplete just enters the suggested results into the search form. It was always working like that, it's not a bug.
There is a third autocomplete - for the tags form on the "ask question" form. That one inserts suggested tags into the tags field.
My answer to "LinkedIn posts do not work"
This is my answer to a Question on Support site for LampCMS project
So it turned out that LinkedIn has updated their oauth based authentication/authorization API
It now requires to ask for specific permissions. I am already working on updating our LinkedIN integration script.
The one good news about this is that now LinkedIN shares user's email address with the API client. So basically the popup permission window tells user that the Applications wants to access their profile, get their email address and post to LinkedIN on their behalf. User can agree or decline.
Having email address provided by the API makes it easier to register new user - we no longer need to use the extra step that we used before to ask user for their email address right after the Join with LinkedIN was completed.
Also knowing the email address during the Sign In with Linked IN can help determine if the user with this email address already registered on our site, in which case we will just connect their existing account with their LinkedIN account.
I'm working on having the updates ready. Will probably take about a week to make changes and test them.
Friday, January 25, 2013
My answer to "LinkedIn posts do not work"
This is my answer to a Question on Support site for LampCMS project
Thank you for this update. I will test this fix and if it works will push changes to github
Sunday, January 13, 2013
My answer to "Can't login with ID/PWD and can't change password"
This is my answer to a Question on Support site for LampCMS project
The fixed version has been pushed to github
Subscribe to:
Posts (Atom)