use of com.mysql.cj.xdevapi.DatabaseObject.DbObjectType in project aws-mysql-jdbc by awslabs.
the class MysqlxSessionTest method testGetObjects.
@Test
public void testGetObjects() {
assumeTrue(this.isSetForXTests, PropertyDefinitions.SYSP_testsuite_url_mysqlx + " must be set to run this test.");
XMessageBuilder builder = (XMessageBuilder) this.session.<XMessage>getMessageBuilder();
ValueFactory<String> svf = new StringValueFactory(new DefaultPropertySet());
String collName = "test_get_objects";
try {
this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
} catch (XProtocolError e) {
if (e.getErrorCode() != MysqlErrorNumbers.ER_BAD_TABLE_ERROR) {
throw e;
}
}
this.session.query(builder.buildCreateCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
Set<String> strTypes = Arrays.stream(new DbObjectType[] { DbObjectType.COLLECTION }).map(DatabaseObject.DbObjectType::toString).collect(Collectors.toSet());
Predicate<com.mysql.cj.result.Row> rowFiler = r -> (strTypes).contains(r.getValue(1, svf));
Function<com.mysql.cj.result.Row, String> rowToName = r -> r.getValue(0, svf);
List<String> collNames = this.session.query(builder.buildListObjects(getTestDatabase(), null), rowFiler, rowToName, Collectors.toList());
assertTrue(collNames.contains(collName));
collNames = this.session.query(builder.buildListObjects(getTestDatabase(), "none%"), rowFiler, rowToName, Collectors.toList());
assertFalse(collNames.contains(collName));
collNames = this.session.query(builder.buildListObjects(getTestDatabase(), "%get_obj%"), rowFiler, rowToName, Collectors.toList());
assertTrue(collNames.contains(collName));
this.session.query(builder.buildDropCollection(getTestDatabase(), collName), new UpdateResultBuilder<>());
}
Aggregations