Search in sources :

Example 1 with SQLProvider

use of org.apache.activemq.artemis.jdbc.store.sql.SQLProvider in project activemq-artemis by apache.

the class PagingStoreFactoryDatabase method newFileFactory.

private synchronized SequentialFileFactory newFileFactory(final String directoryName, boolean writeToDirectory) throws Exception {
    JDBCSequentialFile directoryList = (JDBCSequentialFile) pagingFactoryFileFactory.createSequentialFile(DIRECTORY_NAME);
    directoryList.open();
    SimpleString simpleString = SimpleString.toSimpleString(directoryName);
    ActiveMQBuffer buffer = ActiveMQBuffers.fixedBuffer(simpleString.sizeof());
    buffer.writeSimpleString(simpleString);
    if (writeToDirectory)
        directoryList.write(buffer, true);
    directoryList.close();
    final SQLProvider sqlProvider;
    if (dbConf.getDataSource() != null) {
        final SQLProvider.Factory sqlProviderFactory;
        if (dbConf.getSqlProviderFactory() != null) {
            sqlProviderFactory = dbConf.getSqlProviderFactory();
        } else {
            sqlProviderFactory = new PropertySQLProvider.Factory(dbConf.getDataSource());
        }
        sqlProvider = sqlProviderFactory.create(getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE);
    } else {
        sqlProvider = JDBCUtils.getSQLProvider(dbConf.getJdbcDriverClassName(), getTableNameForGUID(directoryName), SQLProvider.DatabaseStoreType.PAGE);
    }
    final JDBCSequentialFileFactory fileFactory = new JDBCSequentialFileFactory(pagingFactoryFileFactory.getDbDriver().getConnection(), sqlProvider, executorFactory.getExecutor(), criticalErrorListener);
    final int jdbcNetworkTimeout = dbConf.getJdbcNetworkTimeout();
    if (jdbcNetworkTimeout >= 0) {
        fileFactory.setNetworkTimeout(this.executorFactory.getExecutor(), jdbcNetworkTimeout);
    }
    return fileFactory;
}
Also used : PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) JDBCSequentialFile(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) JDBCSequentialFileFactory(org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory) ActiveMQBuffer(org.apache.activemq.artemis.api.core.ActiveMQBuffer)

Example 2 with SQLProvider

use of org.apache.activemq.artemis.jdbc.store.sql.SQLProvider in project activemq-artemis by apache.

the class JdbcNodeManager method with.

public static JdbcNodeManager with(DatabaseStorageConfiguration configuration, ScheduledExecutorService scheduledExecutorService, ExecutorFactory executorFactory, IOCriticalErrorListener ioCriticalErrorListener) {
    if (configuration.getDataSource() != null) {
        final SQLProvider.Factory sqlProviderFactory;
        if (configuration.getSqlProviderFactory() != null) {
            sqlProviderFactory = configuration.getSqlProviderFactory();
        } else {
            sqlProviderFactory = new PropertySQLProvider.Factory(configuration.getDataSource());
        }
        final String brokerId = java.util.UUID.randomUUID().toString();
        return usingDataSource(brokerId, configuration.getJdbcLockExpirationMillis(), configuration.getJdbcLockRenewPeriodMillis(), configuration.getJdbcLockAcquisitionTimeoutMillis(), configuration.getJdbcMaxAllowedMillisFromDbTime(), configuration.getDataSource(), sqlProviderFactory.create(configuration.getNodeManagerStoreTableName(), SQLProvider.DatabaseStoreType.NODE_MANAGER), scheduledExecutorService, executorFactory, ioCriticalErrorListener);
    } else {
        final SQLProvider sqlProvider = JDBCUtils.getSQLProvider(configuration.getJdbcDriverClassName(), configuration.getNodeManagerStoreTableName(), SQLProvider.DatabaseStoreType.NODE_MANAGER);
        final String brokerId = java.util.UUID.randomUUID().toString();
        return usingConnectionUrl(brokerId, configuration.getJdbcLockExpirationMillis(), configuration.getJdbcLockRenewPeriodMillis(), configuration.getJdbcLockAcquisitionTimeoutMillis(), configuration.getJdbcMaxAllowedMillisFromDbTime(), configuration.getJdbcConnectionUrl(), configuration.getJdbcDriverClassName(), sqlProvider, scheduledExecutorService, executorFactory, ioCriticalErrorListener);
    }
}
Also used : PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider) PropertySQLProvider(org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider)

Example 3 with SQLProvider

use of org.apache.activemq.artemis.jdbc.store.sql.SQLProvider in project activemq-artemis by apache.

the class ActiveMQTestBase method destroyTables.

public void destroyTables(List<String> tableNames) throws Exception {
    Driver driver = getDriver(getJDBCClassName());
    Connection connection = driver.connect(getTestJDBCConnectionUrl(), null);
    Statement statement = connection.createStatement();
    try {
        for (String tableName : tableNames) {
            connection.setAutoCommit(false);
            SQLProvider sqlProvider = JDBCUtils.getSQLProvider(getJDBCClassName(), tableName, SQLProvider.DatabaseStoreType.LARGE_MESSAGE);
            try (ResultSet rs = connection.getMetaData().getTables(null, null, sqlProvider.getTableName(), null)) {
                if (rs.next()) {
                    statement.execute("DROP TABLE " + sqlProvider.getTableName());
                }
                connection.commit();
            } catch (SQLException e) {
                connection.rollback();
            }
        }
        connection.setAutoCommit(true);
    } catch (Throwable e) {
        e.printStackTrace();
    } finally {
        connection.close();
    }
}
Also used : SQLException(java.sql.SQLException) Statement(java.sql.Statement) ClusterConnection(org.apache.activemq.artemis.core.server.cluster.ClusterConnection) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Driver(java.sql.Driver) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SQLProvider(org.apache.activemq.artemis.jdbc.store.sql.SQLProvider)

Aggregations

SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 SQLProvider (org.apache.activemq.artemis.jdbc.store.sql.SQLProvider)3 PropertySQLProvider (org.apache.activemq.artemis.jdbc.store.sql.PropertySQLProvider)2 Connection (java.sql.Connection)1 Driver (java.sql.Driver)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)1 ClusterConnection (org.apache.activemq.artemis.core.server.cluster.ClusterConnection)1 JDBCSequentialFile (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFile)1 JDBCSequentialFileFactory (org.apache.activemq.artemis.jdbc.store.file.JDBCSequentialFileFactory)1