mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-09-18 19:59:09 +00:00
bug5451: table creation, dropping and clearing now uses the SQL scripts from the resources/ directory;
the createtables.sql script is incomplete yet and doesn't have create statements for all tables expected by the clear and drop scripts
This commit is contained in:
@@ -26,6 +26,7 @@ Require-Bundle: com.sap.db.jdbc;bundle-version="2.8.14",
|
||||
com.sap.sailing.shared.server.gateway,
|
||||
com.sap.sse,
|
||||
com.sap.sailing.server.interface,
|
||||
com.sap.sse.datamining
|
||||
com.sap.sse.datamining,
|
||||
org.apache.commons.io;bundle-version="2.2.0"
|
||||
Web-ContextPath: /hanaexport
|
||||
Bundle-Activator: com.sap.sailing.hanaexport.impl.Activator
|
||||
|
||||
@@ -2,4 +2,6 @@ source.. = src/,\
|
||||
resources/
|
||||
output.. = bin/
|
||||
bin.includes = META-INF/,\
|
||||
.
|
||||
.,\
|
||||
resources/,\
|
||||
WEB-INF/
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
DELETE FROM SAILING.BOAT_CLASS;
|
||||
DELETE FROM SAILING.COMPETITORS;
|
||||
DELETE FROM SAILING.COMPETITOR_RACES;
|
||||
DELETE FROM SAILING.EVENTS;
|
||||
DELETE FROM SAILING.IRM;
|
||||
DELETE FROM SAILING.RACE_RESULTS;
|
||||
DELETE FROM SAILING.RANKING_METRIC;
|
||||
DELETE FROM SAILING.SCORING_SCHEME;
|
||||
DELETE FROM SAILING.REGATTAS;
|
||||
DELETE FROM SAILING.RACES;
|
||||
@@ -0,0 +1,46 @@
|
||||
CREATE COLUMN TABLE SAILING.EVENTS (
|
||||
id INTEGER PRIMARY KEY,
|
||||
name NVARCHAR(250) NOT NULL,
|
||||
startDate DATE NOT NULL,
|
||||
endDate DATE NOT NULL,
|
||||
venue NVARCHAR(250),
|
||||
isListed BOOLEAN,
|
||||
description NVARCHAR(250)
|
||||
);
|
||||
CREATE ROW TABLE SAILING.SCORING_SCHEME (
|
||||
id NVARCHAR(20) PRIMARY KEY,
|
||||
description NVARCHAR(250)
|
||||
);
|
||||
CREATE ROW TABLE SAILING.RANKING_METRIC (
|
||||
id NVARCHAR(20) PRIMARY KEY,
|
||||
description NVARCHAR(250)
|
||||
);
|
||||
CREATE ROW TABLE SAILING.BOAT_CLASS (
|
||||
id NVARCHAR(20) PRIMARY KEY,
|
||||
description NVARCHAR(250)
|
||||
);
|
||||
CREATE COLUMN TABLE SAILING.REGATTAS (
|
||||
name NVARCHAR(20) PRIMARY KEY,
|
||||
boatClass NVARCHAR(20) NOT NULL,
|
||||
scoringSchema NVARCHAR(20) NOT NULL,
|
||||
rankingMetric NVARCHAR(20) NOT NULL,
|
||||
FOREIGN KEY (boatClass) REFERENCES SAILING.BOAT_CLASS (id),
|
||||
FOREIGN KEY (scoringSchema) REFERENCES SAILING.SCORING_SCHEME (id),
|
||||
FOREIGN KEY (rankingMetric) REFERENCES SAILING.RANKING_METRIC (id)
|
||||
);
|
||||
CREATE COLUMN TABLE SAILING.RACES (
|
||||
id NVARCHAR(20) PRIMARY KEY,
|
||||
name NVARCHAR(250) NOT NULL,
|
||||
regatta NVARCHAR(20) NOT NULL,
|
||||
raceColumn NVARCHAR(5) NOT NULL,
|
||||
fleet NVARCHAR(20) NOT NULL,
|
||||
boatClass NVARCHAR(20) NOT NULL,
|
||||
startOfTracking DATE NOT NULL,
|
||||
startOfRace DATE NOT NULL,
|
||||
endOfTracking DATE NOT NULL,
|
||||
endOfTrace DATE NOT NULL,
|
||||
avgWindSpeed DECIMAL(17, 3),
|
||||
WindSpeedUnit NVARCHAR(5) DEFAULT 'KTS',
|
||||
FOREIGN KEY (regatta) REFERENCES SAILING.REGATTAS (name),
|
||||
FOREIGN KEY (boatClass) REFERENCES SAILING.BOAT_CLASS (id)
|
||||
);
|
||||
@@ -0,0 +1,10 @@
|
||||
DROP TABLE SAILING.BOAT_CLASS CASCADE;
|
||||
DROP TABLE SAILING.COMPETITORS CASCADE;
|
||||
DROP TABLE SAILING.COMPETITOR_RACES CASCADE;
|
||||
DROP TABLE SAILING.EVENTS CASCADE;
|
||||
DROP TABLE SAILING.IRM CASCADE;
|
||||
DROP TABLE SAILING.RACE_RESULTS CASCADE;
|
||||
DROP TABLE SAILING.RANKING_METRIC CASCADE;
|
||||
DROP TABLE SAILING.SCORING_SCHEME CASCADE;
|
||||
DROP TABLE SAILING.REGATTAS CASCADE;
|
||||
DROP TABLE SAILING.RACES CASCADE;
|
||||
@@ -8,7 +8,6 @@ import org.osgi.framework.BundleContext;
|
||||
import com.sap.db.jdbc.Driver;
|
||||
|
||||
public class Activator implements BundleActivator {
|
||||
|
||||
@Override
|
||||
public void start(BundleContext context) throws Exception {
|
||||
DriverManager.registerDriver(Driver.singleton());
|
||||
@@ -17,5 +16,4 @@ public class Activator implements BundleActivator {
|
||||
@Override
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+51
-5
@@ -1,15 +1,19 @@
|
||||
package com.sap.sailing.hanaexport.jaxrs.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.QueryParam;
|
||||
import javax.ws.rs.core.Response;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
|
||||
import com.sap.sailing.domain.base.BoatClass;
|
||||
@@ -24,21 +28,21 @@ import com.sap.sse.security.shared.impl.SecuredSecurityTypes;
|
||||
public class HanaCloudSacExportResource extends SharedAbstractSailingServerResource {
|
||||
private static final Logger logger = Logger.getLogger(HanaCloudSacExportResource.class.getName());
|
||||
|
||||
@GET
|
||||
@POST
|
||||
@Produces("application/json;charset=UTF-8")
|
||||
@Path("clear")
|
||||
public Response clear() throws SQLException {
|
||||
public Response clear() throws SQLException, IOException {
|
||||
SecurityUtils.getSubject().checkPermission(SecuredSecurityTypes.SERVER.getStringPermissionForTypeRelativeIdentifier(
|
||||
SecuredSecurityTypes.ServerActions.CAN_EXPORT_MASTERDATA,
|
||||
new TypeRelativeObjectIdentifier(ServerInfo.getName())));
|
||||
logger.info("Clearing HANA Cloud SAILING DB on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
final Connection connection = HanaConnectionFactory.INSTANCE.getConnection();
|
||||
connection.createStatement().execute("DELETE FROM SAILING.BOAT_CLASS");
|
||||
executeQueriesFromSqlResource("/cleartables.sql", connection);
|
||||
logger.info("Done learing HANA Cloud SAILING DB on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@POST
|
||||
@Produces("application/json;charset=UTF-8")
|
||||
@Path("export")
|
||||
public Response export() throws SQLException {
|
||||
@@ -58,4 +62,46 @@ public class HanaCloudSacExportResource extends SharedAbstractSailingServerResou
|
||||
logger.info("Done exporting HANA Cloud SAILING DB content on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Produces("application/json;charset=UTF-8")
|
||||
@Path("createtables")
|
||||
public Response createTables(@QueryParam("drop") boolean drop) throws SQLException, IOException {
|
||||
SecurityUtils.getSubject().checkPermission(SecuredSecurityTypes.SERVER.getStringPermissionForTypeRelativeIdentifier(
|
||||
SecuredSecurityTypes.ServerActions.CAN_EXPORT_MASTERDATA,
|
||||
new TypeRelativeObjectIdentifier(ServerInfo.getName())));
|
||||
final Connection connection = HanaConnectionFactory.INSTANCE.getConnection();
|
||||
if (drop) {
|
||||
logger.info("Dropping HANA Cloud SAILING DB tables on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
for (final String statementAsString : getStatementsFromResource("/droptables.sql")) {
|
||||
try {
|
||||
logger.info("...dropping with "+statementAsString);
|
||||
connection.createStatement().execute(statementAsString);
|
||||
} catch (Exception e) {
|
||||
logger.info("Problem trying to drop with "+statementAsString+"; continuing...");
|
||||
}
|
||||
}
|
||||
logger.info("Done dropping HANA Cloud SAILING DB tables on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
}
|
||||
logger.info("Creating HANA Cloud SAILING DB tables on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
executeQueriesFromSqlResource("/createtables.sql", connection);
|
||||
logger.info("Done creating HANA Cloud SAILING DB tables on behalf of user "+SecurityUtils.getSubject().getPrincipal());
|
||||
return Response.ok().build();
|
||||
}
|
||||
|
||||
private String[] getStatementsFromResource(String resourceWithSemicolonSeparatedStatements) throws IOException {
|
||||
final StringWriter sw = new StringWriter();
|
||||
IOUtils.copy(getClass().getResourceAsStream(resourceWithSemicolonSeparatedStatements), sw);
|
||||
return sw.toString().split(";");
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes statements one by one; if an exception occurs it is immediately forwarded to the caller and neither
|
||||
* caught nor logged here.
|
||||
*/
|
||||
private void executeQueriesFromSqlResource(String resourceWithSemicolonSeparatedStatements, final Connection connection) throws IOException, SQLException {
|
||||
for (final String statementAsString : getStatementsFromResource(resourceWithSemicolonSeparatedStatements)) {
|
||||
connection.createStatement().execute(statementAsString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user