Package org.springframework.data.neo4j.mapping

Examples of org.springframework.data.neo4j.mapping.Neo4JPersistentProperty


    @Override
    public Result<T> findAllBySchemaPropertyValue(String property, Object value) {
        final String SCHEMA_PROP_MATCH_CLAUSE = "MATCH (entity:`%s`) where entity.`%s` = {propValue} return entity";

        Neo4jPersistentEntity persistentEntity = template.getEntityType(clazz).getEntity();
        Neo4jPersistentProperty persistentProperty = (Neo4jPersistentProperty)persistentEntity.getPersistentProperty(property);
        if (persistentProperty.getIndexInfo() == null || !persistentProperty.getIndexInfo().isLabelBased() ) {
            throw new IllegalArgumentException(format("property %s.%s is not schema indexed",persistentEntity.getName(),property));
        }

        Map<String,Object> params = new HashMap<String,Object>();
        params.put("propValue", value);
        String cypherQuery = format(SCHEMA_PROP_MATCH_CLAUSE,
                persistentProperty.getIndexInfo().getIndexName(), property );
        return template.query(cypherQuery,params).to(clazz);
    }
View Full Code Here


            return fromGraph;
        }
    }
    @Override
    public Object setValue(final Field field, final Object newVal, MappingPolicy mappingPolicy) {
        Neo4jPersistentProperty property = property(field);
        if (property != null) {
            return setValue(property, newVal, mappingPolicy);
        }
        return delegate.setValue(property, newVal, mappingPolicy);
    }
View Full Code Here

        if (isDirty()) {
            final Map<Neo4jPersistentProperty, ExistingValue> dirtyCopy = new HashMap<Neo4jPersistentProperty, ExistingValue>(dirty);
            try {
                for (final Map.Entry<Neo4jPersistentProperty, ExistingValue> entry : dirtyCopy.entrySet()) {
                    final Neo4jPersistentProperty property = entry.getKey();
                    Object valueFromEntity = getValueFromEntity(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY);
                    cascadePersist(valueFromEntity);
                    if (log.isDebugEnabled()) log.debug("Flushing dirty Entity new node " + entity + " field " + property+ " with value "+ valueFromEntity);
                    final MappingPolicy mappingPolicy = property.getMappingPolicy();
                    checkConcurrentModification(entity, entry, property, mappingPolicy);
                    delegate.setValue(property, valueFromEntity, mappingPolicy);
                    dirty.remove(property);
                    if (valueFromEntity instanceof DirtyValue) {
                        ((DirtyValue)valueFromEntity).setDirty(false);
                    }
                }
            } finally {
                if (!dirty.isEmpty()) { // restore all dirty data
                    dirty.putAll(dirtyCopy);
                    for (Map.Entry<Neo4jPersistentProperty, ExistingValue> entry : dirtyCopy.entrySet()) {
                        final Neo4jPersistentProperty property = entry.getKey();
                        Object valueFromEntity = getValueFromEntity(property, MappingPolicy.MAP_FIELD_DIRECT_POLICY);
                        if (valueFromEntity instanceof DirtyValue) {
                            ((DirtyValue)valueFromEntity).setDirty(true);
                        }
                    }
View Full Code Here

        fullTextIndexedPartInfo = Mockito.mock(PartInfo.class);
        when(fullTextIndexedPartInfo.isIndexed()).thenReturn(true);
        when(fullTextIndexedPartInfo.isFullText()).thenReturn(true);

        Neo4jPersistentProperty leafProperty1 = Mockito.mock(Neo4jPersistentProperty.class);
        idBasedPartInfo = Mockito.mock(PartInfo.class);
        when(idBasedPartInfo.isIndexed()).thenReturn(false);
        when(idBasedPartInfo.getLeafProperty()).thenReturn(leafProperty1);
        when(leafProperty1.isRelationship()).thenReturn(false);
        when(leafProperty1.isIdProperty()).thenReturn(true);

        Neo4jPersistentProperty leafProperty2 = Mockito.mock(Neo4jPersistentProperty.class);
        relBasedPartInfo = Mockito.mock(PartInfo.class);
        when(relBasedPartInfo.isIndexed()).thenReturn(false);
        when(relBasedPartInfo.getLeafProperty()).thenReturn(leafProperty2);
        when(leafProperty2.isRelationship()).thenReturn(true);
        when(leafProperty2.isIdProperty()).thenReturn(false);


    }
View Full Code Here

        if (variables.containsKey(path)) {
            return variables.get(path);
        }

        Neo4jPersistentProperty baseProperty = path.getBaseProperty();
        List<String> parts = new ArrayList<String>();
        parts.add(getVariableFor(baseProperty.getOwner()));

        final Neo4jPersistentProperty leaf = path.getLeafProperty();
        for (Neo4jPersistentProperty property : path) {
            if (leaf.isRelationship() || !leaf.equals(property)) {
                parts.add(property.getName());
            }
        }

        String variable = StringUtils.collectionToDelimitedString(parts, "_");
View Full Code Here

    private IndexInfo getIndexInfo() {
        return getLeafProperty().getIndexInfo();
    }

    String getNeo4jPropertyName() {
        Neo4jPersistentProperty leafProperty = getLeafProperty();
        return leafProperty.getNeo4jPropertyName();
    }
View Full Code Here

        return matchPattern(variableContext, path);
    }

    private String matchPattern(VariableContext variableContext, PersistentPropertyPath<Neo4jPersistentProperty> relPath) {
        if (!relPath.getLeafProperty().isRelationship()) {
            final Neo4jPersistentProperty property = relPath.getBaseProperty();
            return formatMatch(variableContext.getVariableFor(property.getOwner()));
        }
        if (relPath.getLength() == 1) {
            final Neo4jPersistentProperty property = relPath.getBaseProperty();
            return formatMatch(variableContext.getVariableFor(property.getOwner()),
                    QueryTemplates.getArrow(property.getRelationshipInfo()),
                    variableContext.getVariableFor(relPath));
        }
        final RelationshipInfo info = relPath.getLeafProperty().getRelationshipInfo();
        return formatMatch2(matchPattern(variableContext, relPath.getParentPath()),
                QueryTemplates.getArrow(info),
View Full Code Here

        final PartInfo partInfo = new PartInfo(path, variable, part, index);
        MatchClause matchClause = new MatchClause(path);
        // index("a:foo AND b:bar")
        // a=index1(a="foo"), b=index2(b="bar") where a=b - not good b/c of cross product
        // index1(a=foo) where a.foo=bar
        Neo4jPersistentProperty leafProperty = partInfo.getLeafProperty();
        boolean isIdProperty = leafProperty.isIdProperty();
        boolean addedMatchClause = false;
        if (partInfo.isPrimitiveProperty() && !isIdProperty) {
            if (!addedStartClause(partInfo)) {
                whereClauses.add(new WhereClause(partInfo,template));
            }
        } else if (leafProperty.isRelationship() || isIdProperty) {
            if (useLabels) {
                whereClauses.add(new IdPropertyWhereClause(new PartInfo(path, variable, part, index), template));
                whereClauses.add(new LabelBasedTypeRestrictingWhereClause(new PartInfo(path, variableContext.getVariableFor(entity), part, -1), entity, template));
                matchClauses.add(matchClause);
                addedMatchClause = true;
View Full Code Here

        return template.createRelationshipBetween(startNode, endNode,type,null);
    }

    private String getRelationshipTypeFromEntity(Neo4jPersistentEntity<?> persistentEntity) {
        final RelationshipProperties relationshipProperties = persistentEntity.getRelationshipProperties();
        final Neo4jPersistentProperty typeProperty = relationshipProperties.getTypeProperty();
        final Object value = typeProperty!=null ? typeProperty.getValue(entity, mappingPolicy) : null;
        if (value==null) {
            return relationshipProperties.getRelationshipType();
        }
        if (value instanceof RelationshipType) {
            return ((RelationshipType)value).name();
View Full Code Here

                }
            });
            type.doWithAssociations(new AssociationHandler<Neo4jPersistentProperty>() {
                @Override
                public void doWithAssociation(Association<Neo4jPersistentProperty> association) {
                    final Neo4jPersistentProperty property = association.getInverse();
                    final FieldAccessorFactory factory = factoryForField(property);
                    final List<FieldAccessorListenerFactory> listenerFactories = getFieldAccessListenerFactories(property);
                    newFieldAccessorFactories.add(property, factory, listenerFactories);
                }
            });
View Full Code Here

TOP

Related Classes of org.springframework.data.neo4j.mapping.Neo4JPersistentProperty

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.