Example usage for com.mongodb BasicDBObject BasicDBObject

List of usage examples for com.mongodb BasicDBObject BasicDBObject

Introduction

In this page you can find the example usage for com.mongodb BasicDBObject BasicDBObject.

Prototype

public BasicDBObject(final Map map) 

Source Link

Document

Creates an object from a map.

Usage

From source file:bd.DSession.java

@Override
public String insertar(Object o) {
    CSession x = (CSession) o;/*from  w  w w  .  j  a  v a2s  .c  o  m*/

    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().insert(datos);
    con.end();
    return datos.getString("_id");
}

From source file:bd.DSession.java

@Override
public String modificar(Object o) {
    CSession x = (CSession) o;/*from  ww w. jav  a  2  s  .c o  m*/
    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().update(new BasicDBObject("_id", x.getId()), datos);
    con.end();
    return x.getId().toString();
}

From source file:bd.DSession.java

@Override
public ArrayList listar(HashMap map) {
    ArrayList datos = new ArrayList();
    CSession x = new CSession();
    conecion con = new conecion(table);
    BasicDBObject id = new BasicDBObject(map);
    DBCursor cursor = con.get_colletion().find(id);

    try {/*  w w w . ja  v  a 2s.  c o m*/
        while (cursor.hasNext()) {
            x = new CSession();
            x.set_datos((HashMap) cursor.next().toMap());
            datos.add(x);
        }
    } finally {
        cursor.close();
    }
    con.end();

    return datos;
}

From source file:bd.DVenta.java

@Override
public String insertar(Object o) {
    CVenta x = (CVenta) o;/*from   w  w  w .j  a v a2s .c om*/

    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().insert(datos);
    con.end();
    return datos.getString("_id");
}

From source file:bd.DVenta.java

@Override
public String modificar(Object o) {
    CVenta x = (CVenta) o;// ww  w . j av  a 2 s .  c  o  m
    String ver = verificar(x);
    if (ver.compareTo(MSG_ACEPTADO) != 0)
        return ver;

    conecion con = new conecion(table);
    BasicDBObject datos = new BasicDBObject(x.get_datos());
    con.get_colletion().update(new BasicDBObject("_id", x.getId()), datos);
    con.end();
    return x.getId().toString();
}

From source file:bd.DVenta.java

@Override
public ArrayList listar(HashMap map) {
    ArrayList datos = new ArrayList();
    CVenta x = new CVenta();
    conecion con = new conecion(table);
    BasicDBObject id = new BasicDBObject(map);
    DBCursor cursor = con.get_colletion().find(id);

    try {//from  www  . j a  va 2s .  c o m
        while (cursor.hasNext()) {
            x = new CVenta();
            x.set_datos((HashMap) cursor.next().toMap());
            datos.add(x);
        }
    } finally {
        cursor.close();
    }
    con.end();

    return datos;
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String addByMap(String tableName, Map columns) {
    if (tableName == null || tableName.equals("") || columns == null || columns.equals("")) {
        return "501";
    }//from  w  w  w  .  j a  va2 s  .  co  m
    DBCollection table = db.getCollection(tableName);
    BasicDBObject document = new BasicDBObject(columns);
    WriteResult wRes = table.insert(document);
    return ((ObjectId) document.get("_id")).toString();
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String addDefaultMap(String tableName, Map columns) {
    if (tableName == null || tableName.equals("") || columns == null || columns.equals("")) {
        return "501";
    }//  www .j a  v  a  2  s .  co  m
    columns.put("status", "active");
    columns.put("createDate", System.currentTimeMillis() + "");
    columns.put("updateDate", System.currentTimeMillis() + "");
    DBCollection table = db.getCollection(tableName);
    BasicDBObject document = new BasicDBObject(columns);
    WriteResult wRes = table.insert(document);
    return ((ObjectId) document.get("_id")).toString();
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public String getByCondition(String tableName, Map condition) {
    if (tableName == null || tableName.equals("") || condition == null || condition.equals("")) {
        return "501";
    }/* w  w w  .j  a v a2  s.c  om*/
    String row = "";
    DBCollection table = db.getCollection(tableName);
    BasicDBObject searchQuery = new BasicDBObject(condition);
    BasicDBObject andQuery = new BasicDBObject();
    andQuery.put("$and", searchQuery);
    DBCursor cursor = table.find(searchQuery);
    if (cursor.size() > 0) {
        JSON json = new JSON();
        row = json.serialize(cursor);
        cursor.close();
        return row;
    } else {
        cursor.close();
        return null;
    }
}

From source file:br.ufabc.impress.mongo.manager.DBHelper.java

@Override
public boolean modifyByCondition(String tableName, String json, Map condition) {
    if (tableName == null || tableName.equals("") || json == null || json.equals("") || condition == null
            || condition.isEmpty()) {/*w w w  . j  a v  a2  s  .com*/
        return false;
    }
    DBCollection table = db.getCollection(tableName);
    BasicDBObject searchQuery = new BasicDBObject(condition);
    DBObject dbObject = (DBObject) JSON.parse(json);
    dbObject.put("update", System.currentTimeMillis() + "");
    WriteResult result = table.update(searchQuery, dbObject);
    return result.isUpdateOfExisting();
}