Search in sources :

Example 1 with Database

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

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

Example 3 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 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);
}
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 4 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 5 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)

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