All Downloads are FREE. Search and download functionalities are using the official Maven repository.

service.database.command.InitDatabase Maven / Gradle / Ivy

package service.database.command;

import databaseconnector.api.sql.SQLDatabaseConnection;
import databaseconnector.api.sql.SQLSchema;
import service.database.SQLDatabaseService;
import service.database.exception.DatabaseRoleNotActivatedException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Optional;

public class InitDatabase extends AbstractDatabaseCommand {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        setAccessControlAllowOriginHeader(req, resp);

        try {
            SQLDatabaseConnection databaseConnection = getDatabaseConnection();
            Optional schema = SQLDatabaseService.getSchema();
            assert schema.isPresent();
            databaseConnection.init(schema.get());
            resp.setStatus(200);
        } catch (DatabaseRoleNotActivatedException exception) {
            displayError(resp, 501, exception.getMessage());
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy