List of usage examples for com.mongodb BasicDBObjectBuilder start
public static BasicDBObjectBuilder start(final String key, final Object val)
From source file:org.alfresco.bm.data.ProcessDataDAO.java
License:Open Source License
/** * @param db MongoDB// w w w. j av a2s.c o m * @param collection name of DB collection containing process data */ public ProcessDataDAO(DB db, String collection) { super(); this.collection = db.getCollection(collection); // Initialize indexes DBObject idx_PROCNAME = BasicDBObjectBuilder.start(ProcessData.FIELD_NAME, 1).get(); DBObject opt_PROCNAME = BasicDBObjectBuilder.start("name", "IDX_PROCNAME").add("unique", true).get(); this.collection.createIndex(idx_PROCNAME, opt_PROCNAME); }
From source file:org.alfresco.bm.data.WebScriptInvocationDataDAO.java
License:Open Source License
/** * @param db MongoDB//from ww w . java2 s .co m * @param collection name of DB collection containing Web Script Invocation data */ public WebScriptInvocationDataDAO(DB db, String collection) { super(); this.collection = db.getCollection(collection); // Initialize indexes DBObject idx_WebScriptInvocationName = BasicDBObjectBuilder .start(WebScriptInvocationData.FIELD_WS_INVOCATION_NAME, 1).get(); DBObject opt_WebScriptInvocationName = BasicDBObjectBuilder.start("name", "IDX_WS_INVOCATION_NAME") .add("unique", true).get(); this.collection.createIndex(idx_WebScriptInvocationName, opt_WebScriptInvocationName); }
From source file:org.alfresco.bm.devicesync.dao.mongo.MongoMetricsService.java
License:Open Source License
@Override public void addMetrics(DBObject syncMetrics, DBObject activeMQStats) { long timestamp = System.currentTimeMillis(); LocalDateTime time = new LocalDateTime(timestamp, DateTimeZone.UTC); String formattedTime = time.toString(); DBObject insert = BasicDBObjectBuilder.start("timestamp", timestamp).add("time", formattedTime) .add("sync", syncMetrics).add("activeMQ", activeMQStats).get(); collection.insert(insert);/*from ww w. ja va2 s .co m*/ }
From source file:org.alfresco.bm.event.mongo.MongoEventService.java
License:Open Source License
@Override public void start() throws Exception { // Initialize indexes DBObject idx_NEXT_AVAILABLE_EVENT_V2 = BasicDBObjectBuilder .start(Event.FIELD_SCHEDULED_TIME, Integer.valueOf(-1)) .add(Event.FIELD_LOCK_OWNER, Integer.valueOf(1)).add(Event.FIELD_DATA_OWNER, Integer.valueOf(1)) .add(Event.FIELD_DRIVER, Integer.valueOf(1)).get(); DBObject opt_NEXT_AVAILABLE_EVENT_V2 = BasicDBObjectBuilder.start("name", "IDX_NEXT_AVAILABLE_EVENT_V2") .add("unique", Boolean.FALSE).get(); collection.createIndex(idx_NEXT_AVAILABLE_EVENT_V2, opt_NEXT_AVAILABLE_EVENT_V2); DBObject idx_NAME = BasicDBObjectBuilder.start(Event.FIELD_NAME, Integer.valueOf(1)).get(); DBObject opt_NAME = BasicDBObjectBuilder.start("name", "IDX_NAME").add("unique", Boolean.FALSE).get(); collection.createIndex(idx_NAME, opt_NAME); }
From source file:org.alfresco.bm.event.mongo.MongoResultService.java
License:Open Source License
private void checkIndexes() throws Exception { if (!checkIndexes) { return;// w ww . j a va2 s. c o m } // Initialize indexes DBObject idx_EVENT_NAME_START = BasicDBObjectBuilder.start(EventRecord.FIELD_EVENT_NAME, Integer.valueOf(1)) .add(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBObject opt_EVENT_NAME_START = BasicDBObjectBuilder.start("name", "IDX_EVENT_NAME_START") .add("unique", Boolean.FALSE).get(); collection.createIndex(idx_EVENT_NAME_START, opt_EVENT_NAME_START); DBObject idx_SUCCESS_START = BasicDBObjectBuilder.start(EventRecord.FIELD_SUCCESS, Integer.valueOf(1)) .add(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBObject opt_SUCCESS_START = BasicDBObjectBuilder.start("name", "IDX_SUCCESS_START") .add("unique", Boolean.FALSE).get(); collection.createIndex(idx_SUCCESS_START, opt_SUCCESS_START); DBObject idx_START = BasicDBObjectBuilder.start(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBObject opt_START = BasicDBObjectBuilder.start("name", "IDX_START").add("unique", Boolean.FALSE).get(); collection.createIndex(idx_START, opt_START); DBObject idx_SESSION_START = BasicDBObjectBuilder .start(EventRecord.FIELD_EVENT_SESSION_ID, Integer.valueOf(1)) .add(EventRecord.FIELD_START_TIME, Integer.valueOf(1)).get(); DBObject opt_SESSION_START = BasicDBObjectBuilder.start("name", "IDX_SESSION_START") .add("unique", Boolean.FALSE).get(); collection.createIndex(idx_SESSION_START, opt_SESSION_START); }
From source file:org.alfresco.bm.file.FileDataServiceImpl.java
License:Open Source License
/** * Ensure that the MongoDB collection has the required indexes associated with * this user bean.// w ww . j a va 2s .c o m */ private void checkIndexes() { collection.setWriteConcern(WriteConcern.SAFE); DBObject idxRandomizer = BasicDBObjectBuilder.start(FIELD_FILESET, 1).add(FIELD_RANDOMIZER, 1).get(); DBObject optRandomizer = BasicDBObjectBuilder.start("name", "idx_randomizer").add("unique", Boolean.FALSE) .get(); collection.createIndex(idxRandomizer, optRandomizer); DBObject idxExtension = BasicDBObjectBuilder.start(FIELD_FILESET, 1).add(FIELD_EXTENSION, 1) .add(FIELD_RANDOMIZER, 1).get(); DBObject optExtension = BasicDBObjectBuilder.start("name", "idx_extension").add("unique", Boolean.FALSE) .get(); collection.createIndex(idxExtension, optExtension); DBObject uidxRemoteName = BasicDBObjectBuilder.start(FIELD_FILESET, 1).add(FIELD_REMOTE_NAME, 1).get(); DBObject optRemoteName = BasicDBObjectBuilder.start("name", "uidx_remoteName").add("unique", Boolean.TRUE) .get(); collection.createIndex(uidxRemoteName, optRemoteName); DBObject uidxLocalName = BasicDBObjectBuilder.start(FIELD_FILESET, 1).add(FIELD_LOCAL_NAME, 1).get(); DBObject optLocalName = BasicDBObjectBuilder.start("name", "uidx_localName").add("unique", Boolean.TRUE) .get(); collection.createIndex(uidxLocalName, optLocalName); }
From source file:org.alfresco.bm.session.MongoSessionService.java
License:Open Source License
/** * Ensure that the MongoDB collection has the required indexes *///from w w w . j a va 2s . c o m private void checkIndexes() { collection.setWriteConcern(WriteConcern.SAFE); // Ensure unique session ID // This is guaranteed by MongoDB // Ensure ordering by start time DBObject idxSessionIdStartTime = BasicDBObjectBuilder.start(FIELD_START_TIME, 1).get(); DBObject optSessionIdStartTime = BasicDBObjectBuilder.start("name", "idxSessionIdStartTime") .add("unique", Boolean.FALSE).get(); collection.createIndex(idxSessionIdStartTime, optSessionIdStartTime); // Find unfinished sessions DBObject idxEndTimeStartTime = BasicDBObjectBuilder.start(FIELD_END_TIME, 1).add(FIELD_START_TIME, 1).get(); DBObject optEndTimeStartTime = BasicDBObjectBuilder.start("name", "idxEndTimeStartTime") .add("unique", Boolean.FALSE).get(); collection.createIndex(idxEndTimeStartTime, optEndTimeStartTime); }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Initialize indexes// w ww . j av a2 s . co m */ @Override public void start() throws Exception { // Clean up old data and indexes String[] indexesToDrop = new String[] { "TESTS_NAME_RELEASE", "TEST_DRIVERS_UNIQUE_RELEASE_SCHEMA_IPADDRESS", "TEST_RUNS_TEST", "TEST_RUNS_TEST_NAME_SCHEDULED", "TEST_PROPS_TEST_NAME", "TEST_DEFS_UNIQUE_RELEASE", "TEST_DEFS_RELEASE_SCHEMA", "TEST_DRIVERS_IDX_NAME_EXPIRES" }; for (String indexToDrop : indexesToDrop) { try { testDrivers.dropIndex(indexToDrop); } catch (MongoException e) { // ignore } try { testDefs.dropIndex(indexToDrop); } catch (MongoException e) { // ignore } try { tests.dropIndex(indexToDrop); } catch (MongoException e) { // ignore } try { testRuns.dropIndex(indexToDrop); } catch (MongoException e) { // ignore } try { testProps.dropIndex(indexToDrop); } catch (MongoException e) { // ignore } } // @since 2.0 DBObject idx_TEST_DRIVERS_RELEASE_SCHEMA_IPADDRESS = BasicDBObjectBuilder.start(FIELD_RELEASE, 1) .add(FIELD_SCHEMA, 1).add(FIELD_IP_ADDRESS, 1).get(); DBObject opts_TEST_DRIVERS_RELEASE_SCHEMA_IPADDRESS = BasicDBObjectBuilder.start() .add("name", "TEST_DRIVERS_RELEASE_SCHEMA_IPADDRESS").add("unique", Boolean.FALSE).get(); testDrivers.createIndex(idx_TEST_DRIVERS_RELEASE_SCHEMA_IPADDRESS, opts_TEST_DRIVERS_RELEASE_SCHEMA_IPADDRESS); // @since 2.0 DBObject idx_TEST_DRIVERS_IDX_NAME_EXPIRES_SCHEMA_RELEASE = BasicDBObjectBuilder.start() .add(FIELD_PING + "." + FIELD_EXPIRES, -1).add(FIELD_SCHEMA, 1).add(FIELD_RELEASE, 1).get(); DBObject opts_TEST_DRIVERS_IDX_NAME_EXPIRES_SCHEMA_RELEASE = BasicDBObjectBuilder.start() .add("name", "TEST_DRIVERS_IDX_NAME_EXPIRES_SCHEMA_RELEASE").add("unique", Boolean.FALSE).get(); testDrivers.createIndex(idx_TEST_DRIVERS_IDX_NAME_EXPIRES_SCHEMA_RELEASE, opts_TEST_DRIVERS_IDX_NAME_EXPIRES_SCHEMA_RELEASE); // @since 2.0 DBObject idx_TEST_DEFS_UNIQUE_RELEASE_SCHEMA = BasicDBObjectBuilder.start(FIELD_RELEASE, 1) .add(FIELD_SCHEMA, 1).get(); DBObject opts_TEST_DEFS_UNIQUE_RELEASE_SCHEMA = BasicDBObjectBuilder.start() .add("name", "TEST_DEFS_UNIQUE_RELEASE_SCHEMA").add("unique", Boolean.TRUE).get(); testDefs.createIndex(idx_TEST_DEFS_UNIQUE_RELEASE_SCHEMA, opts_TEST_DEFS_UNIQUE_RELEASE_SCHEMA); // @since 2.0 DBObject idx_TESTS_UNIQUE_NAME = BasicDBObjectBuilder.start(FIELD_NAME, 1).get(); DBObject opts_TESTS_UNIQUE_NAME = BasicDBObjectBuilder.start().add("name", "TESTS_UNIQUE_NAME") .add("unique", Boolean.TRUE).get(); tests.createIndex(idx_TESTS_UNIQUE_NAME, opts_TESTS_UNIQUE_NAME); // @since 2.0 DBObject idx_TESTS_NAME_RELEASE_SCHEMA = BasicDBObjectBuilder.start(FIELD_NAME, 1).add(FIELD_RELEASE, 1) .add(FIELD_SCHEMA, 1).get(); DBObject opts_TESTS_NAME_RELEASE_SCHEMA = BasicDBObjectBuilder.start() .add("name", "TESTS_NAME_RELEASE_SCHEMA").add("unique", Boolean.FALSE).get(); tests.createIndex(idx_TESTS_NAME_RELEASE_SCHEMA, opts_TESTS_NAME_RELEASE_SCHEMA); // @since 2.0 DBObject idx_TEST_RUNS_NAME = BasicDBObjectBuilder.start(FIELD_NAME, 1).get(); DBObject opts_TEST_RUNS_NAME = BasicDBObjectBuilder.start().add("name", "TEST_RUNS_NAME") .add("unique", Boolean.FALSE).get(); testRuns.createIndex(idx_TEST_RUNS_NAME, opts_TEST_RUNS_NAME); // @since 2.0 DBObject idx_TEST_RUNS_UNIQUE_TEST_NAME = BasicDBObjectBuilder.start(FIELD_TEST, 1).add(FIELD_NAME, 1) .get(); DBObject opts_TEST_RUNS_UNIQUE_TEST_NAME = BasicDBObjectBuilder.start() .add("name", "TEST_RUNS_UNIQUE_TEST_NAME").add("unique", Boolean.TRUE).get(); testRuns.createIndex(idx_TEST_RUNS_UNIQUE_TEST_NAME, opts_TEST_RUNS_UNIQUE_TEST_NAME); // @since 2.0 DBObject idx_TEST_RUNS_TEST_STATE_SCHEDULED = BasicDBObjectBuilder.start(FIELD_TEST, 1).add(FIELD_STATE, 1) .add(FIELD_SCHEDULED, 1).get(); DBObject opts_TEST_RUNS_TEST_STATE_SCHEDULED = BasicDBObjectBuilder.start() .add("name", "TEST_RUNS_TEST_STATE_SCHEDULED").add("unique", Boolean.FALSE).get(); testRuns.createIndex(idx_TEST_RUNS_TEST_STATE_SCHEDULED, opts_TEST_RUNS_TEST_STATE_SCHEDULED); // @since 2.0 DBObject idx_TEST_PROPS_UNIQUE_TEST_NAME = BasicDBObjectBuilder.start(FIELD_TEST, 1).add(FIELD_RUN, 1) .add(FIELD_NAME, 1).get(); DBObject opts_TEST_PROPS_UNIQUE_TEST_NAME = BasicDBObjectBuilder.start() .add("name", "TEST_PROPS_UNIQUE_TEST_NAME").add("unique", Boolean.TRUE).get(); testProps.createIndex(idx_TEST_PROPS_UNIQUE_TEST_NAME, opts_TEST_PROPS_UNIQUE_TEST_NAME); }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Retrieve the data for given test/*w w w.java2 s . c o m*/ * * @param testObjId * the ID of the test * @param includeProperties * <tt>true</tt> to flesh out the properties * @return the test object or <tt>null</tt> if not found */ public DBObject getTest(ObjectId testObjId, boolean includeProperties) { DBObject queryObj = QueryBuilder.start(FIELD_ID).is(testObjId).get(); BasicDBObjectBuilder fieldsObjBuilder = BasicDBObjectBuilder.start(FIELD_NAME, 1).add(FIELD_VERSION, true) .add(FIELD_DESCRIPTION, true).add(FIELD_RELEASE, true).add(FIELD_SCHEMA, true); DBObject fieldsObj = fieldsObjBuilder.get(); DBObject testObj = tests.findOne(queryObj, fieldsObj); if (testObj == null) { // The test run no longer exists logger.warn("Test not found. Returning null test: " + testObjId); return null; } BasicDBList propsList = new BasicDBList(); if (includeProperties) { // Get the associated test definition String test = (String) testObj.get(FIELD_NAME); String release = (String) testObj.get(FIELD_RELEASE); Integer schema = (Integer) testObj.get(FIELD_SCHEMA); TestDefEntry testDefEntry = getTestDefCached(release, schema); if (testDefEntry == null) { // Again, we don't bother trying to resolve this logger.warn("Test definition not found for test: " + testObj); logger.warn("Deleting test without a test definition: " + testObj); this.deleteTest(test); return null; } else { // Start with the properties from the test definition Map<String, DBObject> propsMap = new HashMap<String, DBObject>(testDefEntry.testDefPropsMap); // Fetch the properties for the test DBCursor testPropsCursor = getTestPropertiesRaw(testObjId, null); // Combine MongoTestDAO.mergeProperties(propsMap, testPropsCursor); // Turn into a map and add back into the object propsList = MongoTestDAO.getPropertyList(propsMap); testObj.put(FIELD_PROPERTIES, propsList); } } // Done if (logger.isDebugEnabled()) { logger.debug("Found test: " + testObj); } return testObj; }
From source file:org.alfresco.bm.test.mongo.MongoTestDAO.java
License:Open Source License
/** * Fetch masked property names (passwords) by test name. * /*from w w w . j a v a2 s . co m*/ * @param testName * (String, mandatory) test name * * @return (Set<String>) or exception * * @throws ObjectNotFoundException * @since 2.1.2 */ public Set<String> getMaskedProperyNames(String testName) throws ObjectNotFoundException { ArgumentCheck.checkMandatoryString(testName, "testName"); DBObject queryObj = QueryBuilder.start().and(FIELD_NAME).is(testName).get(); BasicDBObjectBuilder fieldsObjBuilder = BasicDBObjectBuilder.start(FIELD_RELEASE, true).add(FIELD_SCHEMA, true); DBObject testObj = tests.findOne(queryObj, fieldsObjBuilder.get()); ObjectNotFoundException.checkObject(testObj, testName); return getMaskedProperyNames((String) testObj.get(FIELD_RELEASE), (Integer) testObj.get(FIELD_SCHEMA)); }