Example usage for com.mongodb DBCursor one

List of usage examples for com.mongodb DBCursor one

Introduction

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

Prototype

@Nullable
public DBObject one() 

Source Link

Document

Returns the first document that matches the query.

Usage

From source file:blowfish.java

public String decrypt(int i) throws InvalidKeyException, IOException {
    String str = null;/*from www.  j  a v  a2 s . c  o m*/
    SecretKey key = null;
    int j;
    int c = 0;
    for (j = 0; j < crypter.indexb.size(); j++) {
        if (crypter.indexb.get(j) == i) {
            c++;
            break;
        }
    }
    if (c == 0) {
        return new String("Wrong Algorithm chosen");
    }
    try {
        Cipher dcipher = Cipher.getInstance("blowfish");
        DBObject query = new BasicDBObject("id", i);
        DBCursor cursor = crypter.collection.find(query);
        str = (String) cursor.one().get("string");
        dcipher.init(Cipher.DECRYPT_MODE, crypter.vecb.get(j));
        byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
        byte[] utf8 = dcipher.doFinal(dec);
        return new String(utf8, "UTF8");
    } catch (BadPaddingException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (UnsupportedEncodingException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (NoSuchPaddingException e) {
    }
    return null;
}

From source file:des.java

public String decrypt(int i) throws InvalidKeyException, IOException {
    String str = null;//from  w  w w  .  ja  va2  s.  c  om
    SecretKey key = null;
    int j;
    int c = 0;
    for (j = 0; j < crypter.indexd.size(); j++) {
        if (crypter.indexd.get(j) == i) {
            c++;
            break;
        }
    }
    if (c == 0) {
        return new String("Wrong Algorithm chosen");
    }
    try {
        Cipher dcipher = Cipher.getInstance("DES");
        DBObject query = new BasicDBObject("id", i);
        DBCursor cursor = crypter.collection.find(query);
        str = (String) cursor.one().get("string");
        dcipher.init(Cipher.DECRYPT_MODE, crypter.vecd.get(j));
        byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
        byte[] utf8 = dcipher.doFinal(dec);
        return new String(utf8, "UTF8");
    } catch (BadPaddingException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (UnsupportedEncodingException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (NoSuchPaddingException e) {
    }
    return null;
}

From source file:twofishc.java

public String decrypt(int i)
        throws InvalidKeyException, IOException, NoSuchProviderException, InvalidAlgorithmParameterException {
    String str = null;// w  ww . j  av  a2s  .  c o m
    SecretKey key = null;
    int j;
    int c = 0;
    for (j = 0; j < crypter.indext.size(); j++) {
        if (crypter.indext.get(j) == i) {
            c++;
            break;
        }
    }
    if (c == 0) {
        return new String("Wrong Algorithm chosen");
    }
    try {
        Cipher dcipher = Cipher.getInstance("Twofish/CBC/PKCS5Padding", "IAIK");
        DBObject query = new BasicDBObject("id", i);
        DBCursor cursor = crypter.collection.find(query);
        str = (String) cursor.one().get("string");
        dcipher.init(Cipher.DECRYPT_MODE, crypter.sks.get(j), crypter.iv.get(j));
        byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
        byte[] utf8 = dcipher.doFinal(dec);
        return new String(utf8, "UTF8");
    } catch (BadPaddingException e) {
    } catch (IllegalBlockSizeException e) {
    } catch (UnsupportedEncodingException e) {
    } catch (NoSuchAlgorithmException e) {
    } catch (NoSuchPaddingException e) {
    }
    return null;
}

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

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//from  w  ww  . j  av a2 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");

        Mongo mongo = new Mongo("localhost", 27017);
        //   Mongo mongo=new Mongo(serverAddress,27017);
        //DB db = mongo.getDB("dashboard" );
        DB db = mongo.getDB(database);

        DBCollection coll = db.getCollection(collection);
        //DBCollection coll=db.getCollection("users");
        DBObject query = new BasicDBObject("AlertMailer", "PRS");
        DBObject query1 = new BasicDBObject("InsertTime", -1);
        //DBObject query = new BasicDBObject("_id",-1);
        DBCursor cursor = coll.find(query).sort(query1).limit(1);

        //String name1= (String)cursor.one().get("name");    
        //while(cursor.hasNext()){
        //    out.println(""+cursor.next()+"");
        //}
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");
        response.getWriter().write(cursor.one().toString());
    }
}

From source file:ezbake.data.mongo.EzMongoHandler.java

License:Apache License

String getCollNameOfPurgeId(long purgeId) {
    String collectionName = null;
    Set purgeIds = new HashSet();
    purgeIds.add(purgeId);//from   w  w w.j ava 2 s.  co  m

    appLog.info("Get Collection Name of Purge Id {} in Purge Tracker Collection", purgeId);
    DBObject query = new BasicDBObject();
    query.put(RedactHelper.APP_ID_FIELD, appId);
    query.put(RedactHelper.PURGE_ID, new BasicDBObject("$in", purgeIds));
    String trackingPurgeCollName = getCollectionName(PURGE_TRACKING_COLL_NAME);
    DBCursor cursor = db.getCollection(trackingPurgeCollName).find(query);
    if (cursor.length() == 1) {
        appLog.info("Found a Record getting collection name");
        collectionName = (String) cursor.one().get(RedactHelper.PURGE_TRACKING_COLL_FIELD);
    }
    appLog.info("getCollNameOfPurgeId, returning Collection Name {}", collectionName);
    return collectionName;
}

From source file:org.jberet.repository.MongoRepository.java

License:Open Source License

@Override
public StepExecutionImpl findOriginalStepExecutionForRestart(final String stepName,
        final JobExecutionImpl jobExecutionToRestart, final ClassLoader classLoader) {
    final StepExecutionImpl result = super.findOriginalStepExecutionForRestart(stepName, jobExecutionToRestart,
            classLoader);/*from  ww  w.  j  a v  a  2  s. co  m*/
    if (result != null) {
        return result;
    }

    final DBObject keys = new BasicDBObject(TableColumns.JOBEXECUTIONID, 1);
    keys.put(TableColumns._id, 0);
    final DBCursor cursor = db.getCollection(TableColumns.JOB_EXECUTION).find(new BasicDBObject(
            TableColumns.JOBINSTANCEID, jobExecutionToRestart.getJobInstance().getInstanceId()), keys);
    final BasicDBList basicDBList = new BasicDBList();
    while (cursor.hasNext()) {
        final DBObject next = cursor.next();
        basicDBList.add(next.get(TableColumns.JOBEXECUTIONID));
    }
    final DBObject inClause = new BasicDBObject("$in", basicDBList);
    final DBObject query = new BasicDBObject(TableColumns.JOBEXECUTIONID, inClause);
    query.put(TableColumns.STEPNAME, stepName);
    final DBCursor cursor1 = db.getCollection(TableColumns.STEP_EXECUTION).find(query)
            .sort(new BasicDBObject(TableColumns.STEPEXECUTIONID, -1));

    return createStepExecutionFromDBObject(cursor1.one(), classLoader);
}