use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.
the class BLOBInDataStore method getInstance.
static BLOBInDataStore getInstance(DataStore store, InputStream in) throws DataStoreException {
DataRecord rec = store.addRecord(in);
DataIdentifier identifier = rec.getIdentifier();
if (auditLogger.isDebugEnabled()) {
auditLogger.debug("{} ({})", identifier, rec.getLength());
}
return new BLOBInDataStore(store, identifier);
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.
the class InternalValue method create.
/**
* Create a new internal value from the given JCR value.
* If the data store is enabled, large binary values are stored in the data store.
*
* @param value the JCR value
* @param resolver
* @param store the data store
* @return the created internal value
* @throws RepositoryException
* @throws ValueFormatException
*/
public static InternalValue create(Value value, NamePathResolver resolver, DataStore store) throws ValueFormatException, RepositoryException {
switch(value.getType()) {
case PropertyType.BINARY:
BLOBFileValue blob = null;
if (value instanceof BinaryValueImpl) {
BinaryValueImpl bin = (BinaryValueImpl) value;
DataIdentifier identifier = bin.getDataIdentifier();
if (identifier != null) {
if (bin.usesDataStore(store)) {
// access the record to ensure it is not garbage collected
store.getRecord(identifier);
blob = BLOBInDataStore.getInstance(store, identifier);
} else {
if (store.getRecordIfStored(identifier) != null) {
// it exists - so we don't need to stream it again
// but we need to create a new object because the original
// one might be in a different data store (repository)
blob = BLOBInDataStore.getInstance(store, identifier);
}
}
}
}
if (blob == null) {
Binary b = value.getBinary();
boolean dispose = false;
try {
if (b instanceof BLOBFileValue) {
// use as is
blob = (BLOBFileValue) b;
} else {
// create a copy from the stream
dispose = true;
blob = getBLOBFileValue(store, b.getStream(), true);
}
} finally {
if (dispose) {
b.dispose();
}
}
}
return new InternalValue(blob);
case PropertyType.BOOLEAN:
return create(value.getBoolean());
case PropertyType.DATE:
return create(value.getDate());
case PropertyType.DOUBLE:
return create(value.getDouble());
case PropertyType.DECIMAL:
return create(value.getDecimal());
case PropertyType.LONG:
return create(value.getLong());
case PropertyType.REFERENCE:
return create(new NodeId(value.getString()));
case PropertyType.WEAKREFERENCE:
return create(new NodeId(value.getString()), true);
case PropertyType.URI:
try {
return create(new URI(value.getString()));
} catch (URISyntaxException e) {
throw new ValueFormatException(e.getMessage());
}
case PropertyType.NAME:
try {
if (value instanceof QValueValue) {
QValue qv = ((QValueValue) value).getQValue();
if (qv instanceof InternalValue) {
return (InternalValue) qv;
} else {
return create(qv.getName());
}
} else {
return create(resolver.getQName(value.getString()));
}
} catch (NameException e) {
throw new ValueFormatException(e.getMessage());
}
case PropertyType.PATH:
try {
if (value instanceof QValueValue) {
QValue qv = ((QValueValue) value).getQValue();
if (qv instanceof InternalValue) {
return (InternalValue) qv;
} else {
return create(qv.getPath());
}
} else {
return create(resolver.getQPath(value.getString(), false));
}
} catch (MalformedPathException mpe) {
throw new ValueFormatException(mpe.getMessage());
}
case PropertyType.STRING:
return create(value.getString());
default:
throw new IllegalArgumentException("illegal value");
}
}
use of org.apache.jackrabbit.core.data.DataIdentifier in project jackrabbit by apache.
the class ValueFactoryImpl method createValue.
@Override
public Value createValue(Binary binary) {
try {
if (binary instanceof BLOBInDataStore) {
BLOBInDataStore blob = (BLOBInDataStore) binary;
DataIdentifier identifier = blob.getDataIdentifier();
InternalValue value;
if (blob.usesDataStore(store)) {
value = InternalValue.getInternalValue(identifier, store, false);
} else {
value = InternalValue.getInternalValue(identifier, store, true);
}
if (value != null) {
// if the value is already in this data store
return new BinaryValueImpl(value.getBLOBFileValue());
}
} else if (binary instanceof BLOBFileValue) {
return new BinaryValueImpl(((BLOBFileValue) binary).copy());
} else if (binary instanceof ReferenceBinary) {
String reference = ((ReferenceBinary) binary).getReference();
DataRecord record = store.getRecordFromReference(reference);
if (record != null) {
return new BinaryValueImpl(BLOBInDataStore.getInstance(store, record.getIdentifier()));
}
}
return createValue(binary.getStream());
} catch (RepositoryException e) {
log.error(e.getMessage(), e);
// ignore - the super method may be smarter
}
return super.createValue(binary);
}
use of org.apache.jackrabbit.core.data.DataIdentifier 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.DataIdentifier in project jackrabbit-oak by apache.
the class OakFileDataStore method getAllRecords.
@Override
public Iterator<DataRecord> getAllRecords() {
final String path = normalizeNoEndSeparator(new File(getPath()).getAbsolutePath());
final OakFileDataStore store = this;
return Files.fileTreeTraverser().postOrderTraversal(new File(path)).filter(new Predicate<File>() {
@Override
public boolean apply(File input) {
return input.isFile() && !input.getParent().equals(path);
}
}).transform(new Function<File, DataRecord>() {
@Override
public DataRecord apply(File input) {
return new FileDataRecord(store, new DataIdentifier(input.getName()), input);
}
}).iterator();
}
Aggregations