Search in sources :

Example 1 with TypeProperty

use of org.structr.core.property.TypeProperty in project structr by structr.

the class GraphObject method setProperties.

/**
 * Sets the given properties.
 *
 * @param securityContext
 * @param properties
 * @throws FrameworkException
 */
default void setProperties(final SecurityContext securityContext, final PropertyMap properties) throws FrameworkException {
    final CreationContainer container = new CreationContainer(this);
    boolean atLeastOnePropertyChanged = false;
    for (final Entry<PropertyKey, Object> attr : properties.entrySet()) {
        final PropertyKey key = attr.getKey();
        final Object value = attr.getValue();
        if (key.indexable(value)) {
            final Object oldValue = getProperty(key);
            if (!value.equals(oldValue)) {
                atLeastOnePropertyChanged = true;
                // bulk set possible, store in container
                key.setProperty(securityContext, container, value);
                if (isNode()) {
                    if (!key.isUnvalidated()) {
                        TransactionCommand.nodeModified(securityContext.getCachedUser(), (AbstractNode) this, key, getProperty(key), value);
                    }
                    if (key instanceof TypeProperty) {
                        if (this instanceof NodeInterface) {
                            final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
                            TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
                        }
                    }
                } else if (isRelationship()) {
                    if (!key.isUnvalidated()) {
                        TransactionCommand.relationshipModified(securityContext.getCachedUser(), (AbstractRelationship) this, key, getProperty(key), value);
                    }
                    if (key instanceof TypeProperty) {
                        if (this instanceof NodeInterface) {
                            final Class type = StructrApp.getConfiguration().getNodeEntityClass((String) value);
                            TypeProperty.updateLabels(StructrApp.getInstance().getDatabaseService(), (NodeInterface) this, type, true);
                        }
                    }
                }
            }
        } else {
            // bulk set NOT possible, set on entity
            if (key.isSystemInternal()) {
                unlockSystemPropertiesOnce();
            }
            setProperty(key, value);
        }
    }
    if (atLeastOnePropertyChanged) {
        // set primitive values directly for better performance
        getPropertyContainer().setProperties(container.getData());
    }
}
Also used : TypeProperty(org.structr.core.property.TypeProperty) AbstractRelationship(org.structr.core.entity.AbstractRelationship) CreationContainer(org.structr.core.graph.CreationContainer) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

AbstractRelationship (org.structr.core.entity.AbstractRelationship)1 CreationContainer (org.structr.core.graph.CreationContainer)1 NodeInterface (org.structr.core.graph.NodeInterface)1 PropertyKey (org.structr.core.property.PropertyKey)1 TypeProperty (org.structr.core.property.TypeProperty)1