Search in sources :

Example 1 with RDBBlobStore

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore in project jackrabbit-oak by apache.

the class OakFixture method getRDB.

public static OakFixture getRDB(final String name, final String jdbcuri, final String jdbcuser, final String jdbcpasswd, final String tablePrefix, final boolean dropDBAfterTest, final long cacheSize, final boolean useDataStore, final File base, final int dsCacheInMB) {
    return new OakFixture(name) {

        private DocumentMK[] kernels;

        private BlobStoreFixture blobStoreFixture;

        private RDBOptions getOptions(boolean dropDBAFterTest, String tablePrefix) {
            return new RDBOptions().dropTablesOnClose(dropDBAfterTest).tablePrefix(tablePrefix);
        }

        private BlobStore getBlobStore(StatisticsProvider statsProvider) {
            try {
                if (useDataStore) {
                    initializeBlobStoreFixture(statsProvider);
                    return blobStoreFixture.setUp();
                } else {
                    DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                    return new RDBBlobStore(ds, getOptions(dropDBAfterTest, tablePrefix));
                }
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }

        @Override
        public Oak getOak(int clusterId) throws Exception {
            DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
            DocumentMK.Builder mkBuilder = new DocumentMK.Builder().setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setClusterId(clusterId).setLogging(false);
            BlobStore blobStore = getBlobStore(StatisticsProvider.NOOP);
            if (blobStore != null) {
                mkBuilder.setBlobStore(blobStore);
            }
            DocumentMK dmk = mkBuilder.open();
            return newOak(dmk.getNodeStore());
        }

        @Override
        public Oak[] setUpCluster(int n, StatisticsProvider statsProvider) throws Exception {
            Oak[] cluster = new Oak[n];
            kernels = new DocumentMK[cluster.length];
            for (int i = 0; i < cluster.length; i++) {
                BlobStore blobStore = getBlobStore(statsProvider);
                DataSource ds = RDBDataSourceFactory.forJdbcUrl(jdbcuri, jdbcuser, jdbcpasswd);
                DocumentMK.Builder mkBuilder = new DocumentMK.Builder().setStatisticsProvider(statsProvider).setRDBConnection(ds, getOptions(dropDBAfterTest, tablePrefix)).memoryCacheSize(cacheSize).setLeaseCheck(false).setClusterId(i + 1).setLogging(false);
                if (blobStore != null) {
                    mkBuilder.setBlobStore(blobStore);
                }
                kernels[i] = mkBuilder.open();
                cluster[i] = newOak(kernels[i].getNodeStore());
            }
            return cluster;
        }

        @Override
        public void tearDownCluster() {
            String dropped = "";
            for (DocumentMK kernel : kernels) {
                kernel.dispose();
                if (kernel.getDocumentStore() instanceof RDBDocumentStore) {
                    dropped += ((RDBDocumentStore) kernel.getDocumentStore()).getDroppedTables();
                }
            }
            if (dropDBAfterTest) {
                if (blobStoreFixture != null) {
                    blobStoreFixture.tearDown();
                }
                if (dropped.isEmpty()) {
                    throw new RuntimeException("dropdb was set, but tables have not been dropped");
                }
            }
        }

        private void initializeBlobStoreFixture(StatisticsProvider statsProvider) {
            if (useDataStore && blobStoreFixture == null) {
                blobStoreFixture = BlobStoreFixture.create(base, true, dsCacheInMB, statsProvider);
            }
        }
    };
}
Also used : DocumentMK(org.apache.jackrabbit.oak.plugins.document.DocumentMK) StatisticsProvider(org.apache.jackrabbit.oak.stats.StatisticsProvider) RDBOptions(org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions) UnknownHostException(java.net.UnknownHostException) DataSource(javax.sql.DataSource) RDBDocumentStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore) Oak(org.apache.jackrabbit.oak.Oak) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) BlobStore(org.apache.jackrabbit.oak.spi.blob.BlobStore)

Example 2 with RDBBlobStore

use of org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore in project jackrabbit-oak by apache.

the class JdbcFactory method hasExternalBlobReferences.

@Override
public boolean hasExternalBlobReferences() throws IOException {
    Closer closer = Closer.create();
    try {
        DataSource ds = getDataSource(closer);
        RDBBlobStore blobStore = new RDBBlobStore(ds);
        return !blobStore.getAllChunkIds(0).hasNext();
    } catch (Throwable e) {
        throw closer.rethrow(e);
    } finally {
        closer.close();
    }
}
Also used : Closer(com.google.common.io.Closer) RDBBlobStore(org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore) DataSource(javax.sql.DataSource)

Aggregations

DataSource (javax.sql.DataSource)2 RDBBlobStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBBlobStore)2 Closer (com.google.common.io.Closer)1 UnknownHostException (java.net.UnknownHostException)1 Oak (org.apache.jackrabbit.oak.Oak)1 DocumentMK (org.apache.jackrabbit.oak.plugins.document.DocumentMK)1 RDBDocumentStore (org.apache.jackrabbit.oak.plugins.document.rdb.RDBDocumentStore)1 RDBOptions (org.apache.jackrabbit.oak.plugins.document.rdb.RDBOptions)1 BlobStore (org.apache.jackrabbit.oak.spi.blob.BlobStore)1 StatisticsProvider (org.apache.jackrabbit.oak.stats.StatisticsProvider)1