blob: b69fca4729a540739d10bdcb4d64648554cfc4e7 [file] [log] [blame]
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package io.v.syncbase.v23.services.syncbase;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import io.v.impl.google.naming.NamingUtil;
import io.v.syncbase.v23.services.syncbase.nosql.Database;
import io.v.syncbase.v23.services.syncbase.nosql.NoSql;
import io.v.syncbase.v23.services.syncbase.nosql.Schema;
import io.v.syncbase.v23.services.syncbase.util.Util;
import io.v.v23.context.VContext;
import io.v.v23.security.access.Permissions;
import io.v.v23.verror.VException;
class SyncbaseAppImpl implements SyncbaseApp {
private final String fullName;
private final String name;
private final AppClient client;
SyncbaseAppImpl(String parentFullName, String relativeName) {
this.fullName = NamingUtil.join(parentFullName, relativeName);
this.name = relativeName;
this.client = AppClientFactory.getAppClient(this.fullName);
}
@Override
public String name() {
return this.name;
}
@Override
public String fullName() {
return this.fullName;
}
@Override
public boolean exists(VContext ctx) throws VException {
return this.client.exists(ctx);
}
@Override
public Database getNoSqlDatabase(String relativeName, Schema schema) {
return NoSql.newDatabase(this.fullName, relativeName, schema);
}
@Override
public String[] listDatabases(VContext ctx) throws VException {
return Util.list(ctx, this.fullName);
}
@Override
public void create(VContext ctx, Permissions perms) throws VException {
this.client.create(ctx, perms);
}
@Override
public void delete(VContext ctx) throws VException {
this.client.delete(ctx);
}
@Override
public void setPermissions(VContext ctx, Permissions perms, String version) throws VException {
this.client.setPermissions(ctx, perms, version);
}
@Override
public Map<String, Permissions> getPermissions(VContext ctx) throws VException {
ServiceClient.GetPermissionsOut perms = this.client.getPermissions(ctx);
return ImmutableMap.of(perms.version, perms.perms);
}
}