Search in sources :

Example 6 with Database

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());
}
Also used : DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 7 with Database

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);
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 8 with 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);
}
Also used : DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 9 with Database

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);
}
Also used : DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) Database(com.netflix.metacat.connector.s3.model.Database)

Example 10 with Database

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;
}
Also used : Table(com.netflix.metacat.connector.s3.model.Table)

Aggregations

Database (com.netflix.metacat.connector.s3.model.Database)13 DatabaseNotFoundException (com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException)8 DatabaseAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException)4 QualifiedName (com.netflix.metacat.common.QualifiedName)3 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)2 TableAlreadyExistsException (com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException)2 Source (com.netflix.metacat.connector.s3.model.Source)1 Table (com.netflix.metacat.connector.s3.model.Table)1 EntityManager (javax.persistence.EntityManager)1