255 lines
26 KiB
HTML
255 lines
26 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="de"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>HmiSchemaBootstrap.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">backend</a> > <a href="index.source.html" class="el_package">com.workbenchclassic.hmi</a> > <span class="el_source">HmiSchemaBootstrap.java</span></div><h1>HmiSchemaBootstrap.java</h1><pre class="source lang-java linenums">package com.workbenchclassic.hmi;
|
|
|
|
import java.sql.Connection;
|
|
import java.sql.DatabaseMetaData;
|
|
import java.sql.PreparedStatement;
|
|
import java.sql.ResultSet;
|
|
import java.sql.SQLException;
|
|
import java.sql.Statement;
|
|
import java.util.Locale;
|
|
import java.util.logging.Level;
|
|
import java.util.logging.Logger;
|
|
import javax.servlet.ServletContextEvent;
|
|
import javax.servlet.ServletContextListener;
|
|
|
|
/**
|
|
* Idempotent schema creation on deployment for Oracle and SQL Server.
|
|
* Existing CUST schema is used; no DBA user/schema creation on Oracle.
|
|
* DDL runs under the permissions of dsCustNJTA (must have CREATE TABLE).
|
|
*/
|
|
<span class="nc" id="L20">public final class HmiSchemaBootstrap implements ServletContextListener {</span>
|
|
<span class="nc" id="L21"> private static final Logger LOG = Logger.getLogger(HmiSchemaBootstrap.class.getName());</span>
|
|
<span class="nc" id="L22"> private static final Object START_LOCK = new Object();</span>
|
|
<span class="nc" id="L23"> private static volatile boolean ready = false;</span>
|
|
<span class="nc" id="L24"> private static volatile String state = "Not initialized";</span>
|
|
// The public health endpoint exposes only fixed diagnostic codes, never SQL errors or connection credentials.
|
|
<span class="nc" id="L26"> private static volatile String phase = "NOT_STARTED";</span>
|
|
<span class="nc" id="L27"> private static volatile String code = "NONE";</span>
|
|
<span class="nc" id="L28"> private static volatile boolean poolConnected = false;</span>
|
|
<span class="nc" id="L29"> private static volatile String databaseKind = "UNKNOWN";</span>
|
|
<span class="nc" id="L30"> static boolean isReady() { return ready; }</span>
|
|
<span class="nc" id="L31"> static String state() { return state; }</span>
|
|
<span class="nc" id="L32"> static String phase() { return phase; }</span>
|
|
<span class="nc" id="L33"> static String failureCode() { return code; }</span>
|
|
<span class="nc" id="L34"> static boolean poolConnected() { return poolConnected; }</span>
|
|
<span class="nc" id="L35"> static String databaseKind() { return databaseKind; }</span>
|
|
|
|
|
|
<span class="nc" id="L38"> static void retryInitialization() { new HmiSchemaBootstrap().contextInitialized(null); }</span>
|
|
|
|
@Override public void contextInitialized(ServletContextEvent event) {
|
|
<span class="nc" id="L41"> synchronized (START_LOCK) {</span>
|
|
<span class="nc" id="L42"> ready = false;</span>
|
|
<span class="nc" id="L43"> poolConnected = false;</span>
|
|
<span class="nc" id="L44"> databaseKind = "UNKNOWN";</span>
|
|
<span class="nc" id="L45"> code = "NONE";</span>
|
|
<span class="nc" id="L46"> phase = "DATASOURCE_LOOKUP";</span>
|
|
<span class="nc" id="L47"> try (Connection c = HmiDb.open()) {</span>
|
|
<span class="nc" id="L48"> poolConnected = true;</span>
|
|
<span class="nc" id="L49"> phase = "DATABASE_DETECTION";</span>
|
|
<span class="nc" id="L50"> String product = c.getMetaData().getDatabaseProductName().toLowerCase(Locale.ROOT);</span>
|
|
<span class="nc" id="L51"> boolean oracle = product.contains("oracle");</span>
|
|
<span class="nc bnc" id="L52" title="All 4 branches missed."> boolean sqlServer = product.contains("microsoft sql server") || product.contains("sql server");</span>
|
|
<span class="nc bnc" id="L53" title="All 4 branches missed."> if (!oracle && !sqlServer) {</span>
|
|
<span class="nc" id="L54"> code = "UNSUPPORTED_DATABASE";</span>
|
|
<span class="nc" id="L55"> throw new SQLException("Unsupported dsCustNJTA database: " + product);</span>
|
|
}
|
|
<span class="nc bnc" id="L57" title="All 2 branches missed."> databaseKind = oracle ? "ORACLE" : "SQL_SERVER";</span>
|
|
<span class="nc" id="L58"> phase = "SCHEMA_CHECK";</span>
|
|
<span class="nc bnc" id="L59" title="All 2 branches missed."> if (sqlServer) createSqlServerSchema(c);</span>
|
|
<span class="nc" id="L60"> else assertOracleSchemaExists(c);</span>
|
|
|
|
<span class="nc" id="L62"> phase = "SCHEMA_INITIALIZATION";</span>
|
|
<span class="nc bnc" id="L63" title="All 2 branches missed."> String prefix = oracle ? "CUST." : "cust.";</span>
|
|
<span class="nc bnc" id="L64" title="All 2 branches missed."> String text = oracle ? "CLOB" : "NVARCHAR(MAX)";</span>
|
|
<span class="nc bnc" id="L65" title="All 2 branches missed."> String shortText = oracle ? "VARCHAR2" : "NVARCHAR";</span>
|
|
<span class="nc bnc" id="L66" title="All 2 branches missed."> String numeric = oracle ? "NUMBER(10)" : "INT";</span>
|
|
<span class="nc bnc" id="L67" title="All 2 branches missed."> String date = oracle ? "TIMESTAMP" : "DATETIME2";</span>
|
|
<span class="nc bnc" id="L68" title="All 2 branches missed."> String now = oracle ? "SYSTIMESTAMP" : "SYSUTCDATETIME()";</span>
|
|
<span class="nc" id="L69"> createIfMissing(c, "HMI_APP_PAGE", "CREATE TABLE " + prefix + "HMI_APP_PAGE ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, PAGE_KEY " + shortText + "(120) NOT NULL UNIQUE, "
|
|
+ "TITLE " + shortText + "(255) NOT NULL, MENU_GROUP " + shortText + "(120), "
|
|
+ "PARENT_PAGE_ID " + shortText + "(64), "
|
|
+ "SORT_ORDER " + numeric + " DEFAULT 0 NOT NULL, ENABLED " + numeric + " DEFAULT 1 NOT NULL)");
|
|
// V5.2: compatible migration for existing Oracle and SQL Server installations.
|
|
// Never drops or recreates HMI_APP_PAGE, preserving all published templates/layouts.
|
|
<span class="nc" id="L76"> addParentPageColumnIfMissing(c, oracle);</span>
|
|
<span class="nc" id="L77"> createIfMissing(c, "HMI_APP_TEMPLATE", "CREATE TABLE " + prefix + "HMI_APP_TEMPLATE ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, PAGE_ID " + shortText + "(64) NOT NULL, "
|
|
+ "VERSION_NO " + numeric + " NOT NULL, STATUS " + shortText + "(20) NOT NULL, "
|
|
+ "LAYOUT_JSON " + text + " NOT NULL, UPDATED_BY " + shortText + "(255), "
|
|
+ "UPDATED_AT " + date + " DEFAULT " + now + " NOT NULL)");
|
|
<span class="nc" id="L82"> createIfMissing(c, "HMI_APP_ASSIGNMENT", "CREATE TABLE " + prefix + "HMI_APP_ASSIGNMENT ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, PAGE_ID " + shortText + "(64) NOT NULL, "
|
|
+ "SCOPE_TYPE " + shortText + "(20) NOT NULL, SCOPE_ID " + shortText + "(255) NOT NULL, "
|
|
+ "TEMPLATE_ID " + shortText + "(64) NOT NULL, PRIORITY " + numeric + " DEFAULT 0 NOT NULL)");
|
|
<span class="nc" id="L86"> createIfMissing(c, "HMI_APP_LAYOUT", "CREATE TABLE " + prefix + "HMI_APP_LAYOUT ("</span>
|
|
+ "USER_ID " + shortText + "(255) NOT NULL, PAGE_ID " + shortText + "(64) NOT NULL, "
|
|
+ "STATION_ID " + shortText + "(120) DEFAULT '*' NOT NULL, BASE_TEMPLATE_ID " + shortText + "(64), OVERRIDES_JSON " + text + " NOT NULL, "
|
|
+ "UPDATED_AT " + date + " DEFAULT " + now + " NOT NULL, "
|
|
+ "PRIMARY KEY (USER_ID, PAGE_ID, STATION_ID))");
|
|
<span class="nc" id="L91"> createIfMissing(c, "HMI_APP_PREF", "CREATE TABLE " + prefix + "HMI_APP_PREF ("</span>
|
|
+ "SCOPE_TYPE " + shortText + "(20) NOT NULL, SCOPE_ID " + shortText + "(255) NOT NULL, "
|
|
+ "PREFS_JSON " + text + " NOT NULL, UPDATED_AT " + date + " DEFAULT " + now + " NOT NULL, "
|
|
+ "PRIMARY KEY (SCOPE_TYPE, SCOPE_ID))");
|
|
<span class="nc" id="L95"> createIfMissing(c, "HMI_APP_GROUP_MEMBER", "CREATE TABLE " + prefix + "HMI_APP_GROUP_MEMBER ("</span>
|
|
+ "USER_ID " + shortText + "(255) NOT NULL, GROUP_ID " + shortText + "(120) NOT NULL, "
|
|
+ "PRIMARY KEY (USER_ID, GROUP_ID))");
|
|
<span class="nc" id="L98"> createIfMissing(c, "HMI_APP_AUDIT", "CREATE TABLE " + prefix + "HMI_APP_AUDIT ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, ACTOR " + shortText + "(255) NOT NULL, "
|
|
+ "ACTION_NAME " + shortText + "(120) NOT NULL, ENTITY_ID " + shortText + "(255), "
|
|
+ "DETAILS " + shortText + "(1000), CREATED_AT " + date + " DEFAULT " + now + " NOT NULL)");
|
|
// Versioned ios.css content, separate from the immutable WAR fallback.
|
|
<span class="nc" id="L103"> createIfMissing(c, "HMI_APP_CSS_REVISION", "CREATE TABLE " + prefix + "HMI_APP_CSS_REVISION ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, VERSION_NO " + numeric + " NOT NULL UNIQUE, "
|
|
+ "STATUS " + shortText + "(20) NOT NULL, CSS_CONTENT " + text + " NOT NULL, "
|
|
+ "UPDATED_BY " + shortText + "(255), UPDATED_AT " + date + " DEFAULT " + now + " NOT NULL)");
|
|
// V5: Person-oriented roles, groups and uploaded HMI image assets.
|
|
<span class="nc bnc" id="L108" title="All 2 branches missed."> String binary = oracle ? "BLOB" : "VARBINARY(MAX)";</span>
|
|
<span class="nc" id="L109"> createIfMissing(c, "HMI_APP_ROLE", "CREATE TABLE " + prefix + "HMI_APP_ROLE ("</span>
|
|
+ "ROLE_KEY " + shortText + "(120) NOT NULL PRIMARY KEY, DESCRIPTION " + shortText + "(255))");
|
|
<span class="nc" id="L111"> createIfMissing(c, "HMI_APP_GROUP_DEF", "CREATE TABLE " + prefix + "HMI_APP_GROUP_DEF ("</span>
|
|
+ "GROUP_KEY " + shortText + "(120) NOT NULL PRIMARY KEY, DESCRIPTION " + shortText + "(255))");
|
|
<span class="nc" id="L113"> createIfMissing(c, "HMI_APP_GROUP_ROLE", "CREATE TABLE " + prefix + "HMI_APP_GROUP_ROLE ("</span>
|
|
+ "GROUP_KEY " + shortText + "(120) NOT NULL, ROLE_KEY " + shortText + "(120) NOT NULL, PRIMARY KEY (GROUP_KEY,ROLE_KEY))");
|
|
<span class="nc" id="L115"> createIfMissing(c, "HMI_APP_PERSON_ROLE", "CREATE TABLE " + prefix + "HMI_APP_PERSON_ROLE ("</span>
|
|
+ "PERS_ID " + shortText + "(120) NOT NULL, ROLE_KEY " + shortText + "(120) NOT NULL, PRIMARY KEY (PERS_ID,ROLE_KEY))");
|
|
<span class="nc" id="L117"> createIfMissing(c, "HMI_APP_PERSON_GROUP", "CREATE TABLE " + prefix + "HMI_APP_PERSON_GROUP ("</span>
|
|
+ "PERS_ID " + shortText + "(120) NOT NULL, GROUP_KEY " + shortText + "(120) NOT NULL, PRIMARY KEY (PERS_ID,GROUP_KEY))");
|
|
<span class="nc" id="L119"> createIfMissing(c, "HMI_APP_LOGIN_PERSON", "CREATE TABLE " + prefix + "HMI_APP_LOGIN_PERSON ("</span>
|
|
+ "LOGIN_ID " + shortText + "(255) NOT NULL PRIMARY KEY, PERS_ID " + shortText + "(120) NOT NULL)");
|
|
// First-run administration: one permanent, database-locked claim marker.
|
|
<span class="nc" id="L122"> createIfMissing(c, "HMI_APP_BOOTSTRAP", "CREATE TABLE " + prefix + "HMI_APP_BOOTSTRAP ("</span>
|
|
+ "ID " + shortText + "(24) NOT NULL PRIMARY KEY, CLAIMED_BY " + shortText + "(255), CLAIMED_AT " + date + ")");
|
|
<span class="nc" id="L124"> try(PreparedStatement ps=c.prepareStatement("SELECT ID FROM " + prefix + "HMI_APP_BOOTSTRAP WHERE ID='GLOBAL'");</span>
|
|
<span class="nc" id="L125"> ResultSet rs=ps.executeQuery()) {</span>
|
|
<span class="nc bnc" id="L126" title="All 2 branches missed."> if(!rs.next())try(PreparedStatement insert=c.prepareStatement(</span>
|
|
"INSERT INTO " + prefix + "HMI_APP_BOOTSTRAP(ID) VALUES ('GLOBAL')")) {
|
|
<span class="nc" id="L128"> try{insert.executeUpdate();}catch(SQLException concurrent){</span>
|
|
<span class="nc" id="L129"> try(PreparedStatement chk=c.prepareStatement("SELECT ID FROM " + prefix + "HMI_APP_BOOTSTRAP WHERE ID='GLOBAL'");</span>
|
|
<span class="nc bnc" id="L130" title="All 2 branches missed."> ResultSet check=chk.executeQuery()){if(!check.next())throw concurrent;}</span>
|
|
<span class="nc" id="L131"> }</span>
|
|
}
|
|
}
|
|
<span class="nc" id="L134"> createIfMissing(c, "HMI_APP_ASSET", "CREATE TABLE " + prefix + "HMI_APP_ASSET ("</span>
|
|
+ "ID " + shortText + "(64) NOT NULL PRIMARY KEY, ORIGINAL_NAME " + shortText + "(255) NOT NULL, "
|
|
+ "MIME_TYPE " + shortText + "(80) NOT NULL, CONTENT " + binary + " NOT NULL, "
|
|
+ "CONTENT_SIZE " + numeric + " NOT NULL, UPDATED_BY " + shortText + "(255) NOT NULL)");
|
|
<span class="nc" id="L138"> createIfMissing(c, "HMI_APP_SCHEMA_VERSION", "CREATE TABLE " + prefix + "HMI_APP_SCHEMA_VERSION ("</span>
|
|
+ "VERSION_NO " + numeric + " NOT NULL PRIMARY KEY, INSTALLED_AT " + date + " DEFAULT " + now + " NOT NULL)");
|
|
// Fail closed when a v1 schema exists: do not alter existing PKs on a production database.
|
|
// See hmi-docs/migrate-v1-to-v2-*.sql for non-destructive, operator-reviewed migration.
|
|
<span class="nc" id="L142"> phase = "SCHEMA_VERIFICATION";</span>
|
|
<span class="nc" id="L143"> verifyLayoutStationKey(c, oracle);</span>
|
|
<span class="nc" id="L144"> try (PreparedStatement check = c.prepareStatement("SELECT VERSION_NO FROM " + prefix + "HMI_APP_SCHEMA_VERSION WHERE VERSION_NO = 7");</span>
|
|
<span class="nc" id="L145"> ResultSet rs = check.executeQuery()) {</span>
|
|
<span class="nc bnc" id="L146" title="All 2 branches missed."> if (!rs.next()) {</span>
|
|
<span class="nc" id="L147"> try (PreparedStatement insert = c.prepareStatement("INSERT INTO " + prefix + "HMI_APP_SCHEMA_VERSION(VERSION_NO) VALUES (7)")) {</span>
|
|
<span class="nc" id="L148"> insert.executeUpdate();</span>
|
|
<span class="nc" id="L149"> } catch (SQLException concurrent) { // A second cluster member may have inserted simultaneously.</span>
|
|
<span class="nc" id="L150"> try (PreparedStatement confirm = c.prepareStatement("SELECT VERSION_NO FROM " + prefix + "HMI_APP_SCHEMA_VERSION WHERE VERSION_NO = 7");</span>
|
|
<span class="nc" id="L151"> ResultSet rs2 = confirm.executeQuery()) {</span>
|
|
<span class="nc bnc" id="L152" title="All 2 branches missed."> if (!rs2.next()) throw concurrent;</span>
|
|
}
|
|
<span class="nc" id="L154"> }</span>
|
|
}
|
|
}
|
|
<span class="nc" id="L157"> HmiDb.useDatabase(oracle);</span>
|
|
<span class="nc" id="L158"> ready = true;</span>
|
|
<span class="nc" id="L159"> HmiInitialAdmin.initialize(c);</span>
|
|
<span class="nc" id="L160"> HmiSchemaRecovery.clear();</span>
|
|
<span class="nc" id="L161"> phase = "READY";</span>
|
|
<span class="nc" id="L162"> code = "NONE";</span>
|
|
<span class="nc bnc" id="L163" title="All 2 branches missed."> state = "Initialized: " + product + ", schema " + (oracle ? "CUST" : "cust") + ", version 7";</span>
|
|
<span class="nc" id="L164"> LOG.info("HMI " + state);</span>
|
|
<span class="nc" id="L165"> } catch (Exception ex) {</span>
|
|
<span class="nc" id="L166"> ready = false;</span>
|
|
<span class="nc bnc" id="L167" title="All 2 branches missed."> if ("NONE".equals(code)) {</span>
|
|
<span class="nc bnc" id="L168" title="All 2 branches missed."> if (!poolConnected) code = "POOL_CONNECTION_FAILED";</span>
|
|
<span class="nc bnc" id="L169" title="All 2 branches missed."> else if ("SCHEMA_VERIFICATION".equals(phase)) code = "SCHEMA_MIGRATION_REQUIRED";</span>
|
|
<span class="nc bnc" id="L170" title="All 4 branches missed."> else if ("SCHEMA_INITIALIZATION".equals(phase) || "SCHEMA_CHECK".equals(phase)) code = "SCHEMA_SETUP_FAILED";</span>
|
|
<span class="nc" id="L171"> else code = "DATABASE_ERROR";</span>
|
|
}
|
|
<span class="nc" id="L173"> state = "Database initialization failed; inspect GlassFish logs";</span>
|
|
<span class="nc" id="L174"> HmiSchemaRecovery.enableAfterFailure();</span>
|
|
<span class="nc" id="L175"> LOG.log(Level.SEVERE, "HMI schema initialization FAILED [" + code + ", phase=" + phase + "]; HMI endpoints remain unavailable", ex);</span>
|
|
<span class="nc" id="L176"> }</span>
|
|
<span class="nc" id="L177"> } // START_LOCK</span>
|
|
<span class="nc" id="L178"> }</span>
|
|
|
|
private boolean pageParentColumnExists(Connection c, boolean oracle) throws SQLException {
|
|
<span class="nc" id="L181"> DatabaseMetaData md = c.getMetaData();</span>
|
|
<span class="nc bnc" id="L182" title="All 2 branches missed."> String schemaName = oracle ? "CUST" : "cust";</span>
|
|
<span class="nc" id="L183"> try (ResultSet rs = md.getColumns(null, schemaName, "HMI_APP_PAGE", "PARENT_PAGE_ID")) {</span>
|
|
<span class="nc bnc" id="L184" title="All 2 branches missed."> if (rs.next()) return true;</span>
|
|
<span class="nc bnc" id="L185" title="All 2 branches missed."> }</span>
|
|
// Some SQL Server drivers return the schema with different capitalization.
|
|
<span class="nc" id="L187"> try (ResultSet rs = md.getColumns(null, schemaName.toUpperCase(Locale.ROOT), "HMI_APP_PAGE", "PARENT_PAGE_ID")) {</span>
|
|
<span class="nc" id="L188"> return rs.next();</span>
|
|
}
|
|
}
|
|
private void addParentPageColumnIfMissing(Connection c, boolean oracle) throws SQLException {
|
|
<span class="nc bnc" id="L192" title="All 2 branches missed."> if (pageParentColumnExists(c, oracle)) return;</span>
|
|
<span class="nc bnc" id="L193" title="All 2 branches missed."> String ddl = oracle</span>
|
|
<span class="nc" id="L194"> ? "ALTER TABLE CUST.HMI_APP_PAGE ADD (PARENT_PAGE_ID VARCHAR2(64))"</span>
|
|
<span class="nc" id="L195"> : "ALTER TABLE cust.HMI_APP_PAGE ADD PARENT_PAGE_ID NVARCHAR(64) NULL";</span>
|
|
<span class="nc" id="L196"> try (Statement st = c.createStatement()) {</span>
|
|
<span class="nc" id="L197"> st.execute(ddl);</span>
|
|
<span class="nc" id="L198"> LOG.info("HMI schema V5.2: added HMI_APP_PAGE.PARENT_PAGE_ID");</span>
|
|
<span class="nc" id="L199"> } catch (SQLException error) {</span>
|
|
// A second GlassFish instance might have applied the same migration.
|
|
<span class="nc bnc" id="L201" title="All 2 branches missed."> if (!pageParentColumnExists(c, oracle)) throw error;</span>
|
|
<span class="nc" id="L202"> }</span>
|
|
<span class="nc" id="L203"> }</span>
|
|
|
|
private void verifyLayoutStationKey(Connection c, boolean oracle) throws SQLException {
|
|
<span class="nc" id="L206"> DatabaseMetaData md = c.getMetaData();</span>
|
|
<span class="nc bnc" id="L207" title="All 2 branches missed."> String schema = oracle ? "CUST" : "cust";</span>
|
|
<span class="nc" id="L208"> boolean station = false, user = false, page = false;</span>
|
|
<span class="nc" id="L209"> try (ResultSet columns = md.getColumns(null, schema, "HMI_APP_LAYOUT", "STATION_ID")) {</span>
|
|
<span class="nc bnc" id="L210" title="All 2 branches missed."> if (!columns.next()) throw new SQLException("HMI schema v1 layout detected (STATION_ID missing); apply documented v1 to v2 migration");</span>
|
|
}
|
|
<span class="nc" id="L212"> try (ResultSet pk = md.getPrimaryKeys(null, schema, "HMI_APP_LAYOUT")) {</span>
|
|
<span class="nc bnc" id="L213" title="All 2 branches missed."> while (pk.next()) {</span>
|
|
<span class="nc" id="L214"> String name = pk.getString("COLUMN_NAME");</span>
|
|
<span class="nc" id="L215"> station |= "STATION_ID".equalsIgnoreCase(name);</span>
|
|
<span class="nc" id="L216"> user |= "USER_ID".equalsIgnoreCase(name);</span>
|
|
<span class="nc" id="L217"> page |= "PAGE_ID".equalsIgnoreCase(name);</span>
|
|
<span class="nc" id="L218"> }</span>
|
|
}
|
|
<span class="nc bnc" id="L220" title="All 6 branches missed."> if (!station || !user || !page) {</span>
|
|
<span class="nc" id="L221"> throw new SQLException("HMI_APP_LAYOUT requires composite primary key USER_ID, PAGE_ID, STATION_ID; apply documented v1 to v2 migration");</span>
|
|
}
|
|
<span class="nc" id="L223"> }</span>
|
|
private void createSqlServerSchema(Connection c) throws SQLException {
|
|
<span class="nc" id="L225"> try (Statement st = c.createStatement()) {</span>
|
|
<span class="nc" id="L226"> st.execute("IF NOT EXISTS (SELECT 1 FROM sys.schemas WHERE name = 'cust') EXEC('CREATE SCHEMA cust')");</span>
|
|
}
|
|
<span class="nc" id="L228"> }</span>
|
|
private void assertOracleSchemaExists(Connection c) throws SQLException {
|
|
<span class="nc" id="L230"> try (PreparedStatement ps = c.prepareStatement("SELECT 1 FROM ALL_USERS WHERE USERNAME = 'CUST'");</span>
|
|
<span class="nc" id="L231"> ResultSet rs = ps.executeQuery()) {</span>
|
|
<span class="nc bnc" id="L232" title="All 2 branches missed."> if (!rs.next()) throw new SQLException("Oracle schema CUST does not exist. Provision it first using DBA privileges.");</span>
|
|
}
|
|
<span class="nc" id="L234"> }</span>
|
|
private void createIfMissing(Connection c, String table, String ddl) throws SQLException {
|
|
<span class="nc bnc" id="L236" title="All 2 branches missed."> if (exists(c, table)) return;</span>
|
|
<span class="nc" id="L237"> try (Statement st = c.createStatement()) {</span>
|
|
<span class="nc" id="L238"> st.execute(ddl);</span>
|
|
<span class="nc" id="L239"> LOG.info("Created HMI table CUST." + table);</span>
|
|
<span class="nc" id="L240"> } catch (SQLException e) {</span>
|
|
<span class="nc bnc" id="L241" title="All 2 branches missed."> if (!exists(c, table)) throw e; // Only suppress a concurrent, successful table creation.</span>
|
|
<span class="nc" id="L242"> }</span>
|
|
<span class="nc" id="L243"> }</span>
|
|
private boolean exists(Connection c, String table) throws SQLException {
|
|
<span class="nc" id="L245"> DatabaseMetaData m = c.getMetaData();</span>
|
|
<span class="nc" id="L246"> try (ResultSet rs = m.getTables(null, "CUST", table, new String[]{"TABLE"})) {</span>
|
|
<span class="nc bnc" id="L247" title="All 2 branches missed."> if (rs.next()) return true;</span>
|
|
<span class="nc bnc" id="L248" title="All 2 branches missed."> }</span>
|
|
<span class="nc" id="L249"> try (ResultSet rs = m.getTables(null, "cust", table, new String[]{"TABLE"})) {</span>
|
|
<span class="nc" id="L250"> return rs.next();</span>
|
|
}
|
|
}
|
|
<span class="nc" id="L253"> @Override public void contextDestroyed(ServletContextEvent event) { ready = false; phase = "STOPPED"; }</span>
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.4.201905082037</span></div></body></html> |