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());
}
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();
}
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());
}
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);
}
Aggregations