|
From: <mrp...@us...> - 2010-07-26 21:59:05
|
Revision: 3302
http://bigdata.svn.sourceforge.net/bigdata/?rev=3302&view=rev
Author: mrpersonick
Date: 2010-07-26 21:58:56 +0000 (Mon, 26 Jul 2010)
Log Message:
-----------
added user flag to SPO (metadata graphs) for CSI
Modified Paths:
--------------
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/StatementEnum.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/ISPO.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPO.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOIndexWriteProc.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOTupleSerializer.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java
branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPO.java
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BNodeContextFactory.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -138,9 +138,14 @@
public BigdataStatement createStatement(Resource s, URI p, Value o,
Resource c, StatementEnum type) {
- return valueFactory.createStatement(s, p, o, c, type);
+ return valueFactory.createStatement(s, p, o, c, type, false);
}
-
+
+ public BigdataStatement createStatement(Resource s, URI p, Value o,
+ Resource c, StatementEnum type, boolean userFlag) {
+ return valueFactory.createStatement(s, p, o, c, type, userFlag);
+ }
+
public BigdataURI createURI(String namespace, String localName) {
return valueFactory.createURI(namespace, localName);
}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataStatementImpl.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -64,6 +64,7 @@
protected final BigdataValue o;
protected final BigdataResource c;
private StatementEnum type;
+ private boolean userFlag;
private transient boolean override = false;
private transient boolean modified = false;
@@ -72,7 +73,8 @@
*/
public BigdataStatementImpl(final BigdataResource subject,
final BigdataURI predicate, final BigdataValue object,
- final BigdataResource context, final StatementEnum type) {
+ final BigdataResource context, final StatementEnum type,
+ final boolean userFlag) {
if (subject == null)
throw new IllegalArgumentException();
@@ -97,6 +99,8 @@
this.type = type;
+ this.userFlag=userFlag;
+
}
final public BigdataResource getSubject() {
@@ -152,6 +156,12 @@
this.type = type;
}
+
+ final public void setUserFlag(boolean userFlag) {
+
+ this.userFlag = userFlag;
+
+ }
final public boolean isAxiom() {
@@ -170,6 +180,12 @@
return StatementEnum.Explicit == type;
}
+
+ final public boolean getUserFlag() {
+
+ return userFlag;
+
+ }
public boolean equals(final Object o) {
@@ -320,8 +336,8 @@
public byte[] serializeValue(final ByteArrayBuffer buf) {
- return SPO.serializeValue(buf, override, type, c != null ? c
- .getIV() : null);
+ return SPO.serializeValue(buf, override, userFlag, type,
+ c != null ? c.getIV() : null);
}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactory.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -137,6 +137,29 @@
Resource c, StatementEnum type);
/**
+ * Create a statement (core impl). The s,p,o, and the optional c arguments
+ * will be normalized to this {@link BigdataValueFactory} using
+ * {@link #asValue(Value)}.
+ *
+ * @param s
+ * The subject.
+ * @param p
+ * The predicate.
+ * @param o
+ * The object.
+ * @param c
+ * The context (optional). Note: When non-<code>null</code>
+ * and statement identifiers are enabled, then this will be a
+ * blank node whose term identifier is the statement identifier.
+ * @param type
+ * The statement type (optional).
+ * @param userFlag
+ * The user flag
+ */
+ BigdataStatement createStatement(Resource s, URI p, Value o,
+ Resource c, StatementEnum type, boolean userFlag);
+
+ /**
* Converts a {@link Value} into a {@link BigdataValue}. If the value is
* already a {@link BigdataValue} and it was allocated by <i>this</i>
* {@link BigdataValueFactoryImpl} then it is returned unchanged. Otherwise a
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/BigdataValueFactoryImpl.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -323,13 +323,21 @@
public BigdataStatementImpl createStatement(Resource s, URI p, Value o,
Resource c, StatementEnum type) {
+
+ return createStatement(s, p, o, c, type, false/* userFlag */);
+
+ }
+ public BigdataStatementImpl createStatement(Resource s, URI p, Value o,
+ Resource c, StatementEnum type, final boolean userFlag) {
+
return new BigdataStatementImpl(//
(BigdataResource) asValue(s),//
(BigdataURI) asValue(p),//
(BigdataValue) asValue(o),//
(BigdataResource) asValue(c),// optional
- type // the statement type (optional).
+ type, // the statement type (optional).
+ userFlag // the user flag (optional)
);
}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/StatementEnum.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/StatementEnum.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/model/StatementEnum.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -48,12 +48,8 @@
* A statement that was inferred from the explicit statements by the
* appropriate model theory.
*/
- Inferred((byte) 2),
- /**
- * For debugging.
- */
- Backchained((byte) 4);
-
+ Inferred((byte) 2);
+
private final byte code;
private StatementEnum(final byte code) {
@@ -105,7 +101,7 @@
*/
static public StatementEnum decode(final byte b) {
- switch (b & ~MASK_OVERRIDE) {
+ switch (b & ~MASK_OVERRIDE & ~MASK_USER_FLAG) {
case 0: return Explicit;
@@ -113,8 +109,6 @@
case 2: return Inferred;
- case 4: return Backchained;
-
default:
throw new RuntimeException("Unexpected byte: " + b);
@@ -164,6 +158,23 @@
public static final int MASK_OVERRIDE = 0x1 << 3;
/**
+ * A user bit mask used by applications to flag statements
+ */
+ public static final int MASK_USER_FLAG = 0x1 << 2;
+
+ /**
+ * Return <code>true</code> iff the user bit is set.
+ *
+ * @param b
+ * The byte.
+ */
+ public static boolean isUserFlag(final byte b) {
+
+ return (b & StatementEnum.MASK_USER_FLAG) != 0;
+
+ }
+
+ /**
* Return <code>true</code> iff the override bit is set.
*
* @param b
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/ISPO.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/ISPO.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/ISPO.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -155,6 +155,17 @@
boolean isExplicit();
/**
+ * Return <code>true</code> IFF the {@link SPO} user flag is set
+ */
+ boolean getUserFlag();
+
+ /**
+ * Set {@link SPO} user flag
+ * @param userFlag
+ */
+ void setUserFlag(boolean userFlag);
+
+ /**
* Return <code>true</code> IFF the {@link SPO} is marked as
* {@link StatementEnum#Inferred}.
*/
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPO.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPO.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPO.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -77,8 +77,13 @@
* Statement type (inferred, explicit, or axiom).
*/
private StatementEnum type;
-
+
/**
+ * User flag
+ */
+ private boolean userFlag;
+
+ /**
* Override flag used for downgrading statements during truth maintenance.
*/
private transient boolean override = false;
@@ -405,6 +410,8 @@
final StatementEnum type = StatementEnum.decode(code);
spo.setStatementType(type);
+
+ spo.setUserFlag(StatementEnum.isUserFlag(code));
if (val.length == 1 + 8) {
@@ -431,7 +438,7 @@
public byte[] serializeValue(final ByteArrayBuffer buf) {
- return serializeValue(buf, isOverride(), type, c);
+ return serializeValue(buf, isOverride(),getUserFlag(), type, c);
}
@@ -463,14 +470,17 @@
* {@link SPO}.
*/
static public byte[] serializeValue(final ByteArrayBuffer buf,
- final boolean override, final StatementEnum type, final IV c) {
+ final boolean override, final boolean userFlag,
+ final StatementEnum type, final IV c) {
buf.reset();
// optionally set the override bit on the value.
- final byte b = (byte) (override ? (type.code() | StatementEnum.MASK_OVERRIDE)
- : type.code());
-
+ final byte b = (byte)
+ (type.code()
+ | (override ? StatementEnum.MASK_OVERRIDE : 0x0)
+ | (userFlag ? StatementEnum.MASK_USER_FLAG : 0x0));
+
buf.putByte(b);
if (type == StatementEnum.Explicit
@@ -511,6 +521,26 @@
}
+ /**
+ * Return <code>true</code> IFF the {@link SPO} has the user flag bit set.
+ */
+ public final boolean getUserFlag() {
+
+ return userFlag;
+
+ }
+
+ /**
+ * Set the user flag bit on this SPO.
+ *
+ * @parm userFlag boolean flag
+ */
+ public final void setUserFlag(final boolean userFlag) {
+
+ this.userFlag=userFlag;
+
+ }
+
private int hashCode = 0;
/**
@@ -627,7 +657,6 @@
case Explicit : t = "Explicit "; break;
case Inferred : t = "Inferred "; break;
case Axiom : t = "Axiom "; break;
- case Backchained : t = "Backchained "; break;
default: throw new AssertionError();
}
} else {
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOIndexWriteProc.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOIndexWriteProc.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOIndexWriteProc.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -211,6 +211,8 @@
// figure out if the override bit is set.
final boolean override = StatementEnum.isOverride(val[0]);
+ final boolean userFlag = StatementEnum.isUserFlag(val[0]);
+
/*
* Decode the new (proposed) statement type (override bit is
* masked off).
@@ -242,7 +244,7 @@
* Statement is NOT pre-existing.
*/
- ndx.insert(key, SPO.serializeValue(tmp, false/* override */,
+ ndx.insert(key, SPO.serializeValue(tmp, false/* override */,userFlag,
newType, new_sid/* MAY be NULL */));
if (isPrimaryIndex && DEBUG) {
@@ -278,7 +280,7 @@
// Note: No statement identifier since statement is not
// explicit.
ndx.insert(key, SPO.serializeValue(tmp,
- false/* override */, newType, null/* sid */));
+ false/* override */,userFlag, newType, null/* sid */));
if (isPrimaryIndex && DEBUG) {
log.debug("Downgrading SPO: key="
@@ -323,7 +325,7 @@
}
ndx.insert(key, SPO.serializeValue(tmp,
- false/* override */, maxType, sid));
+ false/* override */,userFlag, maxType, sid));
if (isPrimaryIndex && DEBUG) {
log.debug("Changing statement type: key="
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOTupleSerializer.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOTupleSerializer.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/spo/SPOTupleSerializer.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -155,6 +155,8 @@
final StatementEnum type = StatementEnum.decode(vbuf.array()[0]);
spo.setStatementType(type);
+
+ spo.setUserFlag(StatementEnum.isUserFlag(vbuf.array()[0]));
if (vbuf.limit() == 1 + 8) {
@@ -256,9 +258,9 @@
final StatementEnum type = spo.getStatementType();
// optionally set the override bit on the value.
- final byte b = (byte) (spo.isOverride() ? (type.code() | StatementEnum.MASK_OVERRIDE)
+ byte b = (byte) (spo.isOverride() ? (type.code() | StatementEnum.MASK_OVERRIDE)
: type.code());
-
+ b=(byte)(spo.getUserFlag()?b|StatementEnum.MASK_USER_FLAG:b);
buf.putByte(b);
if (keyOrder.getKeyArity() == 3) {
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -2279,8 +2279,8 @@
(BigdataURI) terms.get(spo.p()),//
(BigdataValue) terms.get(spo.o()),//
(BigdataResource) (c != null ? terms.get(c) : null),//
- spo.getStatementType()//
- );
+ spo.getStatementType(),//
+ spo.getUserFlag());
}
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/BigdataStatementIteratorImpl.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -210,13 +210,13 @@
if (spo.hasStatementType() == false) {
log.error("statement with no type: "
- + valueFactory.createStatement(s, p, o, c, null));
+ + valueFactory.createStatement(s, p, o, c, null, spo.getUserFlag()));
}
// the statement.
final BigdataStatement stmt = valueFactory.createStatement(s, p, o,
- c, spo.getStatementType());
+ c, spo.getStatementType(), spo.getUserFlag());
// save the reference.
stmts[i++] = stmt;
Modified: branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPO.java
===================================================================
--- branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPO.java 2010-07-26 20:17:12 UTC (rev 3301)
+++ branches/LEXICON_REFACTOR_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/spo/TestSPO.java 2010-07-26 21:58:56 UTC (rev 3302)
@@ -103,23 +103,18 @@
// test w/o override flag.
boolean override = false;
+ boolean userFlag=false;
for (StatementEnum type : StatementEnum.values()) {
- if (type == StatementEnum.Backchained) {
-
- // skip this - it is not a real statement type.
- continue;
-
- }
-
final byte[] val = SPO.serializeValue(new ByteArrayBuffer(),
- override, type, c);
+ override,userFlag, type, c);
final byte b = val[0];
assertEquals(type, StatementEnum.decode(b));
assertEquals(override, StatementEnum.isOverride(b));
+ assertEquals(userFlag, StatementEnum.isUserFlag(b));
final IV iv = new TermId(VTE.URI, 0);
@@ -128,6 +123,7 @@
// Should have (en|de)coded [c] as as statement identifier.
assertEquals(9, val.length);
assertEquals(c, SPO.decodeValue(new SPO(iv, iv, iv), val).c());
+ assertEquals(userFlag,SPO.decodeValue(new SPO(iv, iv, iv), val).getUserFlag());
} else {
// Should not have (en|de)coded a statement identifier.
assertEquals(1, val.length);
@@ -141,28 +137,85 @@
override = true;
for (StatementEnum type : StatementEnum.values()) {
- if (type == StatementEnum.Backchained) {
+ final byte[] val = SPO.serializeValue(new ByteArrayBuffer(),
+ override, userFlag, type, c);
- // skip this - it is not a real statement type.
- continue;
-
+ final byte b = val[0];
+
+ assertEquals(type, StatementEnum.decode(b));
+
+ assertEquals(override, StatementEnum.isOverride(b));
+ assertEquals(userFlag, StatementEnum.isUserFlag(b));
+
+ final IV iv = new TermId(VTE.URI, 0);
+
+ if (type == StatementEnum.Explicit) {
+ // Should have (en|de)coded [c] as as statement identifier.
+ assertEquals(9, val.length);
+ assertEquals(c, SPO.decodeValue(new SPO(iv, iv, iv), val).c());
+ assertEquals(userFlag,SPO.decodeValue(new SPO(iv, iv, iv), val).getUserFlag());
+ } else {
+ // Should not have (en|de)coded a statement identifier.
+ assertEquals(1, val.length);
+ assertEquals(null, SPO.decodeValue(
+ new SPO(iv, iv, iv), val).c());
}
+ }
+
+ // test w/o override flag && w userFlag
+ override = false;
+ userFlag=true;
+ for (StatementEnum type : StatementEnum.values()) {
+
final byte[] val = SPO.serializeValue(new ByteArrayBuffer(),
- override, type, c);
+ override, userFlag, type, c);
final byte b = val[0];
assertEquals(type, StatementEnum.decode(b));
+
+ assertEquals(override, StatementEnum.isOverride(b));
+ assertEquals(userFlag, StatementEnum.isUserFlag(b));
+ final IV iv = new TermId(VTE.URI, 0);
+
+ if (type == StatementEnum.Explicit
+ && c.isStatement()) {
+ // Should have (en|de)coded [c] as as statement identifier.
+ assertEquals(9, val.length);
+ assertEquals(c, SPO.decodeValue(new SPO(iv, iv, iv), val).c());
+ assertEquals(userFlag,SPO.decodeValue(new SPO(iv, iv, iv), val).getUserFlag());
+ } else {
+ // Should not have (en|de)coded a statement identifier.
+ assertEquals(1, val.length);
+ assertEquals(null, SPO.decodeValue(
+ new SPO(iv, iv, iv), val).c());
+ }
+
+ }
+
+ // test w/ override flag && w userFlag
+ override = true;
+ for (StatementEnum type : StatementEnum.values()) {
+
+ final byte[] val = SPO.serializeValue(new ByteArrayBuffer(),
+ override, userFlag, type, c);
+
+ final byte b = val[0];
+
+ assertEquals(type, StatementEnum.decode(b));
+
assertEquals(override, StatementEnum.isOverride(b));
-
+ assertEquals(userFlag, StatementEnum.isUserFlag(b));
+
final IV iv = new TermId(VTE.URI, 0);
if (type == StatementEnum.Explicit) {
// Should have (en|de)coded [c] as as statement identifier.
assertEquals(9, val.length);
assertEquals(c, SPO.decodeValue(new SPO(iv, iv, iv), val).c());
+ assertEquals(userFlag, SPO.decodeValue(new SPO(iv, iv, iv), val).getUserFlag());
} else {
// Should not have (en|de)coded a statement identifier.
assertEquals(1, val.length);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|