Search in sources :

Example 1 with UnknownDatabaseException

use of org.structr.api.UnknownDatabaseException in project structr by structr.

the class GraphObject method setPropertiesInternal.

/**
 * Sets the given properties.
 *
 * @param securityContext
 * @param properties
 * @param isCreation
 */
default void setPropertiesInternal(final SecurityContext securityContext, final PropertyMap properties, final boolean isCreation) 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 (value != null && key.isPropertyTypeIndexable() && key.relatedType() == null) {
            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, oldValue, 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, oldValue, 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, isCreation);
        }
    }
    if (atLeastOnePropertyChanged) {
        try {
            // set primitive values directly for better performance
            getPropertyContainer().setProperties(container.getData());
        } catch (UnknownClientException | UnknownDatabaseException e) {
            final Logger logger = LoggerFactory.getLogger(GraphObject.class);
            logger.warn("Unable to set properties of {} with UUID {}: {}", getType(), getUuid(), e.getMessage());
            logger.warn("Properties: {}", container.getData());
        }
    }
}
Also used : UnknownDatabaseException(org.structr.api.UnknownDatabaseException) TypeProperty(org.structr.core.property.TypeProperty) UnknownClientException(org.structr.api.UnknownClientException) AbstractRelationship(org.structr.core.entity.AbstractRelationship) CreationContainer(org.structr.core.graph.CreationContainer) Logger(org.slf4j.Logger) PropertyKey(org.structr.core.property.PropertyKey) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

Logger (org.slf4j.Logger)1 UnknownClientException (org.structr.api.UnknownClientException)1 UnknownDatabaseException (org.structr.api.UnknownDatabaseException)1 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