Search in sources :

Example 1 with UpdateResultBuilder

use of com.mysql.cj.xdevapi.UpdateResultBuilder 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<>());
}
Also used : MysqlErrorNumbers(com.mysql.cj.exceptions.MysqlErrorNumbers) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) StreamingDocResultBuilder(com.mysql.cj.xdevapi.StreamingDocResultBuilder) Function(java.util.function.Function) MysqlxSession(com.mysql.cj.MysqlxSession) ArrayList(java.util.ArrayList) DatabaseObject(com.mysql.cj.xdevapi.DatabaseObject) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) UpdateResultBuilder(com.mysql.cj.xdevapi.UpdateResultBuilder) Assumptions.assumeTrue(org.junit.jupiter.api.Assumptions.assumeTrue) XMessage(com.mysql.cj.protocol.x.XMessage) DbObjectType(com.mysql.cj.xdevapi.DatabaseObject.DbObjectType) DocFilterParams(com.mysql.cj.xdevapi.DocFilterParams) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) StringValueFactory(com.mysql.cj.result.StringValueFactory) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) Predicate(java.util.function.Predicate) Set(java.util.Set) DocResult(com.mysql.cj.xdevapi.DocResult) Collectors(java.util.stream.Collectors) PropertyDefinitions(com.mysql.cj.conf.PropertyDefinitions) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) Test(org.junit.jupiter.api.Test) IntegerValueFactory(com.mysql.cj.result.IntegerValueFactory) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) FilterParams(com.mysql.cj.xdevapi.FilterParams) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ValueFactory(com.mysql.cj.result.ValueFactory) XMessageBuilder(com.mysql.cj.protocol.x.XMessageBuilder) StringValueFactory(com.mysql.cj.result.StringValueFactory) XProtocolError(com.mysql.cj.protocol.x.XProtocolError) DefaultPropertySet(com.mysql.cj.conf.DefaultPropertySet) DatabaseObject(com.mysql.cj.xdevapi.DatabaseObject) Test(org.junit.jupiter.api.Test)

Aggregations

MysqlxSession (com.mysql.cj.MysqlxSession)1 DefaultPropertySet (com.mysql.cj.conf.DefaultPropertySet)1 PropertyDefinitions (com.mysql.cj.conf.PropertyDefinitions)1 MysqlErrorNumbers (com.mysql.cj.exceptions.MysqlErrorNumbers)1 XMessage (com.mysql.cj.protocol.x.XMessage)1 XMessageBuilder (com.mysql.cj.protocol.x.XMessageBuilder)1 XProtocolError (com.mysql.cj.protocol.x.XProtocolError)1 IntegerValueFactory (com.mysql.cj.result.IntegerValueFactory)1 StringValueFactory (com.mysql.cj.result.StringValueFactory)1 ValueFactory (com.mysql.cj.result.ValueFactory)1 DatabaseObject (com.mysql.cj.xdevapi.DatabaseObject)1 DbObjectType (com.mysql.cj.xdevapi.DatabaseObject.DbObjectType)1 DocFilterParams (com.mysql.cj.xdevapi.DocFilterParams)1 DocResult (com.mysql.cj.xdevapi.DocResult)1 FilterParams (com.mysql.cj.xdevapi.FilterParams)1 StreamingDocResultBuilder (com.mysql.cj.xdevapi.StreamingDocResultBuilder)1 UpdateResultBuilder (com.mysql.cj.xdevapi.UpdateResultBuilder)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1