All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.graphaware.tx.event.improved.data.lazy.LazyNodeTransactionData Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2013-2020 GraphAware
 *
 * This file is part of the GraphAware Framework.
 *
 * GraphAware Framework is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software Foundation, either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details. You should have received a copy of
 * the GNU General Public License along with this program.  If not, see
 * .
 */

package com.graphaware.tx.event.improved.data.lazy;

import com.graphaware.tx.event.improved.data.NodeTransactionData;
import com.graphaware.tx.event.improved.data.TransactionDataContainer;
import com.graphaware.tx.event.improved.entity.snapshot.NodeSnapshot;
import org.neo4j.graphdb.Label;
import org.neo4j.graphdb.Node;
import org.neo4j.graphdb.event.LabelEntry;
import org.neo4j.graphdb.event.PropertyEntry;
import org.neo4j.graphdb.event.TransactionData;
import org.neo4j.logging.Log;
import com.graphaware.common.log.LoggerFactory;

import java.util.*;

/**
 * {@link LazyEntityTransactionData} for {@link org.neo4j.graphdb.Node}s.
 */
public class LazyNodeTransactionData extends LazyEntityTransactionData implements NodeTransactionData {
    private static final Log LOG = LoggerFactory.getLogger(LazyNodeTransactionData.class);

    private final TransactionData transactionData;
    private final TransactionDataContainer transactionDataContainer;

    private Map> assignedLabels = null;
    private Map> removedLabels = null;
    private Map> deletedNodeLabels = null;

    /**
     * Construct node transaction data from Neo4j {@link org.neo4j.graphdb.event.TransactionData}.
     *
     * @param transactionData          provided by Neo4j.
     * @param transactionDataContainer containing {@link com.graphaware.tx.event.improved.data.EntityTransactionData}..
     */
    public LazyNodeTransactionData(TransactionData transactionData, TransactionDataContainer transactionDataContainer) {
        this.transactionData = transactionData;
        this.transactionDataContainer = transactionDataContainer;
    }

    @Override
    protected Node oldSnapshot(Node original) {
        return new NodeSnapshot(original, transactionDataContainer);
    }

    @Override
    protected Node newSnapshot(Node original) {
        return original;
    }

    @Override
    protected Iterable created() {
        return transactionData.createdNodes();
    }

    @Override
    protected Iterable deleted() {
        return transactionData.deletedNodes();
    }

    @Override
    protected Iterable> assignedProperties() {
        return transactionData.assignedNodeProperties();
    }

    @Override
    protected Iterable> removedProperties() {
        return transactionData.removedNodeProperties();
    }

    @Override
    public boolean hasLabelBeenAssigned(Node node, Label label) {
        initializeChanged();

        if (!hasBeenChanged(node)) {
//            LOG.warn(node + " has not been changed but the caller thinks it should have assigned labels.");
            return false;
        }

        if (!assignedLabels.containsKey(node.getId())) {
            return false;
        }

        return assignedLabels.get(node.getId()).contains(label);
    }

    @Override
    public Set




© 2015 - 2025 Weber Informatics LLC | Privacy Policy