/** * Getter accessor for attribute 'featuresCollection'. * * @return * current value of 'featuresCollection' */ public DBCollection getPropertiesCollection() { if (propertiesCollection == null) { if (mongoClient != null) { createSchema(); } else { throw new IllegalStateException("Cannot initialize Properties collection : no mongo client defined"); } } return propertiesCollection; }
/** * Parameterized constructor with collection. * * @param collection * the collection to set */ public PropertyStoreMongoDB(MongoClient client) { this.mongoClient = client; this.propertiesCollection = getPropertiesCollection(); }
/** * Parameterized constructor with collection. * * @param collection * the collection to set */ public PropertyStoreMongoDB(DBCollection collection, String xmlConfFile) { this(collection); importPropertiesFromXmlFile(xmlConfFile); }
/** {@inheritDoc} */ public void updateProperty(String name, String newValue) { assertPropertyExist(name); readProperty(name).fromString(newValue); DBObject query = BUILDER.getName(name); Object update = BUILDER.getValue(newValue); getPropertiesCollection().update(query, BasicDBObjectBuilder.start(MONGO_SET, update).get()); }
/** {@inheritDoc} */ public void deleteProperty(String name) { assertPropertyExist(name); getPropertiesCollection().remove(BUILDER.getName(name)); }
/** {@inheritDoc} */ public <T> void updateProperty(Property<T> prop) { Util.assertNotNull(prop); // Delete deleteProperty(prop.getName()); // Create createProperty(prop); }
/** {@inheritDoc} */ public <T> void createProperty(Property<T> prop) { if (prop == null) { throw new IllegalArgumentException("Property cannot be null nor empty"); } if (existProperty(prop.getName())) { throw new PropertyAlreadyExistException(prop.getName()); } getPropertiesCollection().save(MAPPER.fromProperty2DBObject(prop)); }
/** {@inheritDoc} */ public Property<?> readProperty(String name) { assertPropertyExist(name); DBObject object = getPropertiesCollection().findOne(BUILDER.getName(name)); return MAPPER.mapProperty(object); }
/** * Parameterized constructor with collection. * * @param collection * the collection to set */ public PropertyStoreMongoDB(MongoClient client, String dbName, String collectionName) { this.mongoClient = client; this.collectionName = collectionName; this.dbName = dbName; this.propertiesCollection = getPropertiesCollection(); }
/** {@inheritDoc} */ public Map<String, Property<?>> readAllProperties() { LinkedHashMap<String, Property<?>> mapP = new LinkedHashMap<String, Property<?>>(); for(DBObject dbObject : getPropertiesCollection().find()) { Property<?> prop = MAPPER.mapProperty(dbObject); mapP.put(prop.getName(), prop); } return mapP; }
/** {@inheritDoc} */ public Set<String> listPropertyNames() { Set < String > properties = new HashSet<String>(); for(DBObject dbObject : getPropertiesCollection().find( new BasicDBObject(), new BasicDBObjectBuilder().add(PROPERTY_NAME, true).get())) { properties.add((String) dbObject.get(PROPERTY_NAME)); } return properties; }
/** {@inheritDoc} */ public boolean existProperty(String name) { Util.assertHasLength(name); return 1 == getPropertiesCollection().count(BUILDER.getName(name)); }
/** {@inheritDoc} */ public void clear() { getPropertiesCollection().remove(BasicDBObjectBuilder.start().get()); }