Package com.impetus.kundera.graph

Examples of com.impetus.kundera.graph.Node


        object.setPersonId(ROW_KEY);
        object.setPersonName(originalName);
        object.setDay(Day.TUESDAY);
        object.setMonth(Month.JAN);

        Node node = new Node(nodeId, PersonCouchDB.class, new TransientState(), null, ROW_KEY, null);
        node.setData(object);
        client.persist(node);

        PersonCouchDB result = (PersonCouchDB) client.find(PersonCouchDB.class, ROW_KEY);

        Assert.assertNotNull(result);
View Full Code Here


        }

        // Create an object graph of the entity object.
        ObjectGraph graph = new GraphGenerator().generateGraph(e, this);
        // Call persist on each node in object graph.
        Node node = graph.getHeadNode();
        try
        {
            // Get write lock before writing object required for transaction.
            lock.writeLock().lock();

            node.setPersistenceDelegator(this);
            node.persist();

            // build flush stack.
            flushManager.buildFlushStack(node, com.impetus.kundera.persistence.context.EventLog.EventType.INSERT);

            // Flushing data.
View Full Code Here

        this.persistenceCache = pc;
    }

    public Node getNodeFromCache(String nodeId, PersistenceDelegator pd)
    {
        Node node = nodeMappings.get(nodeId);
        // if not present in first level cache, check from second level cache.
        return node != null ? node : lookupL2Cache(nodeId, pd);
    }
View Full Code Here

    public void processNodeMapping(Node node)
    {
        if (nodeMappings.containsKey(node.getNodeId()))
        {
            Node existingNode = nodeMappings.get(node.getNodeId());

            if (existingNode.getParents() != null)
            {
                if (node.getParents() == null)
                {
                    node.setParents(new HashMap<NodeLink, Node>());
                }
                node.getParents().putAll(existingNode.getParents());
            }

            if (existingNode.getChildren() != null)
            {
                if (node.getChildren() == null)
                {
                    node.setChildren(new HashMap<NodeLink, Node>());
                }
                node.getChildren().putAll(existingNode.getChildren());
            }

            nodeMappings.put(node.getNodeId(), node);
            logCacheEvent("ADDED TO ", node.getNodeId());
        }
View Full Code Here

    public void addGraphToCache(ObjectGraph graph, PersistenceCache persistenceCache)
    {
        // Add each node in the graph to cache
        for (String key : graph.getNodeMapping().keySet())
        {
            Node thisNode = graph.getNodeMapping().get(key);
            addNodeToCache(thisNode);

            // Remove all those head nodes in persistence cache, that are there
            // in Graph as a non-head node
            if (!thisNode.isHeadNode() && persistenceCache.getMainCache().getHeadNodes().contains(thisNode))
            {
                persistenceCache.getMainCache().getHeadNodes().remove(thisNode);
            }
        }
        // Add head Node to list of head nodes
View Full Code Here

        return Collections.synchronizedSet(headNodes);
    }

    private Node lookupL2Cache(String nodeId, PersistenceDelegator pd)
    {
        Node node = null;
        if (l2Cache != null)
        {
            Object entity = l2Cache.get(nodeId);
            if (entity != null)
            {
                node = new Node(nodeId, entity.getClass(), new ManagedState(), this.persistenceCache,
                        nodeId.substring(nodeId.indexOf("$") + 1), pd);
                node.setData(entity);
            }
        }

        return node;
    }
View Full Code Here

                if (cascadeTypes.contains(cascadePermission.get(eventType).get(0))
                        || cascadeTypes.contains(cascadePermission.get(eventType).get(1)))
                {
                    Relation.ForeignKey multiplicity = nodeLink.getMultiplicity();

                    Node childNode = children.get(nodeLink);

                    switch (multiplicity)
                    {
                    case ONE_TO_ONE:
                        oneToOneChildren.put(nodeLink, childNode);
                        break;
                    case ONE_TO_MANY:
                        oneToManyChildren.put(nodeLink, childNode);
                        break;
                    case MANY_TO_ONE:
                        manyToOneChildren.put(nodeLink, childNode);
                        break;
                    case MANY_TO_MANY:
                        manyToManyChildren.put(nodeLink, childNode);
                        break;
                    }
                }
            }

            // Process One-To-Many children
            for (NodeLink nodeLink : oneToManyChildren.keySet())
            {
                // Process child node Graph recursively first
                Node childNode = children.get(nodeLink);

                if (childNode != null && !childNode.isTraversed())
                {
                    addNodesToFlushStack(childNode, eventType);
                }
            }

            // Process Many-To-Many children
            for (NodeLink nodeLink : manyToManyChildren.keySet())
            {
                if (!node.isTraversed() && !(Boolean) nodeLink.getLinkProperty(LinkProperty.IS_RELATED_VIA_JOIN_TABLE))
                {
                    // Push this node to stack
                    node.setTraversed(true);
                    stackQueue.push(node);
                    logEvent(node, eventType);
                }

                Node childNode = children.get(nodeLink);

                if (childNode != null)
                {
                    // Extract information required to be persisted into
                    // Join
                    // Table
                    if (node.isDirty() && !node.isTraversed())
                    {
                        // M-2-M relation fields that are Set or List are joined
                        // by join table.
                        // M-2-M relation fields that are Map aren't joined by
                        // Join table

                        JoinTableMetadata jtmd = (JoinTableMetadata) nodeLink
                                .getLinkProperty(LinkProperty.JOIN_TABLE_METADATA);
                        if (jtmd != null)
                        {
                            String joinColumnName = (String) jtmd.getJoinColumns().toArray()[0];
                            String inverseJoinColumnName = (String) jtmd.getInverseJoinColumns().toArray()[0];
                            Object entityId = node.getEntityId();
                            Object childId = childNode.getEntityId();
                            Set<Object> childValues = new HashSet<Object>();
                            childValues.add(childId);

                            OPERATION operation = null;
                            if (node.getCurrentNodeState().getClass().equals(ManagedState.class))
                            {
                                operation = OPERATION.INSERT;
                            }
                            else if (node.getCurrentNodeState().getClass().equals(RemovedState.class))
                            {
                                operation = OPERATION.DELETE;
                            }

                            addJoinTableData(operation, jtmd.getJoinTableSchema(), jtmd.getJoinTableName(),
                                    joinColumnName, inverseJoinColumnName, node.getDataClass(), entityId, childValues);
                        }
                    }

                    // Process child node Graph recursively first
                    if (!childNode.isTraversed())
                    {
                        addNodesToFlushStack(childNode, eventType);
                    }
                }
            }
            // Process One-To-One children
            for (NodeLink nodeLink : oneToOneChildren.keySet())
            {
                if (!node.isTraversed())
                {
                    // Push this node to stack
                    node.setTraversed(true);
                    stackQueue.push(node);
                    logEvent(node, eventType);
                }

                // Process child node Graph recursively
                Node childNode = children.get(nodeLink);

                addNodesToFlushStack(childNode, eventType);
            }

            // Process Many-To-One children
            for (NodeLink nodeLink : manyToOneChildren.keySet())
            {
                if (!node.isTraversed())
                {
                    // Push this node to stack
                    node.setTraversed(true);
                    stackQueue.push(node);
                    logEvent(node, eventType);
                }

                // Child node of this node
                Node childNode = children.get(nodeLink);

                // Process all parents of child node with Many-To-One
                // relationship first
                Map<NodeLink, Node> parents = childNode.getParents();
                for (NodeLink parentLink : parents.keySet())
                {
                    List<CascadeType> cascadeTypes = (List<CascadeType>) nodeLink.getLinkProperty(LinkProperty.CASCADE);

                    if (cascadeTypes.contains(cascadePermission.get(eventType).get(0))
                            || cascadeTypes.contains(cascadePermission.get(eventType).get(1)))
                    {
                        Relation.ForeignKey multiplicity = parentLink.getMultiplicity();

                        Node parentNode = parents.get(parentLink);

//                        performOperation(parentNode, eventType);

                        if (multiplicity.equals(Relation.ForeignKey.MANY_TO_ONE))
                        {
                            if (!parentNode.isTraversed() && parentNode.isDirty())
                            {
                                addNodesToFlushStack(parentNode, eventType);
                            }
                        }
                    }
View Full Code Here

            while (iter.hasNext())
            {
                try
                {
                    EventLog event = iter.next();
                    Node node = event.getNode();
                    if (node.isProcessed())
                    {
                        // One time set as required for rollback.
                        Node original = node.clone();
                        node.setOriginalNode(original);
                    }

                    // mark it null for garbage collection.
                    event = null;
View Full Code Here

            while (iter.hasNext())
            {
                try
                {
                    EventLog event = iter.next();
                    Node node = event.getNode();
                    Class clazz = node.getDataClass();
                    EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(delegator.getKunderaMetadata(), clazz);
                    Client client = delegator.getClient(metadata);

                    // do manual rollback, if data is processed, and running
                    // without transaction or with kundera's default transaction
                    // support!
                    if (node.isProcessed()
                            && (!delegator.isTransactionInProgress() || MetadataUtils
                                    .defaultTransactionSupported(metadata.getPersistenceUnit(), delegator.getKunderaMetadata())))
                    {
                        if (node.getOriginalNode() == null)
                        {
                            Object entityId = node.getEntityId();
                            client.delete(node.getData(), entityId);
                        }
                        else
                        {
                            client.persist(node.getOriginalNode());
                        }
                    }
                    // mark it null for garbage collection.
                    event = null;
                }
View Full Code Here

        String nodeId = ObjectGraphUtils.getNodeId(primaryKey, entityClass);

        // TODO all the scrap should go from here.
        MainCache mainCache = (MainCache) getPersistenceCache().getMainCache();
        Node node = mainCache.getNodeFromCache(nodeId, this);

        // if node is not in persistence cache or is dirty, fetch from database
        if (node == null || node.isDirty())
        {
            node = new Node(nodeId, entityClass, new ManagedState(), getPersistenceCache(), primaryKey, this);
            node.setClient(getClient(entityMetadata));
            // TODO ManagedState.java require serious attention.
            node.setPersistenceDelegator(this);

            try
            {
                lock.readLock().lock();
                node.find();
            }
            finally
            {
                lock.readLock().unlock();
            }
        }
        else
        {
            node.setPersistenceDelegator(this);
        }
        Object nodeData = node.getData();
        if (nodeData == null)
        {
            return null;
        }
        else
View Full Code Here

TOP

Related Classes of com.impetus.kundera.graph.Node

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.