Example usage for com.mongodb BasicDBList BasicDBList

List of usage examples for com.mongodb BasicDBList BasicDBList

Introduction

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

Prototype

BasicDBList

Source Link

Usage

From source file:ch.qos.logback.contrib.mongodb.MongoDBLoggingEventAppender.java

License:Open Source License

private BasicDBList toDocument(StackTraceElement[] callerData) {
    final BasicDBList dbList = new BasicDBList();
    for (final StackTraceElement ste : callerData) {
        dbList.add(new BasicDBObject().append("file", ste.getFileName()).append("class", ste.getClassName())
                .append("method", ste.getMethodName()).append("line", ste.getLineNumber())
                .append("native", ste.isNativeMethod()));
    }/*from   w  w  w.  ja  va2  s  .co m*/
    return dbList;
}

From source file:cl.wsconsulta.servlet.ConsultaServlet.java

public static String consultar(String consulta) throws FileNotFoundException, IOException {

    DB database;/* ww  w. j  a v a2s.co m*/

    database = null;

    dataBase = "labsd";
    indiceInvertido = "prueba.xml";
    coleccionDocumentos = "documentos";
    coleccionIndice = "indiceInvertido";

    MongoClient mongoClient = new MongoClient();
    database = mongoClient.getDB(dataBase);

    DBCollection indiceInvertido = database.getCollection(coleccionIndice);
    DBCollection documento = database.getCollection(coleccionDocumentos);
    BasicDBList privileges = new BasicDBList();

    BasicDBObject query = new BasicDBObject("palabra", consulta);
    DBCursor cursor = indiceInvertido.find(query);
    if (cursor.count() == 0) {
        System.out.println("Busqueda sin resultados: " + consulta);
    } else {
        while (cursor.hasNext()) {

            privileges = (BasicDBList) cursor.next().get("documento");

            //DBObject obj = cursor.next();
            //Object value = obj.get("documento");
            //System.out.println(value);
        }
    }
    String lista = privileges.toString();
    return lista;

}

From source file:co.dewald.log.MongoDBAppender.java

License:Open Source License

/**
 * @param event// w w  w. j av a  2  s.  c om
 */
protected void append(LoggingEvent event) {
    try {
        if (!init())
            return;

        BasicDBObject log = new BasicDBObject("timestamp", new Date(event.timeStamp));
        log.append("logger", event.getLoggerName());
        log.append("level", event.getLevel().toString());
        log.append("thread", event.getThreadName());
        log.append("message", event.getRenderedMessage());

        if (event.getLocationInformation() != null) {
            LocationInfo info = event.getLocationInformation();

            log.append("file", info.getFileName());
            log.append("line", info.getLineNumber());
            log.append("class", info.getClassName());
            log.append("method", info.getMethodName());
        }

        if (event.getThrowableInformation() != null) {
            ThrowableInformation info = event.getThrowableInformation();
            BasicDBList throwable = new BasicDBList();

            throwable.addAll(Arrays.asList(info.getThrowableStrRep()));
            log.append("throwable", throwable);
        }

        if (event.getNDC() != null)
            log.append("ndc", event.getNDC());

        try {
            event.getMDCCopy();
            @SuppressWarnings("rawtypes")
            Map properties = event.getProperties();

            if (properties != null && !properties.isEmpty()) {
                log.append("mdc", new BasicDBObject(properties));
            }
        } catch (NoSuchMethodError backwardsCompatible) {
            backwardsCompatible.printStackTrace();
        }

        this.logs.insert(log);
    } catch (Throwable irony) {
        irony.printStackTrace();
    }
}

From source file:com.AlertMailerWebPage.servlet.Save.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from   ww w . j  a  v  a  2 s .c  o  m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        Properties defaultProps = new Properties();
        InputStream in = GetProcessSpeed.class.getResourceAsStream("configuration.properties");
        defaultProps.load(in);
        in.close();
        String database = (String) defaultProps.get("database_mailerDetails");
        String collection = (String) defaultProps.get("collection_mailerDetails");
        String serverAddress = (String) defaultProps.get("IP_AMDBoard");

        String relaxation = request.getParameter("relaxation2");
        String alertmailer = request.getParameter("alertmailer");
        String SUBJECT_OWNER_NoNMultiStory = request.getParameter("SUBJECT_OWNER_NoNMultiStory2");
        String SUBJECT_NoNOWNER_NoNMultiStory = request.getParameter("SUBJECT_NoNOWNER_NoNMultiStory2");
        //Mongo mongo = new Mongo("localhost", 27017);

        try {
            org.json.JSONArray jj = new JSONArray(relaxation);
            int j = jj.length();
            out.println(j);
            BasicDBList ll1 = new BasicDBList();
            for (int i = 0; i < jj.length(); i++) {
                JSONObject jsonobject = jj.getJSONObject(i);
                BasicDBObject n = (BasicDBObject) JSON.parse(jsonobject.toString());
                ll1.add(n);

                out.println(jsonobject.toString());
            }

            out.println("ok");
            // Document m= Document.parse(relaxation);
            //String o=(String)m;

            String SUBJECT_OWNER_MULTISTORY_RENT = request.getParameter("SUBJECT_OWNER_MULTISTORY_RENT2");

            String vm = request.getParameter("vm2");
            String SUBJECT_NoNOWNER_MULTISTORY_RENT = request.getParameter("SUBJECT_NoNOWNER_MULTISTORY_RENT2");
            String SUBJECT_NoNOWNER_MULTISTORY_RENT_PREHEADER = request
                    .getParameter("SUBJECT_NoNOWNER_MULTISTORY_RENT_PREHEADER2");
            String SUBJECT_OWNER_MULTISTORY_SALE = request.getParameter("SUBJECT_OWNER_MULTISTORY_SALE2");
            String PREHEADER_NoNOWNER_RENT = request.getParameter("PREHEADER_NoNOWNER_RENT2");
            String SUBJECT_NoNOWNER_MULTISTORY_SALE = request.getParameter("SUBJECT_NoNOWNER_MULTISTORY_SALE2");
            String SUBJECT_NoNOWNER_MULTISTORY_SALE_PREHEADER = request
                    .getParameter("SUBJECT_NoNOWNER_MULTISTORY_SALE_PREHEADER2");
            String PREHEADER_NoNOWNER_SALE = request.getParameter("PREHEADER_NoNOWNER_SALE2");
            String noofprops = request.getParameter("noofprops");
            // MongoClient mongoClient = new MongoClient(new ServerAddress(serverAddress,27017));
            MongoClient mongoClient = new MongoClient();

            mongoClient.getDatabase(database).getCollection(collection).insertOne(new Document(
                    //mongoClient.getDatabase("dashboard").getCollection("users").insertOne( new Document(
                    "AlertMailer", alertmailer)
                            .append("InsertTime", Calendar.getInstance().getTimeInMillis())
                            .append("SUBJECT_OWNER_NoNMultiStory",
                                    Arrays.asList(SUBJECT_OWNER_NoNMultiStory.split(",")))
                            .append("SUBJECT_NoNOWNER_NoNMultiStory",
                                    Arrays.asList(SUBJECT_NoNOWNER_NoNMultiStory.split(",")))
                            .append("SUBJECT_OWNER_MULTISTORY_RENT",
                                    Arrays.asList(SUBJECT_OWNER_MULTISTORY_RENT.split(",")))
                            .append("SUBJECT_NoNOWNER_MULTISTORY_RENT",
                                    Arrays.asList(SUBJECT_NoNOWNER_MULTISTORY_RENT.split(",")))
                            .append("SUBJECT_NoNOWNER_MULTISTORY_RENT_PREHEADER",
                                    Arrays.asList(SUBJECT_NoNOWNER_MULTISTORY_RENT_PREHEADER.split(",")))
                            .append("PREHEADER_NoNOWNER_RENT",
                                    Arrays.asList(PREHEADER_NoNOWNER_RENT.split(",")))
                            .append("SUBJECT_OWNER_MULTISTORY_SALE",
                                    Arrays.asList(SUBJECT_OWNER_MULTISTORY_SALE.split(",")))
                            .append("SUBJECT_NoNOWNER_MULTISTORY_SALE",
                                    Arrays.asList(SUBJECT_NoNOWNER_MULTISTORY_SALE.split(",")))
                            .append("SUBJECT_NoNOWNER_MULTISTORY_SALE_PREHEADER",
                                    Arrays.asList(SUBJECT_NoNOWNER_MULTISTORY_SALE_PREHEADER.split(",")))
                            .append("PREHEADER_NoNOWNER_SALE",
                                    Arrays.asList(PREHEADER_NoNOWNER_SALE.split(",")))
                            .append("VM", Arrays.asList(vm.split(","))).append("Relaxation", ll1)
                            .append("NoOfProperties", noofprops));

        } catch (Exception e) {
        }

        RequestDispatcher rd = request.getRequestDispatcher("Page1.html");
        rd.forward(request, response);
    }
}

From source file:com.arquivolivre.mongocom.management.CollectionManager.java

License:Apache License

private BasicDBObject loadDocument(Object document)
        throws SecurityException, InstantiationException, InvocationTargetException, NoSuchMethodException {
    Field[] fields = document.getClass().getDeclaredFields();
    BasicDBObject obj = new BasicDBObject();
    for (Field field : fields) {
        try {//from   w  ww.  ja  va2  s .c  om
            field.setAccessible(true);
            String fieldName = field.getName();
            Object fieldContent = field.get(document);
            if (fieldContent == null && !field.isAnnotationPresent(GeneratedValue.class)) {
                continue;
            }
            if (fieldContent instanceof List) {
                BasicDBList list = new BasicDBList();
                boolean isInternal = field.isAnnotationPresent(Internal.class);
                for (Object item : (List) fieldContent) {
                    if (isInternal) {
                        list.add(loadDocument(item));
                    } else {
                        list.add(item);
                    }
                }
                obj.append(fieldName, list);
            } else if (field.getType().isEnum()) {
                obj.append(fieldName, fieldContent.toString());
            } else if (field.isAnnotationPresent(Reference.class)) {
                obj.append(fieldName, new org.bson.types.ObjectId(save(fieldContent)));
            } else if (field.isAnnotationPresent(Internal.class)) {
                obj.append(fieldName, loadDocument(fieldContent));
            } else if (field.isAnnotationPresent(Id.class) && !fieldContent.equals("")) {
                obj.append(fieldName, reflectId(field));
            } else if (field.isAnnotationPresent(GeneratedValue.class)) {
                Object value = reflectGeneratedValue(field, fieldContent);
                if (value != null) {
                    obj.append(fieldName, value);
                }
            } else if (!field.isAnnotationPresent(ObjectId.class)) {
                obj.append(fieldName, fieldContent);
            } else if (!fieldContent.equals("")) {
                obj.append("_id", new org.bson.types.ObjectId((String) fieldContent));
            }
        } catch (IllegalArgumentException | IllegalAccessException ex) {
            LOG.log(Level.SEVERE, null, ex);
        }
    }
    return obj;
}

From source file:com.arquivolivre.mongocom.management.MongoQuery.java

License:Apache License

/**
 * Set a criteria to the query//from  w w  w .j av  a 2 s  . c o m
 *
 * @param field field name
 * @param value
 * @return the same object instance
 */
public MongoQuery add(String field, Object value) {
    if (value instanceof MongoQuery) {
        MongoQuery q = (MongoQuery) value;
        query.append(field, q.getQuery());
    } else if (value instanceof List) {
        BasicDBList lists = new BasicDBList();
        for (Object item : (List) value) {
            if (item instanceof MongoQuery) {
                MongoQuery q = (MongoQuery) item;
                lists.add(q.getQuery());
                continue;
            }
            lists.add(item);
        }
        query.append(field, lists);
    } else if (field.equals("_id")) {
        query.append(field, new ObjectId((String) value));
    } else {
        query.append(field, value);
    }
    return this;
}

From source file:com.avbravo.ejbjmoordb.mongodb.internal.JavaToDocument.java

@SuppressWarnings("rawtypes")
public Object toDBObjectRecursive(Object object, FieldDescriptor fieldDescriptor,
        List<EmbeddedBeans> embeddedBeansList, List<ReferencedBeans> referencedBeansList) {

    if (object == null) {
        return null;
    }/*ww w  .  j  a va  2 s .  c  o m*/
    if (fieldDescriptor.isArray()) {

        //Test.msg(" isArray");
        if (ReflectionUtils.isSimpleClass(fieldDescriptor.getField().getType().getComponentType())) {
            return fieldDescriptor.getFieldValue(object);
        } else {
            Object[] array = (Object[]) fieldDescriptor.getFieldValue(object);
            BasicDBList fieldObj = new BasicDBList();
            for (Object el : array) {
                fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList));
            }
            return fieldObj;
        }
    } else if (fieldDescriptor.isIterable()) {

        Iterable col = (Iterable) fieldDescriptor.getFieldValue(object);
        BasicDBList fieldObj = new BasicDBList();
        if (col != null) {
            for (Object el : col) {

                if (ReflectionUtils.isSimpleClass(el.getClass())) {

                    fieldObj.add(el);
                } else {

                    if (isEmbedded(fieldDescriptor.getName())) {

                        fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList));
                    } else {
                        if (isReferenced(fieldDescriptor.getName())) {
                            //aris
                            ClassDescriptor classD = cache.get(el.getClass());
                            for (FieldDescriptor fieldDesc : classD.getFields()) {

                                if (fieldDesc.getName().equals(referencedBeans.getField())) {
                                    fieldObj.add(toDocumentReferenced(el, referencedBeans.getField()));
                                }
                            }
                            //aris

                        } else {
                            //Test.msg("..........no es embebido ni referenciado");
                        }
                    }

                }
            }
        }

        return fieldObj;
    } else if (fieldDescriptor.isObject()) {

        ////Test.msg("           fieldDescriptor.isObject()        ");
        if (isEmbedded(fieldDescriptor.getName())) {
            //Embebido
            Object fieldValue = fieldDescriptor.getFieldValue(object);
            if (fieldValue == null) {
                return null;
            }
            DBObject dbObject = new BasicDBObject();
            for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) {
                dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor,
                        embeddedBeansList, referencedBeansList));
            }
            return dbObject;

        } else {

            if (isReferenced(fieldDescriptor.getName())) {
                //Referenciado
                Object fieldValue = fieldDescriptor.getFieldValue(object);
                if (fieldValue == null) {
                    return null;
                }
                DBObject dbObject = new BasicDBObject();
                for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) {

                    if (childDescriptor.getName().equals(referencedBeans.getField())) {
                        dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor,
                                embeddedBeansList, referencedBeansList));
                    }

                }
                return dbObject;

            } else {
                //Test.msg("                     [No es Referenced]");
                new JmoordbException(
                        "@Embedded or @Reference is required for this field " + fieldDescriptor.getName());
                return new BasicDBObject();
            }

        }

    } else if (fieldDescriptor.isMap()) {
        //Test.msg("==========================");
        //Test.msg("fieldDescriptor.isMap()");
        //Test.msg("==========================");
        DBObject dbObject = new BasicDBObject();
        Map map = (Map) fieldDescriptor.getFieldValue(object);
        for (Object key : map.keySet()) {
            Object el = map.get(key);
            if (el == null || ReflectionUtils.isSimpleClass(el.getClass())) {
                dbObject.put(key.toString(), el);
            } else {
                dbObject.put(key.toString(), toDocument(el, embeddedBeansList, referencedBeansList));
            }
        }
        return dbObject;
    } else {
        //valor del atributo que no es otra clase

        return fieldDescriptor.getFieldValue(object);
    }
}

From source file:com.avbravo.jmoordbdianna.mongodb.internal.JavaToDocument.java

@SuppressWarnings("rawtypes")
public Object toDBObjectRecursive(Object object, FieldDescriptor fieldDescriptor,
        List<EmbeddedBeans> embeddedBeansList, List<ReferencedBeans> referencedBeansList) {

    if (object == null) {
        return null;
    }/* www  .  j  a v  a2s  . com*/
    if (fieldDescriptor.isArray()) {

        System.out.println(" isArray");
        if (ReflectionUtils.isSimpleClass(fieldDescriptor.getField().getType().getComponentType())) {
            return fieldDescriptor.getFieldValue(object);
        } else {
            Object[] array = (Object[]) fieldDescriptor.getFieldValue(object);
            BasicDBList fieldObj = new BasicDBList();
            for (Object el : array) {
                fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList));
            }
            return fieldObj;
        }
    } else if (fieldDescriptor.isIterable()) {

        Iterable col = (Iterable) fieldDescriptor.getFieldValue(object);
        BasicDBList fieldObj = new BasicDBList();
        if (col != null) {
            for (Object el : col) {

                if (ReflectionUtils.isSimpleClass(el.getClass())) {

                    fieldObj.add(el);
                } else {

                    if (isEmbedded(fieldDescriptor.getName())) {

                        fieldObj.add(toDocument(el, embeddedBeansList, referencedBeansList));
                    } else {
                        if (isReferenced(fieldDescriptor.getName())) {
                            //aris
                            ClassDescriptor classD = cache.get(el.getClass());
                            for (FieldDescriptor fieldDesc : classD.getFields()) {

                                if (fieldDesc.getName().equals(referencedBeans.getField())) {
                                    fieldObj.add(toDocumentReferenced(el, referencedBeans.getField()));
                                }
                            }
                            //aris

                        } else {
                            System.out.println("..........no es embebido ni referenciado");
                        }
                    }

                }
            }
        }

        return fieldObj;
    } else if (fieldDescriptor.isObject()) {

        //System.out.println("           fieldDescriptor.isObject()        ");
        if (isEmbedded(fieldDescriptor.getName())) {
            //Embebido
            Object fieldValue = fieldDescriptor.getFieldValue(object);
            if (fieldValue == null) {
                return null;
            }
            DBObject dbObject = new BasicDBObject();
            for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) {
                dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor,
                        embeddedBeansList, referencedBeansList));
            }
            return dbObject;

        } else {

            if (isReferenced(fieldDescriptor.getName())) {
                //Referenciado
                Object fieldValue = fieldDescriptor.getFieldValue(object);
                if (fieldValue == null) {
                    return null;
                }
                DBObject dbObject = new BasicDBObject();
                for (FieldDescriptor childDescriptor : fieldDescriptor.getChildren()) {

                    if (childDescriptor.getName().equals(referencedBeans.getField())) {
                        dbObject.put(childDescriptor.getName(), toDBObjectRecursive(fieldValue, childDescriptor,
                                embeddedBeansList, referencedBeansList));
                    }

                }
                return dbObject;

            } else {
                System.out.println("                     [No es Referenced]");
                new JmoordbException(
                        "@Embedded or @Reference is required for this field " + fieldDescriptor.getName());
                return new BasicDBObject();
            }

        }

    } else if (fieldDescriptor.isMap()) {
        System.out.println("==========================");
        System.out.println("fieldDescriptor.isMap()");
        System.out.println("==========================");
        DBObject dbObject = new BasicDBObject();
        Map map = (Map) fieldDescriptor.getFieldValue(object);
        for (Object key : map.keySet()) {
            Object el = map.get(key);
            if (el == null || ReflectionUtils.isSimpleClass(el.getClass())) {
                dbObject.put(key.toString(), el);
            } else {
                dbObject.put(key.toString(), toDocument(el, embeddedBeansList, referencedBeansList));
            }
        }
        return dbObject;
    } else {
        //valor del atributo que no es otra clase

        return fieldDescriptor.getFieldValue(object);
    }
}

From source file:com.bdnc.ecommercebdnc.entidades.CarrinhoDeCompras.java

public Document toDocument() {
    Document doc = new Document("id", id).append("produtos", produtos).append("valorParcial", valorParcial)
            .append("qtdItens", qtdItens);
    BasicDBList produtoList = new BasicDBList();
    for (Produto produto : produtos) {
        produtoList.add(produto.toDocument());
    }/*from  w w  w .j  a  va 2  s  .  com*/
    doc.append("produtos", produtoList);
    return doc;
}

From source file:com.berkgokden.mongodb.MongoMapStore.java

License:Open Source License

public void deleteAll(Collection keys) {
    BasicDBList dbo = new BasicDBList();
    for (Object key : keys) {
        dbo.add(new BasicDBObject("_id", key));
    }// w ww  . j av  a 2 s .c om
    BasicDBObject dbb = new BasicDBObject("$or", dbo);
    coll.remove(dbb);
}