.addRejectCheck(new RejectAttributeChecker.SimpleRejectAttributeChecker(new ModelNode(DatabaseType.MARIA_DB.name())), Attribute.DIALECT.getDefinition());
@Override public void close() { JdbcUtil.safeClose(rs); JdbcUtil.safeClose(ps); connectionFactory.releaseConnection(conn); } }
private static void configureDbMeta(StoreProperties props, JdbcStringBasedStoreConfigurationBuilder builder) { props.required(DIALECT); DatabaseType type = DatabaseType.valueOf(props.get(DIALECT).toUpperCase()); builder.dialect(type); String prop; if ((prop = props.get(DB, MAJOR_VERSION)) != null) { builder.dbMajorVersion(new Integer(prop)); } if ((prop = props.get(DB, MINOR_VERSION)) != null) { builder.dbMinorVersion(new Integer(prop)); } String disableUpsert = props.get(DB, DISABLE_UPSERT); boolean upsert = Boolean.parseBoolean(disableUpsert); if (upsert) builder.addProperty(TableManagerFactory.UPSERT_DISABLED, disableUpsert); String disableIndexing = props.get(DB, DISABLE_INDEXING); boolean indexing = Boolean.parseBoolean(disableIndexing); if (indexing) builder.addProperty(TableManagerFactory.INDEXING_DISABLED, disableIndexing); }
@Override public boolean tableExists(Connection connection, TableName tableName) throws PersistenceException { Objects.requireNonNull(tableName, "table name is mandatory"); ResultSet rs = null; try { DatabaseMetaData metaData = connection.getMetaData(); String schemaPattern = tableName.getSchema() == null ? metaData.getUserName() : tableName.getSchema(); rs = metaData.getTables(null, schemaPattern, tableName.getName(), new String[]{"TABLE"}); return rs.next(); } catch (SQLException e) { if (LOG.isTraceEnabled()) LOG.tracef(e, "SQLException occurs while checking the table %s", tableName); return false; } finally { JdbcUtil.safeClose(rs); } }
public void testTableQuoting() throws Exception { tableManager.setCacheName("my.cache"); assert !existsTable(connection, tableManager.getTableName()); tableManager.createTable(connection); assert existsTable(connection, tableManager.getTableName()); }
private void executeUpsert(Connection connection, MarshalledEntry entry, String keyStr, int segment) throws InterruptedException, SQLException { PreparedStatement ps = null; String sql = tableManager.getUpsertRowSql(); if (trace) { log.tracef("Running sql '%s'. Key string is '%s'", sql, keyStr); } try { ps = connection.prepareStatement(sql); prepareUpsertStatement(entry, keyStr, segment, ps); ps.executeUpdate(); } finally { JdbcUtil.safeClose(ps); } }
public void executeUpdateSql(Connection conn, String sql) throws PersistenceException { Statement statement = null; try { statement = conn.createStatement(); statement.executeUpdate(sql); } catch (SQLException e) { log.errorCreatingTable(sql, e); throw new PersistenceException(e); } finally { JdbcUtil.safeClose(statement); } }
public void testCreateTable() throws Exception { assert !existsTable(connection, tableManager.getTableName()); tableManager.createTable(connection); assert existsTable(connection, tableManager.getTableName()); }
private void assertTableExistence(Connection connection, String identifierQuote, String secondTable, String firstTable, String tablePrefix) throws Exception { assert !TableManagerTest.existsTable(connection, new TableName(identifierQuote, tablePrefix, "")) : "this table should not exist!"; assert TableManagerTest.existsTable(connection, new TableName(identifierQuote, tablePrefix, firstTable)); assert TableManagerTest.existsTable(connection, new TableName(identifierQuote, tablePrefix, secondTable)); connection.close(); }
static boolean existsTable(Connection connection, TableName tableName) throws Exception { Statement st = connection.createStatement(); ResultSet rs = null; try { rs = st.executeQuery("select * from " + tableName); return true; } catch (SQLException e) { return false; } finally { JdbcUtil.safeClose(rs); JdbcUtil.safeClose(st); } } }
@BeforeClass public void bindDatasourceInJndi() throws Exception { System.setProperty(Context.INITIAL_CONTEXT_FACTORY, DummyContextFactory.class.getName()); ds = new DummyDataSource(); ds.start(); InitialContext ic = new InitialContext(); ic.bind(getDatasourceLocation(), ds); assert ic.lookup(getDatasourceLocation()) instanceof DummyDataSource; }
@AfterClass public void destroyDatasourceAndUnbind() throws NamingException { InitialContext ic = new InitialContext(); ic.unbind(getDatasourceLocation()); assert ic.lookup(getDatasourceLocation()) == null; ds.stop(); }
@Test(expectedExceptions = PersistenceException.class) public void testHikariCPNoDriverClassFound() throws Exception { testNoDriverClassFound(); }
@Test public void testHikariCPLoaded() throws Exception { testConnectionPoolLoaded(HikariConnectionPool.class); }
@Test public void testHikariValuesNoOverrides() throws Exception { testValuesNoOverrides(); }
@Override public Connection getConnection(String username, String password) throws SQLException { return getConnection(); }
@Test(expectedExceptions = PersistenceException.class) public void testC3PONoDriverClassFound() throws Exception { System.setProperty("infinispan.jdbc.c3p0.force", "true"); testNoDriverClassFound(); }
@Test public void testC3POLoaded() throws Exception { System.setProperty("infinispan.jdbc.c3p0.force", "true"); testConnectionPoolLoaded(C3P0ConnectionPool.class); }
@Test public void testC3P0ValuesNoOverrides() throws Exception { System.setProperty("infinispan.jdbc.c3p0.force", "true"); testValuesNoOverrides(); }