use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class ProtectedItemModifier method setProperty.
protected Property setProperty(NodeImpl parentImpl, Name name, Value value, boolean ignorePermissions) throws RepositoryException {
if (!ignorePermissions) {
checkPermission(parentImpl, name, getPermission(false, false));
}
// validation: make sure Node is not locked or checked-in.
parentImpl.checkSetProperty();
InternalValue intVs = InternalValue.create(value, parentImpl.sessionContext);
return parentImpl.internalSetProperty(name, intVs);
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class GarbageCollector method scanPersistenceManagersByNodeInfos.
private void scanPersistenceManagersByNodeInfos() throws RepositoryException, ItemStateException {
int pmCount = 0;
for (IterablePersistenceManager pm : pmList) {
pmCount++;
int count = 0;
Map<NodeId, NodeInfo> batch = pm.getAllNodeInfos(null, NODESATONCE);
while (!batch.isEmpty()) {
NodeId lastId = null;
for (NodeInfo info : batch.values()) {
count++;
if (count % 1000 == 0) {
LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes...");
}
lastId = info.getId();
if (callback != null) {
callback.beforeScanning(null);
}
if (info.hasBlobsInDataStore()) {
try {
NodeState state = pm.load(info.getId());
Set<Name> propertyNames = state.getPropertyNames();
for (Name name : propertyNames) {
PropertyId pid = new PropertyId(info.getId(), name);
PropertyState ps = pm.load(pid);
if (ps.getType() == PropertyType.BINARY) {
for (InternalValue v : ps.getValues()) {
// getLength will update the last modified date
// if the persistence manager scan is running
v.getLength();
}
}
}
} catch (NoSuchItemStateException ignored) {
// the node may have been deleted in the meantime
}
}
}
batch = pm.getAllNodeInfos(lastId, NODESATONCE);
}
}
NodeInfo.clearPool();
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class GarbageCollector method scanNodeIdList.
private void scanNodeIdList(int split, List<NodeId> nodeList, PersistenceManager pm, int pmCount) throws RepositoryException, ItemStateException {
int count = 0;
for (NodeId id : nodeList) {
count++;
if (count % 1000 == 0) {
if (split > 0) {
LOG.debug("[Split " + split + "] " + pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
} else {
LOG.debug(pm.toString() + " (" + pmCount + "/" + pmList.length + "): analyzed " + count + " nodes [" + nodeList.size() + "]...");
}
}
if (callback != null) {
callback.beforeScanning(null);
}
try {
NodeState state = pm.load(id);
Set<Name> propertyNames = state.getPropertyNames();
for (Name name : propertyNames) {
PropertyId pid = new PropertyId(id, name);
PropertyState ps = pm.load(pid);
if (ps.getType() == PropertyType.BINARY) {
for (InternalValue v : ps.getValues()) {
// getLength will update the last modified date
// if the persistence manager scan is running
v.getLength();
}
}
}
} catch (NoSuchItemStateException e) {
// the node may have been deleted or moved in the meantime
// ignore it
}
}
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class BundleReader method readPropertyEntry.
/**
* Deserializes a <code>PropertyState</code> from the data input stream.
*
* @param id the property id for the new property entry
* @return the property entry
* @throws IOException if an I/O error occurs.
*/
private NodePropBundle.PropertyEntry readPropertyEntry(PropertyId id) throws IOException {
NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id);
int count = 1;
if (version >= BundleBinding.VERSION_3) {
int b = in.readUnsignedByte();
entry.setType(b & 0x0f);
int len = b >>> 4;
if (len != 0) {
entry.setMultiValued(true);
if (len == 0x0f) {
count = readVarInt() + 0x0f - 1;
} else {
count = len - 1;
}
}
entry.setModCount((short) readVarInt());
} else {
// type and modcount
int type = in.readInt();
entry.setModCount((short) ((type >> 16) & 0x0ffff));
type &= 0x0ffff;
entry.setType(type);
// multiValued
entry.setMultiValued(in.readBoolean());
// definitionId
in.readUTF();
// count
count = in.readInt();
}
// values
InternalValue[] values = new InternalValue[count];
String[] blobIds = new String[count];
for (int i = 0; i < count; i++) {
InternalValue val;
int type = entry.getType();
switch(type) {
case PropertyType.BINARY:
int size = in.readInt();
if (size == BundleBinding.BINARY_IN_DATA_STORE) {
val = InternalValue.create(binding.dataStore, readString());
} else if (size == BundleBinding.BINARY_IN_BLOB_STORE) {
blobIds[i] = readString();
try {
BLOBStore blobStore = binding.getBlobStore();
if (blobStore instanceof ResourceBasedBLOBStore) {
val = InternalValue.create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i]));
} else {
val = InternalValue.create(blobStore.get(blobIds[i]));
}
} catch (IOException e) {
if (binding.errorHandling.ignoreMissingBlobs()) {
log.warn("Ignoring error while reading blob-resource: " + e);
val = InternalValue.create(new byte[0]);
} else {
throw e;
}
} catch (Exception e) {
throw new IOExceptionWithCause("Unable to create property value: " + e.toString(), e);
}
} else {
// short values into memory
byte[] data = new byte[size];
in.readFully(data);
val = InternalValue.create(data);
}
break;
case PropertyType.DOUBLE:
val = InternalValue.create(in.readDouble());
break;
case PropertyType.DECIMAL:
val = InternalValue.create(readDecimal());
break;
case PropertyType.LONG:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.create(readVarLong());
} else {
val = InternalValue.create(in.readLong());
}
break;
case PropertyType.BOOLEAN:
val = InternalValue.create(in.readBoolean());
break;
case PropertyType.NAME:
val = InternalValue.create(readQName());
break;
case PropertyType.WEAKREFERENCE:
val = InternalValue.create(readNodeId(), true);
break;
case PropertyType.REFERENCE:
val = InternalValue.create(readNodeId(), false);
break;
case PropertyType.DATE:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.create(readDate());
break;
}
// else fall through
default:
if (version >= BundleBinding.VERSION_3) {
val = InternalValue.valueOf(readString(), entry.getType());
} else {
// because writeUTF(String) has a size limit of 64k,
// Strings are serialized as <length><byte[]>
int len = in.readInt();
byte[] bytes = new byte[len];
in.readFully(bytes);
String stringVal = new String(bytes, "UTF-8");
// https://issues.apache.org/jira/browse/JCR-3083
if (PropertyType.DATE == entry.getType()) {
val = InternalValue.createDate(stringVal);
} else {
val = InternalValue.valueOf(stringVal, entry.getType());
}
}
}
values[i] = val;
}
entry.setValues(values);
entry.setBlobIds(blobIds);
return entry;
}
use of org.apache.jackrabbit.core.value.InternalValue in project jackrabbit by apache.
the class InMemPersistenceManager method destroy.
/**
* {@inheritDoc}
*/
protected void destroy(PropertyState state) throws ItemStateException {
if (!initialized) {
throw new IllegalStateException("not initialized");
}
// delete binary values (stored as files)
InternalValue[] values = state.getValues();
if (values != null) {
for (InternalValue val : values) {
if (val != null) {
val.deleteBinaryResource();
}
}
}
// remove property state
stateStore.remove(state.getPropertyId());
}
Aggregations