use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.
the class S3ConnectorTableService method create.
@Override
public void create(@Nonnull final ConnectorContext context, @Nonnull final TableInfo tableInfo) {
log.debug("Start: Create table {}", tableInfo.getName());
Preconditions.checkArgument(tableInfo.getSerde() == null || !Strings.isNullOrEmpty(tableInfo.getSerde().getOwner()), "Table owner is null or empty");
final QualifiedName tableName = tableInfo.getName();
if (tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName()) != null) {
throw new TableAlreadyExistsException(tableName);
}
final Database database = databaseDao.getBySourceDatabaseName(catalogName, tableName.getDatabaseName());
if (database == null) {
throw new DatabaseNotFoundException(QualifiedName.ofDatabase(catalogName, tableName.getDatabaseName()));
}
tableDao.save(infoConverter.fromTableInfo(database, tableInfo));
log.debug("End: Create table {}", tableInfo.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 ConnectorContext 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 ConnectorContext 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 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 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);
}
Aggregations