Search in sources :

Example 46 with InternalValue

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);
}
Also used : InternalValue(org.apache.jackrabbit.core.value.InternalValue)

Example 47 with InternalValue

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();
}
Also used : IterablePersistenceManager(org.apache.jackrabbit.core.persistence.IterablePersistenceManager) NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeInfo(org.apache.jackrabbit.core.persistence.util.NodeInfo) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 48 with InternalValue

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
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) NodeId(org.apache.jackrabbit.core.id.NodeId) InternalValue(org.apache.jackrabbit.core.value.InternalValue) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.core.id.PropertyId) PropertyState(org.apache.jackrabbit.core.state.PropertyState)

Example 49 with InternalValue

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;
}
Also used : IOException(java.io.IOException) InternalValue(org.apache.jackrabbit.core.value.InternalValue) IOException(java.io.IOException) IOExceptionWithCause(org.apache.commons.io.IOExceptionWithCause)

Example 50 with InternalValue

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());
}
Also used : InternalValue(org.apache.jackrabbit.core.value.InternalValue)

Aggregations

InternalValue (org.apache.jackrabbit.core.value.InternalValue)62 Name (org.apache.jackrabbit.spi.Name)21 NodeId (org.apache.jackrabbit.core.id.NodeId)20 PropertyState (org.apache.jackrabbit.core.state.PropertyState)17 RepositoryException (javax.jcr.RepositoryException)16 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)13 PropertyId (org.apache.jackrabbit.core.id.PropertyId)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)11 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)11 NodeState (org.apache.jackrabbit.core.state.NodeState)10 Value (javax.jcr.Value)9 IOException (java.io.IOException)7 InputStream (java.io.InputStream)6 HashMap (java.util.HashMap)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)6 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)6 ArrayList (java.util.ArrayList)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)4 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)4 Path (org.apache.jackrabbit.spi.Path)4