Created
January 20, 2013 08:52
-
-
Save idanmo/4577356 to your computer and use it in GitHub Desktop.
GigaSpaces MongoDB persistency example implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class MongoDbSpaceSynchronizationEndpoint extends SpaceSynchronizationEndpoint { | |
| private DB db = ... // MongoDB database object | |
| @Override | |
| public void onOperationsBatchSynchronization(final OperationsBatchData data) { | |
| // Get the MongoDB collection that will be used for persisting space documents | |
| DBCollection collection = db.getCollection("spaceDocuments"); | |
| // Persist each of the space documents in this batch | |
| for (DataSyncOperation operation : data.getBatchDataItems()) { | |
| // Handle only write operations which are document supported | |
| if (operation.getDataSyncOperationType() == DataSyncOperationType.WRITE && operation.supportsDataAsDocument()) { | |
| // Get the space document for this operation | |
| SpaceDocument spaceDocument = operation.getDataAsDocument(); | |
| // Create a MongoDB document | |
| BasicDBObject mongoDocument = new BasicDBObject(); | |
| for (Map.Entry<String,Object> property : spaceDocument.getProperties().entrySet()) | |
| mongoDocument.append(property.getKey(), property.getValue()); | |
| // Insert to MongoDB | |
| collection.insert(mongoDocument); | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <bean id="spaceSynchronizationEndpoint" class="com.gigaspaces.persistency.MongoDbSpaceSynchronizationEndpoint" /> | |
| <os-core:space id="space" url="/./documentsSpace" space-sync-endpoint="spaceSynchronizationEndpoint" /> | |
| <os-core:giga-space id="gigaSpace" space="space" /> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment