Skip to content

Instantly share code, notes, and snippets.

@gscheibel
gscheibel / AssociationContext.java
Created July 31, 2012 16:10
Abstract AssociationContext
public abstract class AssociationContext {
private final List<String> selectableColumns;
public AssociationContext() {
this.selectableColumns = new ArrayList<String>();
this.selectableColumns.add( "rows" );
this.selectableColumns.add( "columns" );
}
public List<String> getSelectableColumns() {
@gscheibel
gscheibel / MongoDBAssociationContext.java
Created July 31, 2012 16:15
MongoDBAssociationContext
public class MongoDBAssociationContext extends AssociationContext {
private List<String> loadingColumns;
@Override
public List<String> getLoadingColumns(){
if(this.loadingColumns == null){
this.loadingColumns = new ArrayList<String>(2);
this.loadingColumns.add( "rows" );
this.loadingColumns.add( "columns" );
@gscheibel
gscheibel / gist:3776838
Created September 24, 2012 16:26
Composite ID stored with IN_ENTITY & join column
{
"_id": {
"author": "Guillaume",
"title": "There are more than 20 JUGs in France"
},
"content": "Great! Congratulations folks",
"labels": []
} {
"_id": {
"news_author_fk": "Guillaume",
@gscheibel
gscheibel / gist:3776978
Created September 24, 2012 16:52
Label representation
{
"_id": NumberLong(5),
"name": "statJUG",
"news_author_fk": "Guillaume",
"news_topic_fk": "There are more than 20 JUGs in France"
}
@gscheibel
gscheibel / MongoDBDialect.java
Created October 10, 2012 12:55
Stack management
public void updateTuple(Tuple tuple, EntityKey key) {
//all above
if(this.stack != null){
this.stack.add( new Operation(idObject, updater) );
} else {
this.getCollection( key ).update( idObject, updater, true, false );
}
}
@gscheibel
gscheibel / module.xml
Created January 21, 2013 18:47
Jboss AS 7.1 OGM MongoDB module
<module xmlns="urn:jboss:module:1.1" name="org.hibernate.ogm.mongodb" slot="main">
<resources>
<resource-root path="hibernate-ogm-mongodb-4.0.0-SNAPSHOT.jar" />
<resource-root path="mongo-java-driver-2.9.0.jar" />
</resources>
<dependencies>
<module name="org.hibernate" export="true" services="import" slot="ogm" />
<module name="org.slf4j" />
<module name="javax.api" />
@gscheibel
gscheibel / module.xml
Created January 21, 2013 18:49
Jboss AS 7.1 OGM core module
<module xmlns="urn:jboss:module:1.1" name="org.hibernate" slot="ogm">
<resources>
<resource-root path="hibernate-ogm-core-4.0.0-SNAPSHOT.jar" />
</resources>
<dependencies>
<module name="org.hibernate" export="true" slot="main" />
<module name="org.slf4j" />
<module name="javax.api" />
<module name="javax.persistence.api" />
@gscheibel
gscheibel / AbstractTest.java
Created January 23, 2013 18:15
Hibernate Search with OGM
final QueryBuilder queryBuilder = ftm.getSearchFactory().buildQueryBuilder().forEntity(Post.class).get();
final org.apache.lucene.search.Query query = queryBuilder.keyword().onField("title").matching(title).createQuery();
final Object result = ftm.createFullTextQuery(query, Post.class).getSingleResult();
@gscheibel
gscheibel / mongo.xml
Created February 22, 2013 09:27
first option to list the writeconcern properties potential values
<row>
<entry>hibernate.ogm.mongodb.writeconcern</entry>
<entry>Defines the write concern setting used to control the
acknowledgment of write operations. You can use: ERRORS_IGNORED,
ACKNOWLEDGED, UNACKNOWLEDGED, FSYNCED, JOURNALED, REPLICA_ACKNOWLEDGED,
NONE, NORMAL, SAFE, MAJORITY, FSYNC_SAFE, JOURNAL_SAFE, REPLICAS_SAFE.
For more information, please refer to the
<ulink href="http://api.mongodb.org/java/current/com/mongodb/WriteConcern.html">official documentation</ulink>
This option is case insensitive and the default value is
@gscheibel
gscheibel / Main.java
Created March 25, 2013 10:43
Devoxx FR demo
public static void main(String[] args) throws UnknownHostException {
MongoClient client = new MongoClient();
DB devoxx = client.getDB("devoxx");
DBCollection events = devoxx.getCollection("events");
DBCursor dbObjects = events.find();
for (DBObject dbObject : dbObjects) {
System.out.println(dbObject.get("name"));
}
}