List of usage examples for com.mongodb BasicDBObjectBuilder append
public BasicDBObjectBuilder append(final String key, final Object val)
From source file:com.packages.mongodb.converter.automobileconverter.java
public static DBObject toDBObject(automobile p) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("address", p.getaddress()) .append("email", p.getemail()).append("type", p.gettype()).append("comment", p.getcomments()) .append("name", p.getname()).append("dealer", p.getdealer()).append("phone", p.getphone()) .append("brand", p.getbrand()); if (p.getid() != null) builder = builder.append("_id", new ObjectId(p.getid())); return builder.get(); }
From source file:com.packages.mongodb.converter.hotelconverter.java
public static DBObject toDBObject(hotels p) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("address", p.getaddress()) .append("email", p.getemail()).append("rating", p.getrating()).append("message", p.getmessage()) .append("name", p.getname()).append("budget", p.getbudget()).append("phone", p.getphone()); if (p.getid() != null) builder = builder.append("_id", new ObjectId(p.getid())); return builder.get(); }
From source file:com.packages.mongodb.converter.individualconverter.java
public static DBObject toDBObject(individual p) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("area", p.getarea()) .append("city", p.getcity()).append("first_name", p.getfirst_name()) .append("houseno", p.gethouseno()).append("last_name", p.getlast_name()) .append("image", p.getimage()).append("email", p.getemail()).append("phone_no", p.getphone_no()) .append("pincode", p.getpincode()); if (p.getid() != null) builder = builder.append("_id", new ObjectId(p.getid())); return builder.get(); }
From source file:converter.OfferConverter.java
public static DBObject toDBObject(Offer of) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("address", of.getAddress()) .append("lat", of.getLatitude()).append("long", of.getLongitude()).append("type", of.getType()) .append("price", of.getPrice()).append("link", of.getLink()).append("rooms", of.getRooms()) .append("floor", of.getFloor()).append("m2", of.getM2()); if (of.getId() != null) { builder = builder.append("_id", new ObjectId(of.getId())); }//from w w w. j a v a2s . co m return builder.get(); }
From source file:converter.SquareConverter.java
public static DBObject toDBObject(Square s) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("lat", s.getLatitude()) .append("long", s.getLongitude()).append("atm", AtmConverter.toDBObject(s.getNearestAtm())) .append("supermarket", SupermarketConverter.toDBObject(s.getNearestSupermarket())) .append("doctor", DoctorConverter.toDBObject(s.getNearestDoctor())) .append("kindergarten", KindergartenConverter.toDBObject(s.getNearestKindergarten())) .append("pollution", PollutionConverter.toDBObject(s.getPollution())); if (s.getId() != null) builder = builder.append("_id", new ObjectId(s.getId())); return builder.get(); }
From source file:fr.ensimag.biblio.converter.UserConverter.java
public static DBObject toDBObject(User user) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start().append("lastName", user.getLastName()) .append("firstName", user.getFirstName()).append("login", user.getLogin()) .append("password", user.getPassword()).append("isMale", user.getIsMale()) .append("age", user.getAge()).append("town", user.getTown()); if (user.getId() != null) builder = builder.append("_id", new ObjectId(user.getId())); return builder.get(); }
From source file:mongocrud.AddWindow.java
private static DBObject create(Student s) { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); builder.append("name", s.getName()); builder.append("age", s.getAge()); builder.append("_id", s.getId()); return builder.get(); }
From source file:net.tbnr.gearz.arena.ArenaManager.java
License:Open Source License
/** * Converts an Arena object into a DB Object that can be reversed using the other method (which is not static) * * @param arena The arena to convert into a DBObject * @return The DBObject version of this Arena. *//*from w ww . j a v a 2s . c om*/ public static DBObject objectFromArena(Arena arena) { BasicDBObjectBuilder objectBuilder = new BasicDBObjectBuilder(); //Start building the database object for this arena for (Field field : arena.getClass().getFields()) { //Get all the fields ... if (!field.isAnnotationPresent(ArenaField.class)) { continue; //... that we can access, and are annotated by ArenaField ... } ArenaField annotation = field.getAnnotation(ArenaField.class); //Get the Annotation from the field as an object ArenaIterator iterator; //Setup an object to put the iterator in try { iterator = (ArenaIterator) field.get(arena); //Try to getSetting the arena iterator } catch (IllegalAccessException e) { continue; //Didn't work :o } BasicDBList list = new BasicDBList(); //Pour our list into the DB List object while (iterator.hasNext()) { Object next = iterator.next(); ArenaFieldSerializer.SerializationDelegate<?> serializerFor = ArenaFieldSerializer .getSerializerFor(next.getClass()); if (serializerFor == null) continue; list.add(serializerFor.getObjectFor(next)); //Add whatever "next" is now. Depending on code above, it could be a DBObject, or whatever the iterator has in store. } objectBuilder.append(annotation.key(), list); //Put that in the database } objectBuilder.append("name", arena.getName()); //Meta for a bit. objectBuilder.append("description", arena.getDescription()); objectBuilder.append("worldId", arena.getWorldId()); objectBuilder.append("last-updated", Calendar.getInstance().getTimeInMillis()); objectBuilder.append("author", arena.getAuthors()); if (arena.getId() != null) { objectBuilder.append("_id", new ObjectId(arena.getId())); //Good for replacing/updating } return objectBuilder.get(); //Finish the object off! :D }
From source file:org.alfresco.serializers.JSON.java
License:Open Source License
public DBObject makeDBObject() { BasicDBObjectBuilder builder = BasicDBObjectBuilder.start(); for (Map.Entry<String, Object> entry : map.entrySet()) { builder.append(entry.getKey(), entry.getValue()); }/*from w w w . j a v a 2 s . c o m*/ return builder.get(); }
From source file:org.alfresco.serializers.PropertySerializer.java
License:Open Source License
private void makeNodePropertyValue(PropertyDefinition propertyDef, Serializable value, BasicDBObjectBuilder builder) { String propName = propertyDef.getName().toPrefixString(namespaceService); PropertyValue propertyValue = nodePropertyHelper.makeNodePropertyValue(propertyDef, value); switch (propertyValue.getPersistedValueType()) { case NULL://from w ww . j ava2 s . c o m break; case BOOLEAN: boolean boolValue = propertyValue.getBooleanValue(); builder.append(propName, boolValue); break; case LONG: long longValue = propertyValue.getLongValue(); builder.append(propName, longValue); break; case FLOAT: float floatValue = propertyValue.getFloatValue(); builder.append(propName, floatValue); break; case DOUBLE: double doubleValue = propertyValue.getDoubleValue(); builder.append(propName, doubleValue); break; case STRING: String stringValue = propertyValue.getStringValue(); builder.append(propName, stringValue); break; case JSONOBJECT: JSON json = propertyValue.getJSON(); DBObject builder1 = json.makeDBObject(); builder.append(propName, builder1); break; // case FIXED_POINT: // ret = propertyValue.getJSON(); // break; case SERIALIZABLE: // TODO // Serializable s = propertyValue.getSerializableValue(); // byte[] b = SerializationUtils.serialize(s); // ret = files.createFile(nodeId, nodeVersion, propertyQName.toString(), b); break; default: throw new AlfrescoRuntimeException("Unrecognised value type: " + propertyValue.getPersistedType()); } }