Search in sources :

Example 11 with Database

use of org.molgenis.emx2.Database in project java-spanner by googleapis.

the class GapicSpannerRpc method createDatabase.

@Override
public OperationFuture<Database, CreateDatabaseMetadata> createDatabase(final String instanceName, String createDatabaseStatement, Iterable<String> additionalStatements, com.google.cloud.spanner.Database databaseInfo) throws SpannerException {
    final String databaseId = databaseInfo.getId().getDatabase();
    CreateDatabaseRequest.Builder requestBuilder = CreateDatabaseRequest.newBuilder().setParent(instanceName).setCreateStatement(createDatabaseStatement).addAllExtraStatements(additionalStatements);
    if (databaseInfo.getEncryptionConfig() != null) {
        requestBuilder.setEncryptionConfig(EncryptionConfigProtoMapper.encryptionConfig(databaseInfo.getEncryptionConfig()));
    }
    if (databaseInfo.getDialect() != null) {
        requestBuilder.setDatabaseDialect(databaseInfo.getDialect().toProto());
    }
    final CreateDatabaseRequest request = requestBuilder.build();
    OperationFutureCallable<CreateDatabaseRequest, Database, CreateDatabaseMetadata> callable = new OperationFutureCallable<>(databaseAdminStub.createDatabaseOperationCallable(), request, DatabaseAdminGrpc.getCreateDatabaseMethod(), instanceName, nextPageToken -> listDatabaseOperations(instanceName, 0, String.format("(metadata.@type:type.googleapis.com/%s) AND (name:%s/operations/)", CreateDatabaseMetadata.getDescriptor().getFullName(), String.format("%s/databases/%s", instanceName, databaseId)), nextPageToken), input -> {
        if (input.getDone() && input.hasResponse()) {
            try {
                Timestamp createTime = input.getResponse().unpack(Database.class).getCreateTime();
                if (Timestamp.getDefaultInstance().equals(createTime)) {
                    // method to indicate that there is no known create time.
                    return null;
                }
            } catch (InvalidProtocolBufferException e) {
                return null;
            }
        }
        return null;
    });
    return RetryHelper.runWithRetries(callable, databaseAdminStubSettings.createDatabaseOperationSettings().getInitialCallSettings().getRetrySettings(), new OperationFutureRetryAlgorithm<>(), NanoClock.getDefaultClock());
}
Also used : CreateDatabaseRequest(com.google.spanner.admin.database.v1.CreateDatabaseRequest) Database(com.google.spanner.admin.database.v1.Database) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata) Timestamp(com.google.protobuf.Timestamp)

Example 12 with Database

use of org.molgenis.emx2.Database in project molgenis-emx2 by molgenis.

the class TestEmx2Roles method testRolesIO.

@Test
public void testRolesIO() {
    // create user roles
    schema.addMember("bofke", "Viewer");
    TableStore store = new TableStoreForCsvInMemory();
    // export
    Emx2Members.outputRoles(store, schema);
    // empty the database, verify
    schema = schema.getDatabase().dropCreateSchema(TestEmx2Roles.class.getSimpleName());
    assertEquals(0, schema.getMembers().size());
    // import and see if consistent
    Emx2Members.inputRoles(store, schema);
    List<Member> members = schema.getMembers();
    assertEquals("bofke", members.get(0).getUser());
    assertEquals("Viewer", members.get(0).getRole());
}
Also used : TableStoreForCsvInMemory(org.molgenis.emx2.io.tablestore.TableStoreForCsvInMemory) Member(org.molgenis.emx2.Member) TableStore(org.molgenis.emx2.io.tablestore.TableStore) Test(org.junit.Test)

Example 13 with Database

use of org.molgenis.emx2.Database in project molgenis-emx2 by molgenis.

the class TestEmx2Roles method setup.

@BeforeClass
public static void setup() {
    Database database = TestDatabaseFactory.getTestDatabase();
    schema = database.dropCreateSchema(TestEmx2Roles.class.getSimpleName());
}
Also used : Database(org.molgenis.emx2.Database) BeforeClass(org.junit.BeforeClass)

Example 14 with Database

use of org.molgenis.emx2.Database in project molgenis-emx2 by molgenis.

the class TestImportTableTask method setup.

@BeforeClass
public static void setup() {
    Database database = TestDatabaseFactory.getTestDatabase();
    schema = database.dropCreateSchema(TestImportTableTask.class.getSimpleName());
}
Also used : Database(org.molgenis.emx2.Database) BeforeClass(org.junit.BeforeClass)

Example 15 with Database

use of org.molgenis.emx2.Database in project molgenis-emx2 by molgenis.

the class Benchmark method testCopyInAndOut.

public void testCopyInAndOut() {
    Database database = TestDatabaseFactory.getTestDatabase();
    Schema schema = database.dropCreateSchema(Benchmark.class.getSimpleName());
    int aSize = 50;
    int bSize = 100000;
    Table a = schema.create(table("TableA").add(column("ID").setPkey()));
    List<String> values = new ArrayList<>();
    Table b = schema.create(table("TableB").add(column("ID").setPkey()).add(column("ref").setType(REF_ARRAY).setRefTable("TableA")));
    // Table c =
    // schema.create(
    // table("TableC")
    // .add(column("ID").setPkey())
    // .add(column("ref").setType(MREF).setRefTable("TableA")));
    StopWatch.start("benchmark started");
    List<Row> aRows = new ArrayList<>();
    for (int i = 0; i < aSize; i++) {
        aRows.add(new Row().set("ID", "row" + i));
        values.add("row" + i);
    }
    StopWatch.start("benchmark1");
    a.insert(aRows);
    StopWatch.print("inserted primary", aSize);
    aRows.clear();
    List<Row> bRows = new ArrayList<>();
    for (int i = 0; i < bSize; i++) {
        bRows.add(new Row().set("ID", "row" + i).set("ref", values));
    }
    StopWatch.start("benchmark2 started");
    b.insert(bRows);
    StopWatch.print("inserted ref_array", bSize);
    bRows.clear();
// List<Row> cRows = new ArrayList<>();
// for (int i = 0; i < bSize; i++) {
// cRows.add(new Row().set("ID", "row" + i).set("ref", values));
// }
// StopWatch.start("benchmark3 started");
// c.insert(cRows);
// StopWatch.print("inserted mref", bSize);
// cRows.clear();
// StopWatch.print("inserted mref", bSize);
// ref_array
}
Also used : Table(org.molgenis.emx2.Table) Schema(org.molgenis.emx2.Schema) Database(org.molgenis.emx2.Database) ArrayList(java.util.ArrayList) Row(org.molgenis.emx2.Row)

Aggregations

Test (org.junit.Test)24 Database (com.google.spanner.admin.database.v1.Database)21 Database (org.molgenis.emx2.Database)12 AbstractMessage (com.google.protobuf.AbstractMessage)10 ArrayList (java.util.ArrayList)10 Schema (org.molgenis.emx2.Schema)9 ByteString (com.google.protobuf.ByteString)8 Operation (com.google.longrunning.Operation)7 RestoreDatabaseRequest (com.google.spanner.admin.database.v1.RestoreDatabaseRequest)7 BeforeClass (org.junit.BeforeClass)7 CreateDatabaseRequest (com.google.spanner.admin.database.v1.CreateDatabaseRequest)4 InstanceName (com.google.spanner.admin.database.v1.InstanceName)4 ListDatabasesPagedResponse (com.google.cloud.spanner.admin.database.v1.DatabaseAdminClient.ListDatabasesPagedResponse)3 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)3 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)3 MetadataUtils.deleteColumn (org.molgenis.emx2.sql.MetadataUtils.deleteColumn)3 BackupName (com.google.spanner.admin.database.v1.BackupName)2 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)2 GetDatabaseRequest (com.google.spanner.admin.database.v1.GetDatabaseRequest)2 ListDatabasesRequest (com.google.spanner.admin.database.v1.ListDatabasesRequest)2