bda-controller/src/main/java/gr/ntua/ece/cslab/selis/bda/controller/resources/DatastoreResource.java
@POST
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response createNewScn(ScnDbInfo scn) {
        LOGGER.log(Level.INFO, scn.toString());

        String details = "";

        try {
            List<Connector> connectors = Connector.getConnectors();

            boolean correctConnector = false;
            for (Connector connector : connectors) {
                if (connector.getId() == scn.getConnectorId()) {
                    correctConnector = true;
                }
            }

            if (correctConnector) {
                scn.save();
            } else {
                LOGGER.log(Level.WARNING, "Bad connector id provided!");
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Connector id does not exist.")
                ).build();
            }

            details = Integer.toString(scn.getId());
        } catch (Exception e) {
            e.printStackTrace();

            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not register new SCN.")
            ).build();
        }

        try {
            StorageBackend.createNewScn(scn);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.log(Level.INFO, "Clearing SCN registry and databases after failure.");
            try {
                StorageBackend.destroyScn(scn);
            } catch (Exception e1) {
            }
            try {
                ScnDbInfo.destroy(scn.getId());
            } catch (Exception e1) {
                e1.printStackTrace();
                LOGGER.log(Level.SEVERE, "Could not clear SCN registry, after databases creation failed!");
            }
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new SCN.")
            ).build();
        }

        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
/**
     * Create new SCN databases/schemas/tables.
     * @param scn an SCN description.
     */
Create new SCN databases/schemas/tables.
@param scn an SCN description.
Create new SCN databases / schemas / tables . @param scn an SCN description .
@POST
    @Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response createNewScn(ScnDbInfo scn) {
        LOGGER.log(Level.INFO, scn.toString());
        String details = "";
        try {
            List<Connector> connectors = Connector.getConnectors();
            boolean correctConnector = false;
            for (Connector connector : connectors) {
                if (connector.getId() == scn.getConnectorId()) {
                    correctConnector = true;
                }
            }
            if (correctConnector) {
                scn.save();
            } else {
                LOGGER.log(Level.WARNING, "Bad connector id provided!");
                return Response.serverError().entity(
                        new RequestResponse("ERROR", "Connector id does not exist.")
                ).build();
            }
            details = Integer.toString(scn.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not register new SCN.")
            ).build();
        }
        try {
            StorageBackend.createNewScn(scn);
        } catch (Exception e) {
            e.printStackTrace();
            LOGGER.log(Level.INFO, "Clearing SCN registry and databases after failure.");
            try {
                StorageBackend.destroyScn(scn);
            } catch (Exception e1) {
            }
            try {
                ScnDbInfo.destroy(scn.getId());
            } catch (Exception e1) {
                e1.printStackTrace();
                LOGGER.log(Level.SEVERE, "Could not clear SCN registry, after databases creation failed!");
            }
            return Response.serverError().entity(
                    new RequestResponse("ERROR", "Could not create new SCN.")
            ).build();
        }
        return Response.ok(
                new RequestResponse("OK", details)
        ).build();
    }
@ POST @ Consumes ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) @ Produces ( { MediaType . APPLICATION_JSON , MediaType . APPLICATION_XML } ) public Response createNewScn ( ScnDbInfo scn ) { LOGGER . log ( Level . INFO , scn . toString ( ) ) ; String details = "" ; try { List < Connector > connectors = Connector . getConnectors ( ) ; boolean correctConnector = false ; for ( Connector connector : connectors ) { if ( connector . getId ( ) == scn . getConnectorId ( ) ) { correctConnector = true ; } } if ( correctConnector ) { scn . save ( ) ; } else { LOGGER . log ( Level . WARNING , "Bad connector id provided!" ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Connector id does not exist." ) ) . build ( ) ; } details = Integer . toString ( scn . getId ( ) ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not register new SCN." ) ) . build ( ) ; } try { StorageBackend . createNewScn ( scn ) ; } catch ( Exception e ) { e . printStackTrace ( ) ; LOGGER . log ( Level . INFO , "Clearing SCN registry and databases after failure." ) ; try { StorageBackend . destroyScn ( scn ) ; } catch ( Exception e1 ) { } try { ScnDbInfo . destroy ( scn . getId ( ) ) ; } catch ( Exception e1 ) { e1 . printStackTrace ( ) ; LOGGER . log ( Level . SEVERE , "Could not clear SCN registry, after databases creation failed!" ) ; } return Response . serverError ( ) . entity ( new RequestResponse ( "ERROR" , "Could not create new SCN." ) ) . build ( ) ; } return Response . ok ( new RequestResponse ( "OK" , details ) ) . build ( ) ; }
Create new SCN databases/schemas/tables.
Create new SCN databases / schemas / tables .