/** * 增强当前数据库以符合该类规则 * * @param connection 链接 * @throws SQLException */ public static void enhance(ConnectionProvider connection) throws SQLException { if (connection.profile().isH2()) { try (Statement statement = connection.getConnection().createStatement()) { statement.executeUpdate("DROP ALIAS IF EXISTS `IF`"); statement.executeUpdate("CREATE ALIAS IF NOT EXISTS `IF` FOR \"" + JpaFunctionUtils.class.getName() + ".h2If\""); // // statement.executeUpdate("DROP ALIAS IF EXISTS `DATEDIFF`"); // statement.executeUpdate("CREATE ALIAS IF NOT EXISTS `DATEDIFF` FOR \"" + JpaFunctionUtils.class.getName() + ".H2DATEDIFF\""); } } }
@PostConstruct @Transactional public void init() throws SQLException { jdbcService.runJdbcWork(connection -> { String fileName; if (connection.profile().isMySQL()) { fileName = "mysql"; } else if (connection.profile().isH2()) { fileName = "h2"; } else throw new IllegalStateException("not support for:" + connection.getConnection()); try { try (Statement statement = connection.getConnection().createStatement()) { statement.executeUpdate("DROP TABLE IF EXISTS `UNSETTLEMENTUSAGESTOCK`"); statement.executeUpdate("DROP TABLE IF EXISTS `USAGESTOCK`"); statement.executeUpdate("DROP TABLE IF EXISTS `UsageStockInfo`"); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "0.sql").getInputStream() , Charset.forName("UTF-8"))); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "1.sql").getInputStream() , Charset.forName("UTF-8"))); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "2.sql").getInputStream() , Charset.forName("UTF-8"))); } } catch (IOException e) { throw new IllegalStateException("读取SQL失败", e); } }); } }
@PostConstruct @Transactional public void functions() throws SQLException { jdbcService.runJdbcWork(connection -> { String name; if (connection.profile().isMySQL()) { name = "mysql"; } else if (connection.profile().isH2()) { name = "h2"; } else throw new IllegalStateException("not support database platform:" + connection.profile()); try (Statement statement = connection.getConnection().createStatement()) { try { addFunction(name, statement, "agentLevel"); addFunction(name, statement, "agentBelongs"); addFunction(name, statement, "loginBelongs"); } catch (IOException e) { throw new InternalError(e); } } }); }
private void database() throws SQLException { jdbcService.runJdbcWork(connection -> { if (connection.profile().isH2()) { executeSQLCode(connection, "LoginAgentLevel.h2.sql"); } else if (connection.profile().isMySQL()) { if (connection.profile().isMySQL()) { fileName = "mysql"; } else if (connection.profile().isH2()) { fileName = "h2"; } else
} else if (platform.isSybase()) { dbms = "sybase"; } else if (platform.isH2()) { dbms = "h2"; } else {
} else if (platform.isSybase()) { dbms = "sybase"; } else if (platform.isH2()) { dbms = "h2"; } else {