use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorDatabaseService method create.
@Override
public void create(@Nonnull final ConnectorRequestContext context, @Nonnull final DatabaseInfo databaseInfo) {
final String databaseName = databaseInfo.getName().getDatabaseName();
log.debug("Start: Create database {}", databaseInfo.getName());
Preconditions.checkNotNull(databaseName, "Database name is null");
if (databaseDao.getBySourceDatabaseName(catalogName, databaseName) != null) {
log.warn("Database {} already exists", databaseName);
throw new DatabaseAlreadyExistsException(databaseInfo.getName());
}
final Database database = new Database();
database.setName(databaseName);
database.setSource(sourceDao.getByName(catalogName));
databaseDao.save(database);
log.debug("End: Create database {}", databaseInfo.getName());
}
use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorDatabaseService method get.
@Override
public DatabaseInfo get(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
final String databaseName = name.getDatabaseName();
Preconditions.checkNotNull(databaseName, "Database name is null");
log.debug("Get database {}", name);
final Database database = databaseDao.getBySourceDatabaseName(catalogName, databaseName);
if (database == null) {
throw new DatabaseNotFoundException(name);
}
return infoConverter.toDatabaseInfo(QualifiedName.ofCatalog(catalogName), database);
}
use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorDatabaseService method rename.
@Override
public void rename(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName oldName, @Nonnull final QualifiedName newName) {
log.debug("Start: Rename database {} with {}", oldName, newName);
final String newDatabaseName = newName.getDatabaseName();
Preconditions.checkNotNull(newDatabaseName, "Database name is null");
final Database oldDatabase = databaseDao.getBySourceDatabaseName(catalogName, oldName.getDatabaseName());
if (oldDatabase == null) {
throw new DatabaseNotFoundException(oldName);
}
if (databaseDao.getBySourceDatabaseName(catalogName, newDatabaseName) != null) {
throw new DatabaseAlreadyExistsException(newName);
}
oldDatabase.setName(newDatabaseName);
databaseDao.save(oldDatabase);
log.debug("End: Rename database {} with {}", oldName, newName);
}
use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorDatabaseService method delete.
@Override
public void delete(@Nonnull final ConnectorRequestContext context, @Nonnull final QualifiedName name) {
log.debug("Start: Delete database {}", name);
final String databaseName = name.getDatabaseName();
Preconditions.checkNotNull(databaseName, "Database name is null");
final Database database = databaseDao.getBySourceDatabaseName(catalogName, databaseName);
if (database == null) {
throw new DatabaseNotFoundException(name);
} else if (database.getTables() != null && !database.getTables().isEmpty()) {
throw new ConnectorException("Database " + databaseName + " is not empty. One or more tables exist.", null);
}
databaseDao.delete(database);
log.debug("End: Delete database {}", name);
}
use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorInfoConverter method fromTableInfo.
/**
* Creates the s3 table.
* @param database s3 database
* @param tableInfo table info
* @return s3 table
*/
public Table fromTableInfo(final Database database, final TableInfo tableInfo) {
final Table result = fromTableInfo(tableInfo);
result.setDatabase(database);
return result;
}
Aggregations