use of com.mongodb.client.MongoCollection in project MyPet by xXKeyleXx.
the class MongoDbRepository method updateMyPet.
@SuppressWarnings("unchecked")
private boolean updateMyPet(StoredMyPet storedMyPet) {
MongoCollection petCollection = db.getCollection(Configuration.Repository.MongoDB.PREFIX + "pets");
Document filter = new Document("uuid", storedMyPet.getUUID().toString());
Document petDocument = (Document) petCollection.find(filter).first();
if (petDocument == null) {
return false;
}
petDocument.append("uuid", storedMyPet.getUUID().toString());
petDocument.append("owner_uuid", storedMyPet.getOwner().getInternalUUID().toString());
petDocument.append("exp", storedMyPet.getExp());
petDocument.append("health", storedMyPet.getHealth());
petDocument.append("respawn_time", storedMyPet.getRespawnTime());
petDocument.append("name", storedMyPet.getPetName());
petDocument.append("type", storedMyPet.getPetType().name());
petDocument.append("last_used", storedMyPet.getLastUsed());
petDocument.append("hunger", storedMyPet.getSaturation());
petDocument.append("world_group", storedMyPet.getWorldGroup());
petDocument.append("wants_to_spawn", storedMyPet.wantsToRespawn());
petDocument.append("skilltree", storedMyPet.getSkilltree() != null ? storedMyPet.getSkilltree().getName() : null);
try {
petDocument.append("skills", TagStream.writeTag(storedMyPet.getSkillInfo(), true));
petDocument.append("info", TagStream.writeTag(storedMyPet.getInfo(), true));
} catch (IOException e) {
e.printStackTrace();
}
petCollection.replaceOne(filter, petDocument);
return true;
}
use of com.mongodb.client.MongoCollection in project MyPet by xXKeyleXx.
the class MongoDbRepository method updateToV3.
private void updateToV3() {
MongoCollection playerCollection = db.getCollection(Configuration.Repository.MongoDB.PREFIX + "players");
playerCollection.dropIndex(new BasicDBObject("offline_uuid", 1));
playerCollection.createIndex(new BasicDBObject("name", 1));
}
use of com.mongodb.client.MongoCollection in project MyPet by xXKeyleXx.
the class MongoDbRepository method init.
@Override
@SuppressWarnings("unchecked")
public void init() throws RepositoryInitException {
connect();
if (!collectionExists(Configuration.Repository.MongoDB.PREFIX + "info")) {
initStructure();
} else {
MongoCollection infoCollection = db.getCollection(Configuration.Repository.MongoDB.PREFIX + "info");
Document info = (Document) infoCollection.find().first();
updateStructure(info.getInteger("version"));
}
updateInfo();
}
use of com.mongodb.client.MongoCollection in project beam by apache.
the class MongoDbReadWriteIT method testProjectPushDown.
@Test
public void testProjectPushDown() {
final Schema expectedSchema = Schema.builder().addNullableField("c_varchar", STRING).addNullableField("c_boolean", BOOLEAN).addNullableField("c_integer", INT32).build();
Row testRow = row(expectedSchema, "varchar", true, 2147483647);
String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + " c_bigint BIGINT, \n " + " c_tinyint TINYINT, \n" + " c_smallint SMALLINT, \n" + " c_integer INTEGER, \n" + " c_float FLOAT, \n" + " c_double DOUBLE, \n" + " c_boolean BOOLEAN, \n" + " c_varchar VARCHAR, \n " + " c_arr ARRAY<VARCHAR> \n" + ") \n" + "TYPE 'mongodb' \n" + "LOCATION '" + mongoSqlUrl + "'";
sqlEnv.executeDdl(createTableStatement);
String insertStatement = "INSERT INTO TEST VALUES (" + "9223372036854775807, " + "127, " + "32767, " + "2147483647, " + "1.0, " + "1.0, " + "TRUE, " + "'varchar', " + "ARRAY['123', '456']" + ")";
BeamRelNode insertRelNode = sqlEnv.parseQuery(insertStatement);
BeamSqlRelUtils.toPCollection(writePipeline, insertRelNode);
writePipeline.run().waitUntilFinish();
BeamRelNode node = sqlEnv.parseQuery("select c_varchar, c_boolean, c_integer from TEST");
// Calc should be dropped, since MongoDb supports project push-down and field reordering.
assertThat(node, instanceOf(BeamPushDownIOSourceRel.class));
// Only selected fields are projected.
assertThat(node.getRowType().getFieldNames(), containsInAnyOrder("c_varchar", "c_boolean", "c_integer"));
PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, node);
assertThat(output.getSchema(), equalTo(expectedSchema));
PAssert.that(output).containsInAnyOrder(testRow);
readPipeline.run().waitUntilFinish();
MongoDatabase db = client.getDatabase(database);
MongoCollection coll = db.getCollection("system.profile");
// Find the last executed query.
Object query = coll.find().filter(Filters.eq("op", "query")).sort(new BasicDBObject().append("ts", -1)).iterator().next();
// Retrieve a projection parameters.
assertThat(query, instanceOf(Document.class));
Object command = ((Document) query).get("command");
assertThat(command, instanceOf(Document.class));
Object projection = ((Document) command).get("projection");
assertThat(projection, instanceOf(Document.class));
// Validate projected fields.
assertThat(((Document) projection).keySet(), containsInAnyOrder("c_varchar", "c_boolean", "c_integer"));
}
use of com.mongodb.client.MongoCollection in project beam by apache.
the class MongoDbReadWriteIT method testPredicatePushDown.
@Test
public void testPredicatePushDown() {
final Document expectedFilter = new Document().append("$or", ImmutableList.of(new Document("c_varchar", "varchar"), new Document("c_varchar", new Document("$not", new Document("$eq", "fakeString")))).asList()).append("c_boolean", true).append("c_integer", 2147483647);
final Schema expectedSchema = Schema.builder().addNullableField("c_varchar", STRING).addNullableField("c_boolean", BOOLEAN).addNullableField("c_integer", INT32).build();
Row testRow = row(expectedSchema, "varchar", true, 2147483647);
String createTableStatement = "CREATE EXTERNAL TABLE TEST( \n" + " c_bigint BIGINT, \n " + " c_tinyint TINYINT, \n" + " c_smallint SMALLINT, \n" + " c_integer INTEGER, \n" + " c_float FLOAT, \n" + " c_double DOUBLE, \n" + " c_boolean BOOLEAN, \n" + " c_varchar VARCHAR, \n " + " c_arr ARRAY<VARCHAR> \n" + ") \n" + "TYPE 'mongodb' \n" + "LOCATION '" + mongoSqlUrl + "'";
sqlEnv.executeDdl(createTableStatement);
String insertStatement = "INSERT INTO TEST VALUES (" + "9223372036854775807, " + "127, " + "32767, " + "2147483647, " + "1.0, " + "1.0, " + "TRUE, " + "'varchar', " + "ARRAY['123', '456']" + ")";
BeamRelNode insertRelNode = sqlEnv.parseQuery(insertStatement);
BeamSqlRelUtils.toPCollection(writePipeline, insertRelNode);
writePipeline.run().waitUntilFinish();
BeamRelNode node = sqlEnv.parseQuery("select c_varchar, c_boolean, c_integer from TEST" + " where (c_varchar='varchar' or c_varchar<>'fakeString') and c_boolean and c_integer=2147483647");
// Calc should be dropped, since MongoDb can push-down all predicate operations from a query
// above.
assertThat(node, instanceOf(BeamPushDownIOSourceRel.class));
// Only selected fields are projected.
assertThat(node.getRowType().getFieldNames(), containsInAnyOrder("c_varchar", "c_boolean", "c_integer"));
PCollection<Row> output = BeamSqlRelUtils.toPCollection(readPipeline, node);
assertThat(output.getSchema(), equalTo(expectedSchema));
PAssert.that(output).containsInAnyOrder(testRow);
readPipeline.run().waitUntilFinish();
MongoDatabase db = client.getDatabase(database);
MongoCollection coll = db.getCollection("system.profile");
// Find the last executed query.
Object query = coll.find().filter(Filters.eq("op", "query")).sort(new BasicDBObject().append("ts", -1)).iterator().next();
// Retrieve a projection parameters.
assertThat(query, instanceOf(Document.class));
Object command = ((Document) query).get("command");
assertThat(command, instanceOf(Document.class));
Object filter = ((Document) command).get("filter");
assertThat(filter, instanceOf(Document.class));
Object projection = ((Document) command).get("projection");
assertThat(projection, instanceOf(Document.class));
// Validate projected fields.
assertThat(((Document) projection).keySet(), containsInAnyOrder("c_varchar", "c_boolean", "c_integer"));
// Validate filtered fields.
assertThat(((Document) filter), equalTo(expectedFilter));
}
Aggregations