Example usage for com.mongodb.client MongoCursor close

List of usage examples for com.mongodb.client MongoCursor close

Introduction

In this page you can find the example usage for com.mongodb.client MongoCursor close.

Prototype

@Override
    void close();

Source Link

Usage

From source file:com.mycompany.mavenproject2.SelectDeptController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    /*   List<String> values = Arrays.asList("one", "two", "three");
    list.setItems(FXCollections.observableList(values));*/

    /*    String qry="select name from dept_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){                //from   ww  w  . ja v a2 s  .c  om
       List.getItems().addAll(rs.getString("name"));
    }*/

    MongoCursor<Document> cursor4 = db.getCollection("DeptDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            List.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }

}

From source file:com.mycompany.mavenproject2.SelectLocationController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    /*    String qry="select name from location_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){/*w  w  w . jav  a2  s . c  o m*/
                
       List.getItems().addAll(rs.getString("name"));
    }*/

    MongoCursor<Document> cursor4 = db.getCollection("LocationDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");
            List.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

From source file:com.mycompany.mavenproject2.SelectPackController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    /* String qry="select name from pack_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){//w w w. j  a  v a2 s.com
                
       List.getItems().addAll(rs.getString("name"));
    }*/

    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");
            List.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

From source file:com.mycompany.mavenproject2.SelectSizeController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    /*String qry="select name from size_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){/*from  w  w w.j a  v  a2  s.  c  o m*/
                
       List.getItems().addAll(rs.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");
            List.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }

}

From source file:com.mycompany.mavenproject2.SelectUOMController.java

@Override
public void initialize(URL url, ResourceBundle rb) {

    /*String qry="select name from uom_detail";
    java.sql.Connection conn=Connection.getConnect();            
    PreparedStatement pst2=conn.prepareStatement(qry);
    ResultSet rs = pst2.executeQuery(qry);
    while(rs.next()){//  ww w. ja  va2 s .co  m
                
       List.getItems().addAll(rs.getString("name"));
    }*/
    MongoCursor<Document> cursor4 = db.getCollection("UOMDetail").find().iterator();
    try {
        while (cursor4.hasNext()) {

            String rs = cursor4.next().getString("Name");
            List.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }

}

From source file:com.mycompany.mavenproject2.ShortcutController.java

@Override
public void initialize(URL url, ResourceBundle rb) {
    MongoCursor<Document> cursor4 = db.getCollection("PackDetail").find().iterator();
    try {/*from  w  w w.  jav  a 2s . com*/
        while (cursor4.hasNext()) {
            String rs = cursor4.next().getString("Name");
            PackCombo.setValue(rs);
            PackCombo.getItems().addAll(rs);
        }
    } finally {
        cursor4.close();
    }
}

From source file:com.mycompany.mavenproject2.TenderAddController.java

public void InsertMongo() {
    if (GlobalFlag == 1) {
        UpdateMongo();/*from  w w  w  .  jav  a2s.  co  m*/
    } else {
        count = (int) col.count();
        if (count == 0) {
            Document input = createSaleSeedData();
            col.insertOne(input);
        } else {
            sort1 = new BasicDBObject();
            MongoCursor<Document> cursor = col.find().sort(sort1).limit(1).skip((int) count - 1).iterator();
            try {
                while (cursor.hasNext()) {
                    EID = cursor.next().getInteger("ID");
                    System.out.println("last EID " + EID);
                    EID++;
                    System.out.println("Inserted " + EID);
                }
            } finally {
                cursor.close();
            }
            final Document seedData = createSaleSeedData();
            col.insertOne(seedData);
        }
    }
}

From source file:com.mycompany.mavenproject2.TenderAddController.java

public void UpdateMongo() {
    MongoCursor<Document> cursor4 = col.find().iterator();
    try {//  w  w w  .  j  av  a  2s .  c o m
        while (cursor4.hasNext()) {
            System.out.println("ID=> " + cursor4.next().getInteger("ID"));
        }
    } finally {
        cursor4.close();
    }
    System.out.println("Updated Selected _id is " + PID);
    col.updateOne(new Document("ID", PID), new Document("$set", UpdateSeedData()));
    //.append("$currentDate", new Document("lastModified", true)));
    MongoCursor<Document> cursor5 = col.find().iterator();
    try {
        while (cursor5.hasNext()) {
            System.out.println("After UpdateID=> " + cursor5.next().getInteger("ID"));
        }
    } finally {
        cursor5.close();
    }
}

From source file:com.navercorp.pinpoint.plugin.mongodb.MongoDBBase.java

License:Apache License

public void readData(PluginTestVerifier verifier, MongoCollection<Document> collection,
        Class<?> mongoDatabaseImpl) {
    //read data//from   w  w w .j  a  v  a 2  s .  c om
    MongoCursor<Document> cursor = collection.find().iterator();

    Method find;
    try {
        find = mongoDatabaseImpl.getDeclaredMethod("find");
    } catch (NoSuchMethodException e) {
        find = null;
    }

    verifier.verifyTrace(event(MONGO_EXECUTE_QUERY, find, null, MONGODB_ADDRESS, null,
            new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_INFO.getName(), "customers"),
            new ExpectedAnnotation(MongoConstants.MONGO_COLLECTION_OPTION.getName(), "secondaryPreferred")));

    int resultCount = 0;
    try {
        while (cursor.hasNext()) {
            resultCount++;
            cursor.next();
        }
    } finally {
        cursor.close();
    }
    Assert.assertEquals(2, resultCount);
}

From source file:com.px100systems.data.plugin.storage.mongo.MongoDatabaseStorage.java

License:Open Source License

public Map<String, List<String>> getSchema(boolean reset) {
    MongoDatabase db = mongoClient.getDatabase(databaseName);

    Map<String, List<String>> result = new HashMap<>();

    MongoCursor<String> cursor = db.listCollectionNames().iterator();
    try {//from w  ww .ja  va  2 s . com
        while (cursor.hasNext()) {
            String name = cursor.next();
            if (!name.startsWith("system."))
                if (reset)
                    db.getCollection(name).drop();
                else
                    result.put(name, new ArrayList<String>());
        }
    } finally {
        cursor.close();
    }

    for (Map.Entry<String, List<String>> e : result.entrySet()) {
        MongoCursor<Document> idxCursor = db.getCollection(e.getKey()).listIndexes().iterator();
        try {
            while (idxCursor.hasNext()) {
                Document idx = idxCursor.next();
                String indexName = idx.get("name", String.class);
                if (CompoundIndexDescriptor.isCompondIndexName(indexName))
                    e.getValue().add(indexName);
                else {
                    String name = idx.get("key", Document.class).keySet().iterator().next();
                    if (!name.startsWith("_"))
                        e.getValue().add(name);
                }
            }
        } finally {
            idxCursor.close();
        }
    }

    return result;
}