Search in sources :

Example 11 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 ConnectorRequestContext 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 12 with Database

use of com.netflix.metacat.connector.s3.model.Database in project metacat by Netflix.

the class DatabaseDaoImpl method searchBySourceDatabaseName.

@Override
public List<Database> searchBySourceDatabaseName(final String sourceName, final String databaseNamePrefix, final Sort sort, final Pageable pageable) {
    final StringBuilder queryBuilder = new StringBuilder(SQL_SEARCH_DATABASES);
    if (sort != null && sort.hasSort()) {
        queryBuilder.append(" order by ").append(sort.getSortBy()).append(" ").append(sort.getOrder().name());
    }
    // entityManager
    final EntityManager entityManager = em.get();
    final TypedQuery<Database> pQuery = entityManager.createQuery(queryBuilder.toString(), Database.class);
    pQuery.setParameter("sourceName", sourceName);
    pQuery.setParameter("isNameNull", databaseNamePrefix == null ? 1 : 0);
    pQuery.setParameter("databaseName", databaseNamePrefix + "%");
    if (pageable != null && pageable.isPageable()) {
        pQuery.setFirstResult(pageable.getOffset());
        pQuery.setMaxResults(pageable.getLimit());
    }
    return pQuery.getResultList();
}
Also used : EntityManager(javax.persistence.EntityManager) Database(com.netflix.metacat.connector.s3.model.Database)

Example 13 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 ConnectorContext 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 14 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 ConnectorContext 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)

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