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);
}
}
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;
}
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);
}
}
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;
}
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);
}
}
Aggregations