public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) throws UndefinedDatabaseException, InsufficientPrivilegeException, CannotDropCurrentDatabaseException { boolean exists = catalog.existDatabase(databaseName); if (!exists) { if (ifExists) { // DROP DATABASE IF EXISTS LOG.info("database \"" + databaseName + "\" does not exists."); return; } else { // Otherwise, it causes an exception. throw new UndefinedDatabaseException(databaseName); } } if (queryContext.getCurrentDatabase().equals(databaseName)) { throw new CannotDropCurrentDatabaseException(); } catalog.dropDatabase(databaseName); }
public void dropDatabase(QueryContext queryContext, String databaseName, boolean ifExists) throws UndefinedDatabaseException, InsufficientPrivilegeException, CannotDropCurrentDatabaseException { boolean exists = catalog.existDatabase(databaseName); if (!exists) { if (ifExists) { // DROP DATABASE IF EXISTS LOG.info("database \"" + databaseName + "\" does not exists."); return; } else { // Otherwise, it causes an exception. throw new UndefinedDatabaseException(databaseName); } } if (queryContext.getCurrentDatabase().equals(databaseName)) { throw new CannotDropCurrentDatabaseException(); } catalog.dropDatabase(databaseName); }
@Override public Response run(JerseyResourceDelegateContext context) { JerseyResourceDelegateContextKey<MasterContext> masterContextKey = JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class); MasterContext masterContext = context.get(masterContextKey); JerseyResourceDelegateContextKey<String> databaseNameKey = JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class); String databaseName = context.get(databaseNameKey); if (databaseName.isEmpty()) { return ResourcesUtil.createBadRequestResponse(LOG, "DatabaseName is empty string."); } CatalogService catalogService = masterContext.getCatalog(); if (!catalogService.existDatabase(databaseName)) { return Response.status(Status.NOT_FOUND).build(); } try { catalogService.dropDatabase(databaseName); return Response.ok().build(); } catch (TajoException e) { return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a database " + databaseName); } } }
@Override public Response run(JerseyResourceDelegateContext context) { JerseyResourceDelegateContextKey<MasterContext> masterContextKey = JerseyResourceDelegateContextKey.valueOf(JerseyResourceDelegateUtil.MasterContextKey, MasterContext.class); MasterContext masterContext = context.get(masterContextKey); JerseyResourceDelegateContextKey<String> databaseNameKey = JerseyResourceDelegateContextKey.valueOf(databaseNameKeyName, String.class); String databaseName = context.get(databaseNameKey); if (databaseName.isEmpty()) { return ResourcesUtil.createBadRequestResponse(LOG, "DatabaseName is empty string."); } CatalogService catalogService = masterContext.getCatalog(); if (!catalogService.existDatabase(databaseName)) { return Response.status(Status.NOT_FOUND).build(); } try { catalogService.dropDatabase(databaseName); return Response.ok().build(); } catch (TajoException e) { return ResourcesUtil.createExceptionResponse(LOG, "Unable to drop a database " + databaseName); } } }