Package org.apache.marmotta.kiwi.model.caching

Examples of org.apache.marmotta.kiwi.model.caching.IntArray


     * @param inferred if true, inferred triples are included in the result; if false not
     * @return the result set if the query is found in the cache, returns null if the query is not found
     */
    @SuppressWarnings("unchecked")
  public List<KiWiTriple> listTriples(KiWiResource subject, KiWiUriResource property, KiWiNode object, KiWiUriResource context, boolean inferred) {
        IntArray key = createCacheKey(subject,property,object,context,inferred);
        if(queryCache.get(key) != null) return (List<KiWiTriple>)queryCache.get(key).getObjectValue();
        else
            return null;
    }
View Full Code Here


     * @param result   the result of the triple query to cache
     */
    public void cacheTriples(KiWiResource subject, KiWiUriResource property, KiWiNode object, KiWiResource context, boolean inferred, List<KiWiTriple> result) {

        // cache the query result
        IntArray key = createCacheKey(subject,property,object,context,inferred);
        queryCache.put(new Element(key,result));

        // cache the nodes of the triples and the triples themselves
        Set<KiWiNode> nodes = new HashSet<KiWiNode>();
        for(KiWiTriple triple : result) {
            Collections.addAll(nodes, new KiWiNode[]{triple.getSubject(), triple.getObject(), triple.getPredicate(), triple.getContext()});
            queryCache.put(new Element(createCacheKey(triple.getSubject(),triple.getPredicate(),triple.getObject(),triple.getContext(),triple.isInferred()), ImmutableList.of(triple)));
        }

        // special optimisation: when only the subject (and optionally context) is given, we also fill the caches for
        // all property values
        if(subject != null && property == null && object == null) {
            HashMap<KiWiUriResource,List<KiWiTriple>> properties = new HashMap<KiWiUriResource, List<KiWiTriple>>();
            for(KiWiTriple triple : result) {
                List<KiWiTriple> values = properties.get(triple.getPredicate());
                if(values == null) {
                    values = new LinkedList<KiWiTriple>();
                    properties.put(triple.getPredicate(),values);
                }
                values.add(triple);
            }
            for(Map.Entry<KiWiUriResource,List<KiWiTriple>> entry : properties.entrySet()) {
                IntArray key2 = createCacheKey(subject,entry.getKey(),null,context,inferred);
                queryCache.put(new Element(key2,entry.getValue()));
            }
        }


View Full Code Here

        bb.put(p);
        bb.put(o);
        bb.put(c);
        bb.put( (byte) (inferred ? 1 : 0) );

        return new IntArray(bb.array());

    }
View Full Code Here

     * @param object    The statement's object.
     * @param context   The statement's context.
     * @return The created statement.
     */
    public Statement createStatement(Resource subject, URI predicate, Value object, Resource context, KiWiConnection connection) {
        IntArray cacheKey = IntArray.createSPOCKey(subject, predicate, object, context);
        KiWiTriple result = (KiWiTriple)tripleRegistry.get(cacheKey);
        try {
            if(result == null || result.isDeleted()) {
                KiWiResource ksubject   = convert(subject);
                KiWiUriResource kpredicate = convert(predicate);
View Full Code Here

    /**
     * Remove a statement from the triple registry. Called when the statement is deleted and the transaction commits.
     * @param triple
     */
    protected void removeStatement(KiWiTriple triple) {
        IntArray cacheKey = IntArray.createSPOCKey(triple.getSubject(), triple.getPredicate(), triple.getObject(), triple.getContext());
        tripleRegistry.remove(cacheKey);
        triple.setDeleted(true);
    }
View Full Code Here

     * @param object    The statement's object.
     * @param context   The statement's context.
     * @return The created statement.
     */
    public Statement createStatement(Resource subject, URI predicate, Value object, Resource context, KiWiConnection connection) {
        IntArray cacheKey = IntArray.createSPOCKey(subject,predicate,object,context);
        Statement result = tripleRegistry.get(cacheKey);
        try {
            if(result == null || ((KiWiTriple)result).isDeleted()) {
                KiWiResource ksubject   = convert(subject);
                KiWiUriResource kpredicate = convert(predicate);
View Full Code Here

TOP

Related Classes of org.apache.marmotta.kiwi.model.caching.IntArray

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.