Search in sources :

Example 1 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class DevApiSample method main.

public static void main(String[] args) {
    Session session = new SessionFactory().getSession("mysqlx://localhost:33060/test?user=user&password=password1234");
    System.err.println("Connected!");
    Schema schema = session.getDefaultSchema();
    System.err.println("Default schema is: " + schema);
    documentWalkthrough(schema);
}
Also used : SessionFactory(com.mysql.cj.xdevapi.SessionFactory) Schema(com.mysql.cj.xdevapi.Schema) Session(com.mysql.cj.xdevapi.Session)

Example 2 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class SchemaTest method testToString.

@Test
public void testToString() {
    // this will pass as long as the test database doesn't require identifier quoting
    assertEquals("Schema(" + getTestDatabase() + ")", this.schema.toString());
    Schema needsQuoted = this.session.getSchema("terrible'schema`name");
    assertEquals("Schema(`terrible'schema``name`)", needsQuoted.toString());
}
Also used : Schema(com.mysql.cj.xdevapi.Schema) Test(org.junit.jupiter.api.Test)

Example 3 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class SchemaTest method testEquals.

@Test
public void testEquals() {
    Schema otherDefaultSchema = this.session.getDefaultSchema();
    assertFalse(otherDefaultSchema == this.schema);
    assertTrue(otherDefaultSchema.equals(this.schema));
    assertTrue(this.schema.equals(otherDefaultSchema));
    Session otherSession = new SessionImpl(this.testHostInfo);
    Schema diffSessionSchema = otherSession.getDefaultSchema();
    assertEquals(this.schema.getName(), diffSessionSchema.getName());
    assertFalse(this.schema.equals(diffSessionSchema));
    assertFalse(diffSessionSchema.equals(this.schema));
    otherSession.close();
}
Also used : Schema(com.mysql.cj.xdevapi.Schema) SessionImpl(com.mysql.cj.xdevapi.SessionImpl) Session(com.mysql.cj.xdevapi.Session) Test(org.junit.jupiter.api.Test)

Example 4 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class SchemaTest method testExists.

@Test
public void testExists() {
    assertEquals(DbObjectStatus.EXISTS, this.schema.existsInDatabase());
    Schema nonExistingSchema = this.session.getSchema(getTestDatabase() + "_SHOULD_NOT_EXIST_0xCAFEBABE");
    assertEquals(DbObjectStatus.NOT_EXISTS, nonExistingSchema.existsInDatabase());
}
Also used : Schema(com.mysql.cj.xdevapi.Schema) Test(org.junit.jupiter.api.Test)

Example 5 with Schema

use of com.mysql.cj.xdevapi.Schema in project aws-mysql-jdbc by awslabs.

the class SessionTest method createExistingSchemaError.

@Test
public void createExistingSchemaError() {
    String testSchemaName = getRandomTestSchemaName();
    Schema newSchema = this.session.createSchema(testSchemaName);
    assertTrue(this.session.getSchemas().contains(newSchema));
    try {
        this.session.createSchema(testSchemaName);
        fail("Attempt to create a schema with the name of an existing schema should fail");
    } catch (XProtocolError err) {
        assertEquals(MysqlErrorNumbers.ER_DB_CREATE_EXISTS, err.getErrorCode());
    }
}
Also used : XProtocolError(com.mysql.cj.protocol.x.XProtocolError) Schema(com.mysql.cj.xdevapi.Schema) JsonString(com.mysql.cj.xdevapi.JsonString) Test(org.junit.jupiter.api.Test)

Aggregations

Schema (com.mysql.cj.xdevapi.Schema)25 Test (org.junit.jupiter.api.Test)23 JsonString (com.mysql.cj.xdevapi.JsonString)18 Session (com.mysql.cj.xdevapi.Session)18 SessionFactory (com.mysql.cj.xdevapi.SessionFactory)16 Collection (com.mysql.cj.xdevapi.Collection)15 WrongArgumentException (com.mysql.cj.exceptions.WrongArgumentException)14 ExecutionException (java.util.concurrent.ExecutionException)14 DocResult (com.mysql.cj.xdevapi.DocResult)3 DbDoc (com.mysql.cj.xdevapi.DbDoc)2 SessionImpl (com.mysql.cj.xdevapi.SessionImpl)2 XProtocolError (com.mysql.cj.protocol.x.XProtocolError)1 Disabled (org.junit.jupiter.api.Disabled)1