Package org.openrdf.sail.memory.model

Examples of org.openrdf.sail.memory.model.MemStatement


  {
    Cursor<MemStatement> stIter = store.createStatementIterator(null, null, null, false,
        store.getCurrentSnapshot(), ReadMode.COMMITTED, vf);

    try {
      MemStatement st;
      while ((st = stIter.next()) != null) {
        Resource context = st.getContext();

        if (st.isExplicit()) {
          if (context == null) {
            dataOut.writeByte(EXPL_TRIPLE_MARKER);
          }
          else {
            dataOut.writeByte(EXPL_QUAD_MARKER);
          }
        }
        else {
          if (context == null) {
            dataOut.writeByte(INF_TRIPLE_MARKER);
          }
          else {
            dataOut.writeByte(INF_QUAD_MARKER);
          }
        }

        writeValue(st.getSubject(), dataOut);
        writeValue(st.getPredicate(), dataOut);
        writeValue(st.getObject(), dataOut);
        if (context != null) {
          writeValue(context, dataOut);
        }
      }
    }
View Full Code Here


    MemResource memContext = null;
    if (hasContext) {
      memContext = (MemResource)readValue(dataIn);
    }

    MemStatement st = new MemStatement(memSubj, memPred, memObj, memContext, isExplicit,
        store.getCurrentSnapshot());
    store.getStatements().add(st);
    st.addToComponentLists();
  }
View Full Code Here

    throws StoreException
  {
    boolean statementsRemoved = false;

    try {
      MemStatement st;
      while ((st = stIter.next()) != null) {

        if (store.removeStatement(st, explicit)) {
          statementsRemoved = true;
          notifyStatementRemoved(st);
View Full Code Here

      // statement is already present. Check this.
      Cursor<MemStatement> stIter = createStatementIterator(memSubj, memPred, memObj, false,
          currentSnapshot + 1, ReadMode.RAW, vf, memContext);

      try {
        MemStatement st = stIter.next();
        if (st != null) {
          // statement is already present, update its transaction
          // status if appropriate

          txnStatements.put(st, st);

          TxnStatus txnStatus = st.getTxnStatus();

          if (txnStatus == TxnStatus.NEUTRAL && !st.isExplicit() && explicit) {
            // Implicit statement is now added explicitly
            st.setTxnStatus(TxnStatus.EXPLICIT);
          }
          else if (txnStatus == TxnStatus.NEW && !st.isExplicit() && explicit) {
            // Statement was first added implicitly and now
            // explicitly
            st.setExplicit(true);
          }
          else if (txnStatus == TxnStatus.DEPRECATED) {
            if (st.isExplicit() == explicit) {
              // Statement was removed but is now re-added
              st.setTxnStatus(TxnStatus.NEUTRAL);
            }
            else if (explicit) {
              // Implicit statement was removed but is now added
              // explicitly
              st.setTxnStatus(TxnStatus.EXPLICIT);
            }
            else {
              // Explicit statement was removed but can still be
              // inferred
              st.setTxnStatus(TxnStatus.INFERRED);
            }

            return st;
          }
          else if (txnStatus == TxnStatus.INFERRED && st.isExplicit() && explicit) {
            // Explicit statement was removed but is now re-added
            st.setTxnStatus(TxnStatus.NEUTRAL);
          }
          else if (txnStatus == TxnStatus.ZOMBIE) {
            // Restore zombie statement
            st.setTxnStatus(TxnStatus.NEW);
            st.setExplicit(explicit);

            return st;
          }

          return null;
        }
      }
      finally {
        stIter.close();
      }
    }

    // completely new statement
    MemStatement st = new MemStatement(memSubj, memPred, memObj, memContext, explicit, currentSnapshot + 1,
        TxnStatus.NEW);
    statements.add(st);
    st.addToComponentLists();

    txnStatements.put(st, st);
   
    assert hasStatement(memSubj, memPred, memObj, explicit, currentSnapshot + 1, ReadMode.TRANSACTION, vf, memContext);
View Full Code Here

        // Deprecate the existing statement...
        st.setTillSnapshot(txnSnapshot);
        statementsDeprecated = true;

        // ...and add a clone with modified explicit/implicit flag
        MemStatement explSt = new MemStatement(st.getSubject(), st.getPredicate(), st.getObject(),
            st.getContext(), txnStatus == TxnStatus.EXPLICIT, txnSnapshot);
        statements.add(explSt);
        explSt.addToComponentLists();
      }

      st.setTxnStatus(TxnStatus.NEUTRAL);
    }
View Full Code Here

    HashSet<MemValue> processedContexts = new HashSet<MemValue>();

    Lock stLock = statementListLockManager.getWriteLock();
    try {
      for (int i = statements.size() - 1; i >= 0; i--) {
        MemStatement st = statements.get(i);

        if (st.getTillSnapshot() <= currentSnapshot) {
          MemResource subj = st.getSubject();
          if (processedSubjects.add(subj)) {
            subj.cleanSnapshotsFromSubjectStatements(currentSnapshot);
          }

          MemURI pred = st.getPredicate();
          if (processedPredicates.add(pred)) {
            pred.cleanSnapshotsFromPredicateStatements(currentSnapshot);
          }

          MemValue obj = st.getObject();
          if (processedObjects.add(obj)) {
            obj.cleanSnapshotsFromObjectStatements(currentSnapshot);
          }

          MemResource context = st.getContext();
          if (context != null && processedContexts.add(context)) {
            context.cleanSnapshotsFromContextStatements(currentSnapshot);
          }

          // stale statement
          statements.remove(i);
        }
        else {
          // Reset snapshot
          st.setSinceSnapshot(1);
        }
      }

      currentSnapshot = 1;
    }
View Full Code Here

      try {
        if (stIter.hasNext()) {
          // statement is already present, update its transaction
          // status if appropriate
          MemStatement st = stIter.next();

          txnStatements.put(st, st);

          TxnStatus txnStatus = st.getTxnStatus();

          if (txnStatus == TxnStatus.NEUTRAL && !st.isExplicit() && explicit) {
            // Implicit statement is now added explicitly
            st.setTxnStatus(TxnStatus.EXPLICIT);
          }
          else if (txnStatus == TxnStatus.NEW && !st.isExplicit() && explicit) {
            // Statement was first added implicitly and now
            // explicitly
            st.setExplicit(true);
          }
          else if (txnStatus == TxnStatus.DEPRECATED) {
            if (st.isExplicit() == explicit) {
              // Statement was removed but is now re-added
              st.setTxnStatus(TxnStatus.NEUTRAL);
            }
            else if (explicit) {
              // Implicit statement was removed but is now added
              // explicitly
              st.setTxnStatus(TxnStatus.EXPLICIT);
            }
            else {
              // Explicit statement was removed but can still be
              // inferred
              st.setTxnStatus(TxnStatus.INFERRED);
            }

            return st;
          }
          else if (txnStatus == TxnStatus.INFERRED && st.isExplicit() && explicit) {
            // Explicit statement was removed but is now re-added
            st.setTxnStatus(TxnStatus.NEUTRAL);
          }
          else if (txnStatus == TxnStatus.ZOMBIE) {
            // Restore zombie statement
            st.setTxnStatus(TxnStatus.NEW);
            st.setExplicit(explicit);

            return st;
          }

          return null;
        }
      }
      finally {
        stIter.close();
      }
    }

    // completely new statement
    MemStatement st = new MemStatement(memSubj, memPred, memObj, memContext, explicit, currentSnapshot + 1,
        TxnStatus.NEW);
    statements.add(st);
    st.addToComponentLists();

    txnStatements.put(st, st);

    return st;
  }
View Full Code Here

        // Deprecate the existing statement...
        st.setTillSnapshot(txnSnapshot);
        statementsDeprecated = true;

        // ...and add a clone with modified explicit/implicit flag
        MemStatement explSt = new MemStatement(st.getSubject(), st.getPredicate(), st.getObject(),
            st.getContext(), txnStatus == TxnStatus.EXPLICIT, txnSnapshot);
        statements.add(explSt);
        explSt.addToComponentLists();
      }

      st.setTxnStatus(TxnStatus.NEUTRAL);
    }
View Full Code Here

    }

    Lock stLock = statementListLockManager.getWriteLock();
    try {
      for (int i = statements.size() - 1; i >= 0; i--) {
        MemStatement st = statements.get(i);

        if (st.getTillSnapshot() <= currentSnapshot) {
          // stale statement
          st.removeFromComponentLists();
          statements.remove(i);
        }
        else {
          // Reset snapshot
          st.setSinceSnapshot(1);
        }
      }

      currentSnapshot = 1;
    }
View Full Code Here

    CloseableIteration<MemStatement, SailException> stIter = store.createStatementIterator(
        SailException.class, null, null, null, false, store.getCurrentSnapshot(), ReadMode.COMMITTED);

    try {
      while (stIter.hasNext()) {
        MemStatement st = stIter.next();
        Resource context = st.getContext();

        if (st.isExplicit()) {
          if (context == null) {
            dataOut.writeByte(EXPL_TRIPLE_MARKER);
          }
          else {
            dataOut.writeByte(EXPL_QUAD_MARKER);
          }
        }
        else {
          if (context == null) {
            dataOut.writeByte(INF_TRIPLE_MARKER);
          }
          else {
            dataOut.writeByte(INF_QUAD_MARKER);
          }
        }

        writeValue(st.getSubject(), dataOut);
        writeValue(st.getPredicate(), dataOut);
        writeValue(st.getObject(), dataOut);
        if (context != null) {
          writeValue(context, dataOut);
        }
      }
    }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.memory.model.MemStatement

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.