Search in sources :

Example 1 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit by apache.

the class DbDataStore method initDatabaseType.

protected void initDatabaseType() throws DataStoreException {
    boolean failIfNotFound = false;
    if (databaseType == null) {
        if (dataSourceName != null) {
            try {
                databaseType = connectionFactory.getDataBaseType(dataSourceName);
            } catch (RepositoryException e) {
                throw new DataStoreException(e);
            }
        } else {
            if (!url.startsWith("jdbc:")) {
                return;
            }
            int start = "jdbc:".length();
            int end = url.indexOf(':', start);
            databaseType = url.substring(start, end);
        }
    } else {
        failIfNotFound = true;
    }
    InputStream in = DbDataStore.class.getResourceAsStream(databaseType + ".properties");
    if (in == null) {
        if (failIfNotFound) {
            String msg = "Configuration error: The resource '" + databaseType + ".properties' could not be found;" + " Please verify the databaseType property";
            log.debug(msg);
            throw new DataStoreException(msg);
        } else {
            return;
        }
    }
    Properties prop = new Properties();
    try {
        try {
            prop.load(in);
        } finally {
            in.close();
        }
    } catch (IOException e) {
        String msg = "Configuration error: Could not read properties '" + databaseType + ".properties'";
        log.debug(msg);
        throw new DataStoreException(msg, e);
    }
    if (driver == null) {
        driver = getProperty(prop, "driver", driver);
    }
    tableSQL = getProperty(prop, "table", tableSQL);
    createTableSQL = getProperty(prop, "createTable", createTableSQL);
    insertTempSQL = getProperty(prop, "insertTemp", insertTempSQL);
    updateDataSQL = getProperty(prop, "updateData", updateDataSQL);
    updateLastModifiedSQL = getProperty(prop, "updateLastModified", updateLastModifiedSQL);
    updateSQL = getProperty(prop, "update", updateSQL);
    deleteSQL = getProperty(prop, "delete", deleteSQL);
    deleteOlderSQL = getProperty(prop, "deleteOlder", deleteOlderSQL);
    selectMetaSQL = getProperty(prop, "selectMeta", selectMetaSQL);
    selectAllSQL = getProperty(prop, "selectAll", selectAllSQL);
    selectDataSQL = getProperty(prop, "selectData", selectDataSQL);
    storeStream = getProperty(prop, "storeStream", storeStream);
    if (!STORE_SIZE_MINUS_ONE.equals(storeStream) && !STORE_TEMP_FILE.equals(storeStream) && !STORE_SIZE_MAX.equals(storeStream)) {
        String msg = "Unsupported Stream store mechanism: " + storeStream + " supported are: " + STORE_SIZE_MINUS_ONE + ", " + STORE_TEMP_FILE + ", " + STORE_SIZE_MAX;
        log.debug(msg);
        throw new DataStoreException(msg);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CountingInputStream(org.apache.commons.io.input.CountingInputStream) DigestInputStream(java.security.DigestInputStream) InputStream(java.io.InputStream) RepositoryException(javax.jcr.RepositoryException) IOException(java.io.IOException) Properties(java.util.Properties)

Example 2 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class DataStoreBlobStore method getReference.

@Override
public String getReference(@Nonnull String encodedBlobId) {
    checkNotNull(encodedBlobId);
    String blobId = extractBlobId(encodedBlobId);
    //Reference are not created for in memory record
    if (InMemoryDataRecord.isInstance(blobId)) {
        return null;
    }
    DataRecord record;
    try {
        record = delegate.getRecordIfStored(new DataIdentifier(blobId));
        if (record != null) {
            return record.getReference();
        } else {
            log.debug("No blob found for id [{}]", blobId);
        }
    } catch (DataStoreException e) {
        log.warn("Unable to access the blobId for  [{}]", blobId, e);
    }
    return null;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataIdentifier(org.apache.jackrabbit.core.data.DataIdentifier) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 3 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class DataStoreBlobStore method writeBlob.

@Override
public String writeBlob(InputStream stream, BlobOptions options) throws IOException {
    boolean threw = true;
    try {
        long start = System.nanoTime();
        checkNotNull(stream);
        DataRecord dr = writeStream(stream, options);
        String id = getBlobId(dr);
        if (tracker != null && !InMemoryDataRecord.isInstance(id)) {
            try {
                tracker.add(id);
                log.trace("Tracked Id {}", id);
            } catch (Exception e) {
                log.warn("Could not add track id", e);
            }
        }
        threw = false;
        stats.uploaded(System.nanoTime() - start, TimeUnit.NANOSECONDS, dr.getLength());
        stats.uploadCompleted(id);
        return id;
    } catch (DataStoreException e) {
        throw new IOException(e);
    } finally {
        //DataStore does not closes the stream internally
        //So close the stream explicitly
        Closeables.close(stream, threw);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataRecord(org.apache.jackrabbit.core.data.DataRecord) IOException(java.io.IOException) RepositoryException(javax.jcr.RepositoryException) DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class DataStoreBlobStore method getBlobId.

@Override
public String getBlobId(@Nonnull String reference) {
    checkNotNull(reference);
    DataRecord record;
    try {
        record = delegate.getRecordFromReference(reference);
        if (record != null) {
            return getBlobId(record);
        }
    } catch (DataStoreException e) {
        log.warn("Unable to access the blobId for  [{}]", reference, e);
    }
    return null;
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) DataRecord(org.apache.jackrabbit.core.data.DataRecord)

Example 5 with DataStoreException

use of org.apache.jackrabbit.core.data.DataStoreException in project jackrabbit-oak by apache.

the class DataStoreBlobStore method getBlobLength.

@Override
public long getBlobLength(String encodedBlobId) throws IOException {
    try {
        checkNotNull(encodedBlobId, "BlobId must be specified");
        BlobId id = BlobId.of(encodedBlobId);
        if (encodeLengthInId && id.hasLengthInfo()) {
            return id.length;
        }
        return getDataRecord(id.blobId).getLength();
    } catch (DataStoreException e) {
        throw new IOException(e);
    }
}
Also used : DataStoreException(org.apache.jackrabbit.core.data.DataStoreException) IOException(java.io.IOException)

Aggregations

DataStoreException (org.apache.jackrabbit.core.data.DataStoreException)85 IOException (java.io.IOException)35 AmazonServiceException (com.amazonaws.AmazonServiceException)28 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)18 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)15 File (java.io.File)14 AmazonClientException (com.amazonaws.AmazonClientException)12 StorageException (com.microsoft.azure.storage.StorageException)11 InputStream (java.io.InputStream)9 URISyntaxException (java.net.URISyntaxException)9 RepositoryException (javax.jcr.RepositoryException)9 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)7 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)7 Copy (com.amazonaws.services.s3.transfer.Copy)7 Upload (com.amazonaws.services.s3.transfer.Upload)7 FileObject (org.apache.commons.vfs2.FileObject)7 FileSystemException (org.apache.commons.vfs2.FileSystemException)7 BufferedInputStream (java.io.BufferedInputStream)6 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)6 S3Object (com.amazonaws.services.s3.model.S3Object)5