Package org.neo4j.graphdb

Examples of org.neo4j.graphdb.PropertyContainer


    @SuppressWarnings("unchecked")
    public <T> T projectTo(Object entity, Class<T> targetType, MappingPolicy mappingPolicy, final Neo4jTemplate template) {
        if (targetType.isInstance(entity)) {
            return (T)entity;
        }
        PropertyContainer state = getPersistentState(entity);
        final MappingPolicy newPolicy = mappingPolicy == null ? getMappingPolicy(targetType) : mappingPolicy;
        return createEntityFromState(state, targetType, newPolicy, template);
    }
View Full Code Here


        if (!mappingPolicy.shouldLoad()) return value;
        if (property.getTypeInformation().isCollectionLike()) {
            List<Object> replacement = new ArrayList<Object>();
            for (Object inner : ((Iterable) value)) {
                final BeanWrapper<Object> innerWrapper = BeanWrapper.create(inner, conversionService);
                final PropertyContainer state = entityStateHandler.getPersistentState(inner);
                fetchValue(innerWrapper, state, persistentEntity, mappingPolicy, template);
                replacement.add(inner);
                //sourceStateTransmitter.copyPropertiesFrom(innerWrapper, entityStateHandler.<S>getPersistentState(inner), persistentEntity);
            }
            return replacement;
        } else {
            final BeanWrapper<Object> innerWrapper = BeanWrapper.create(value, conversionService);
            final PropertyContainer state = entityStateHandler.getPersistentState(value);
            fetchValue(innerWrapper, state, persistentEntity, mappingPolicy, template);
//                        sourceStateTransmitter.copyPropertiesFrom(innerWrapper, entityStateHandler.<S>getPersistentState(value), persistentEntity);
        }
        return value;
    }
View Full Code Here

    }


    @Override
    public Long getId(T entity) {
        final PropertyContainer state = template.getPersistentState(entity);
        if (isNodeEntity()) {
            return ((Node)state).getId();
        }
        else {
            return ((Relationship) state).getId();
View Full Code Here

            this.field = field;
        }

        @Override
        public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
          final PropertyContainer propertyContainer = template.getPersistentState(entity);
          PrefixedDynamicProperties dynamicProperties;
            if (newVal instanceof ManagedPrefixedDynamicProperties) {
                // newVal is already a managed container
                dynamicProperties = (ManagedPrefixedDynamicProperties) newVal;
            }
            else {
                // newVal is not a managed prefixed container and therefore contains
                // pure key/values that must be converted to a prefixed form
            dynamicProperties = new PrefixedDynamicProperties(propertyNamePrefix);
                if (newVal != null) {
                    DynamicProperties newPropertiesVal = (DynamicProperties) newVal;
                    for (String key : newPropertiesVal.getPropertyKeys()) {
                        dynamicProperties.setProperty(key, newPropertiesVal.getProperty(key));
                    }
                }
            }


            Set<String> dynamicProps = dynamicProperties.getPrefixedPropertyKeys();
            Set<String> nodeProps = new HashSet<String>();
            IteratorUtil.addToCollection(propertyContainer.getPropertyKeys(), nodeProps);

            // Get the properties that are not present in the DynamicProperties container anymore
            // by removing all present keys from the actual node properties.
            for (String prop : dynamicProps) {
              nodeProps.remove(prop);
            }
           
            // nodeProps now contains the properties that are present on the node, but not in the DynamicProperties -
            // in other words: properties that have been removed. Remove them from the node as well.
      for(String removedKey : nodeProps) {
        if (dynamicProperties.isPrefixedKey(removedKey)) {
          propertyContainer.removeProperty(removedKey);
        }
      }
           
      // Add all properties to the propertyContainer
            for (String key : dynamicProps) {
                propertyContainer.setProperty(key, dynamicProperties.getPrefixedProperty(key));
            }
            return newVal;
        }
View Full Code Here

            return newVal;
        }

        @Override
        public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
            PropertyContainer element = template.getPersistentState(entity);
            ManagedPrefixedDynamicProperties props = ManagedPrefixedDynamicProperties.create(propertyNamePrefix, field, entity, template,this, field.getMappingPolicy());
            for (String key : element.getPropertyKeys()) {
                props.setPropertyIfPrefixed(key, element.getProperty(key));
            }
            return DoReturn.doReturn(props);
        }
View Full Code Here

            return true;
        }

        @Override
        public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
            final PropertyContainer propertyContainer = template.getPersistentState(entity);
            try {
                if (newVal==null) {
                    propertyContainer.removeProperty(propertyName);
                } else {
                    propertyContainer.setProperty(propertyName, newVal);
                }
            } catch(ConstraintViolationException cve) {
                throw new DataIntegrityViolationException("Unique constraint violated "+property.getOwner().getName()+"."+property.getName()+" new value "+newVal,cve);
            }
            return newVal;
View Full Code Here

        public final Object getValue(final Object entity, MappingPolicy mappingPolicy) {
            return doReturn(doGetValue(entity));
        }

        protected Object doGetValue(final Object entity) {
            PropertyContainer element = template.getPersistentState(entity);
            if (element.hasProperty(propertyName)) {
                Object value = element.getProperty(propertyName);
                if (value == null || fieldType.isInstance(value)) return value;
                return convertSimplePropertyValue(value);
            }
            return getDefaultValue(fieldType);
        }
View Full Code Here

        this.mappingPolicy = persistentEntity.getMappingPolicy();
    }

    @Override
    public void createAndAssignState() {
        final PropertyContainer state = template.getPersistentState(entity);
        if (state !=null) return;
        try {
            final Object id = getIdFromEntity();
            if (id instanceof Number) {
                final Relationship relationship = template.getRelationship(((Number) id).longValue());
View Full Code Here

        }

        @Override
        public Object setValue(final Object entity, final Object newVal, MappingPolicy mappingPolicy) {
            if (entity==null) return entity;
            final PropertyContainer state = template.getPersistentState(entity);
            if (state instanceof Node) {
                Node node = (Node) state;
                Set<String> oldLabels = getLabels(node);
                for (String newLabel : (Iterable<String>) newVal) {
                    if (oldLabels.remove(newLabel)) continue;
View Full Code Here

            throw new MappingException("Error setting labels on "+entity);
        }

        @Override
        public Object getValue(final Object entity, MappingPolicy mappingPolicy) {
            final PropertyContainer state = template.getPersistentState(entity);
            if (state instanceof Node) {
                return doReturn(getLabels((Node) state));
            }
            throw new MappingException("Error retrieving labels from "+entity);
        }
View Full Code Here

TOP

Related Classes of org.neo4j.graphdb.PropertyContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.