Search in sources :

Example 56 with Database

use of com.google.spanner.admin.database.v1.Database in project java-docs-samples by GoogleCloudPlatform.

the class App method create.

static void create(DatabaseAdminClient dbAdminClient, DatabaseId db) {
    OperationFuture<Database, CreateDatabaseMetadata> op = dbAdminClient.createDatabase(db.getInstanceId().getInstance(), db.getDatabase(), Arrays.asList("CREATE TABLE Players(\n" + "  PlayerId INT64 NOT NULL,\n" + "  PlayerName STRING(2048) NOT NULL\n" + ") PRIMARY KEY(PlayerId)", "CREATE TABLE Scores(\n" + "  PlayerId INT64 NOT NULL,\n" + "  Score INT64 NOT NULL,\n" + "  Timestamp TIMESTAMP NOT NULL\n" + "  OPTIONS(allow_commit_timestamp=true)\n" + ") PRIMARY KEY(PlayerId, Timestamp),\n" + "INTERLEAVE IN PARENT Players ON DELETE NO ACTION"));
    try {
        // Initiate the request which returns an OperationFuture.
        Database dbOperation = op.get();
        System.out.println("Created database [" + dbOperation.getId() + "]");
    } catch (ExecutionException e) {
        // If the operation failed during execution, expose the cause.
        throw (SpannerException) e.getCause();
    } catch (InterruptedException e) {
        // and the thread is interrupted, either before or during the activity.
        throw SpannerExceptionFactory.propagateInterrupt(e);
    }
}
Also used : Database(com.google.cloud.spanner.Database) CreateDatabaseMetadata(com.google.spanner.admin.database.v1.CreateDatabaseMetadata) ExecutionException(java.util.concurrent.ExecutionException)

Example 57 with Database

use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.

the class TestEmx2Settings method setup.

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

Example 58 with Database

use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.

the class TestMgColumns method setUp.

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

Example 59 with Database

use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.

the class TestGraphqlCrossSchemaRefs method setup.

@BeforeClass
public static void setup() {
    Database database = TestDatabaseFactory.getTestDatabase();
    schema1 = database.dropCreateSchema(schemaName1);
    schema2 = database.dropCreateSchema(schemaName2);
    CrossSchemaReferenceExample.create(schema1, schema2);
    graphql = new GraphqlApiFactory().createGraphqlForSchema(schema2);
}
Also used : Database(org.molgenis.emx2.Database) BeforeClass(org.junit.BeforeClass)

Example 60 with Database

use of com.google.spanner.admin.database.v1.Database in project molgenis-emx2 by molgenis.

the class OIDCController method handleLoginCallback.

@SuppressWarnings("unchecked")
public Object handleLoginCallback(Request request, Response response) {
    final SessionStore<SparkWebContext> sessionStore = FindBest.sessionStore(null, securityConfig, JEESessionStore.INSTANCE);
    final SparkWebContext context = new SparkWebContext(request, response, sessionStore);
    final HttpActionAdapter<Object, SparkWebContext> adapter = FindBest.httpActionAdapter(null, securityConfig, SparkHttpActionAdapter.INSTANCE);
    final CallbackLogic<Object, SparkWebContext> callbackLogic = FindBest.callbackLogic(null, securityConfig, DefaultCallbackLogic.INSTANCE);
    callbackLogic.perform(context, securityConfig, adapter, null, false, true, true, OIDC_CLIENT_NAME);
    final ProfileManager<OidcProfile> manager = new ProfileManager<>(context);
    Optional<OidcProfile> oidcProfile = manager.get(true);
    if (oidcProfile.isPresent()) {
        String user = oidcProfile.get().getEmail();
        Database database = sessionManager.getSession(request).getDatabase();
        if (!database.hasUser(user)) {
            logger.info("Add new OIDC user({}) to database", user);
            database.addUser(user);
        }
        database.setActiveUser(user);
        logger.info("OIDC sign in for user: {}", user);
        response.status(302);
    } else {
        logger.error("OIDC sign in failed, no profile found");
        response.status(404);
    }
    response.redirect("/");
    return response;
}
Also used : ProfileManager(org.pac4j.core.profile.ProfileManager) SparkWebContext(org.pac4j.sparkjava.SparkWebContext) Database(org.molgenis.emx2.Database) OidcProfile(org.pac4j.oidc.profile.OidcProfile)

Aggregations

Test (org.junit.Test)53 CreateDatabaseMetadata (com.google.spanner.admin.database.v1.CreateDatabaseMetadata)31 Database (com.google.cloud.spanner.Database)29 AbstractMessage (com.google.protobuf.AbstractMessage)24 ArrayList (java.util.ArrayList)24 ExecutionException (java.util.concurrent.ExecutionException)22 Database (com.google.spanner.admin.database.v1.Database)21 Operation (com.google.longrunning.Operation)18 ByteString (com.google.protobuf.ByteString)16 DatabaseAdminClient (com.google.cloud.spanner.DatabaseAdminClient)12 SpannerException (com.google.cloud.spanner.SpannerException)12 Database (org.molgenis.emx2.Database)12 CreateBackupMetadata (com.google.spanner.admin.database.v1.CreateBackupMetadata)11 DatabaseName (com.google.spanner.admin.database.v1.DatabaseName)10 RestoreDatabaseMetadata (com.google.spanner.admin.database.v1.RestoreDatabaseMetadata)9 Timestamp (com.google.cloud.Timestamp)8 Spanner (com.google.cloud.spanner.Spanner)8 RestoreDatabaseRequest (com.google.spanner.admin.database.v1.RestoreDatabaseRequest)7 StatusRuntimeException (io.grpc.StatusRuntimeException)7 Backup (com.google.cloud.spanner.Backup)6