From: <tho...@us...> - 2010-09-14 19:14:36
|
Revision: 3549 http://bigdata.svn.sourceforge.net/bigdata/?rev=3549&view=rev Author: thompsonbry Date: 2010-09-14 19:14:30 +0000 (Tue, 14 Sep 2010) Log Message: ----------- Modified LoadStats and ClosureStats to use CATs in preparation for a concurrent data loader. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/ClosureStats.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/TruthMaintenance.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/load/SingleResourceReaderTask.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rio/LoadStats.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/DataLoader.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TaskATest.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/ClosureStats.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/ClosureStats.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/ClosureStats.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -24,6 +24,8 @@ */ package com.bigdata.rdf.inf; +import com.bigdata.counters.CAT; + /** * Statistics collected when performing inference. * @@ -38,13 +40,13 @@ * change in the #of statements in the database across the closure * operation. */ - public long mutationCount; + public final CAT mutationCount = new CAT(); /** * Time to compute the entailments and store them within the database * (milliseconds). */ - public long elapsed; + public final CAT elapsed = new CAT(); public ClosureStats() { @@ -55,26 +57,26 @@ * @param mutationCount * @param elapsed */ - public ClosureStats(long mutationCount,long elapsed) { + public ClosureStats(final long mutationCount,final long elapsed) { - this.mutationCount = mutationCount; + this.mutationCount.set(mutationCount); - this.elapsed = elapsed; + this.elapsed.set( elapsed); } - public synchronized void add(ClosureStats o) { + public void add(final ClosureStats o) { - this.mutationCount += o.mutationCount; + this.mutationCount.add( o.mutationCount.get()); - this.elapsed += o.elapsed; + this.elapsed.add(o.elapsed.get()); } public String toString() { - return getClass().getSimpleName() + "{mutationCount=" + mutationCount - + ", elapsed=" + elapsed + "ms}"; + return getClass().getSimpleName() + "{mutationCount=" + mutationCount.estimate_get() + + ", elapsed=" + elapsed.estimate_get() + "ms}"; } Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/TruthMaintenance.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/TruthMaintenance.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/inf/TruthMaintenance.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -440,7 +440,7 @@ final long elapsed = System.currentTimeMillis() - begin; - stats.elapsed += elapsed; + stats.elapsed.add(elapsed); if (INFO) log.info("Computed closure in " + elapsed + "ms"); Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/load/SingleResourceReaderTask.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/load/SingleResourceReaderTask.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/load/SingleResourceReaderTask.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -148,7 +148,7 @@ } // Note: IFF the task succeeds! - toldTriples.addAndGet(loadStats.toldTriples); + toldTriples.addAndGet(loadStats.toldTriples.get()); } @@ -194,9 +194,11 @@ final long now = System.currentTimeMillis(); - stats.toldTriples = nstmts; + stats.toldTriples.set(nstmts); - stats.totalTime = stats.loadTime = now - begin; + stats.totalTime.set( now - begin ); + + stats.loadTime.set( now - begin ); /* * This reports the load rate for the file, but this will only Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rio/LoadStats.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rio/LoadStats.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/rio/LoadStats.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -24,6 +24,7 @@ */ package com.bigdata.rdf.rio; +import com.bigdata.counters.CAT; import com.bigdata.rdf.inf.ClosureStats; /** @@ -34,12 +35,12 @@ */ public class LoadStats { - public long toldTriples; - public long loadTime; - public long commitTime; - public long totalTime; + public final CAT toldTriples = new CAT(); + public final CAT loadTime = new CAT(); + public final CAT commitTime = new CAT(); + public final CAT totalTime = new CAT(); - private transient long lastReportTime = 0l; + private transient volatile long lastReportTime = 0l; /** * The internal with which this class will log on {@link System#out} in @@ -55,19 +56,19 @@ public long triplesPerSecond() { - return ((long) (((double) toldTriples) / ((double) totalTime) * 1000d)); + return ((long) (((double) toldTriples.estimate_get()) / ((double) totalTime.estimate_get()) * 1000d)); } public void add(final LoadStats stats) { - toldTriples += stats.toldTriples; + toldTriples.add(stats.toldTriples.get()); - loadTime += stats.loadTime; + loadTime.add(stats.loadTime.get()); - commitTime += stats.commitTime; + commitTime.add(stats.commitTime.get()); - totalTime += stats.totalTime; + totalTime.add(stats.totalTime.get()); if (stats.closureStats != null) { @@ -82,7 +83,7 @@ if (lastReportTime == 0L) { - if (loadTime >= REPORT_INTERVAL) { + if (loadTime.estimate_get() >= REPORT_INTERVAL) { System.out.println("loading: " + toString()); @@ -111,14 +112,14 @@ return toldTriples + " stmts added in " - + ((double) loadTime) + + ((double) loadTime.estimate_get()) / 1000d + " secs, rate= " + triplesPerSecond() + ", commitLatency=" - + commitTime + + commitTime.estimate_get() + "ms" - + (closureStats.elapsed!=0L? "\n"+closureStats.toString() : ""); + + (closureStats.elapsed.estimate_get()!=0L? "\n"+closureStats.toString() : ""); } Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/DataLoader.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/DataLoader.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/DataLoader.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -230,8 +230,8 @@ if (buffer != null) { - if(log.isInfoEnabled()) - log.info("Flushing the buffer."); + if(log.isDebugEnabled()) + log.debug("Flushing the buffer."); buffer.flush(); @@ -610,7 +610,7 @@ database.commit(); - totals.commitTime += System.currentTimeMillis() - beginCommit; + totals.commitTime.add(System.currentTimeMillis() - beginCommit); if (log.isInfoEnabled()) log.info("commit: latency="+totals.commitTime+"ms"); @@ -838,8 +838,8 @@ if (file.isDirectory()) { - if (log.isInfoEnabled()) - log.info("loading directory: " + file); + if (log.isDebugEnabled()) + log.debug("loading directory: " + file); // final LoadStats loadStats = new LoadStats(); @@ -1007,9 +1007,9 @@ final long nstmts = loader.getStatementsAdded(); - stats.toldTriples = nstmts; + stats.toldTriples.set( nstmts ); - stats.loadTime = System.currentTimeMillis() - begin; + stats.loadTime.set(System.currentTimeMillis() - begin); if (closureEnum == ClosureEnum.Incremental || (endOfBatch && closureEnum == ClosureEnum.Batch)) { @@ -1037,20 +1037,24 @@ database.commit(); - stats.commitTime = System.currentTimeMillis() - beginCommit; + stats.commitTime.set(System.currentTimeMillis() - beginCommit); if (log.isInfoEnabled()) log.info("commit: latency=" + stats.commitTime + "ms"); } - stats.totalTime = System.currentTimeMillis() - begin; + stats.totalTime.set(System.currentTimeMillis() - begin); + // aggregate stats + totals.add(stats); + if (log.isInfoEnabled()) { - log.info(stats.toString()); + log.info("file:: " + stats + "; totals:: " + totals); if (buffer != null && buffer.getDatabase() instanceof AbstractLocalTripleStore) { - log.info(((AbstractLocalTripleStore) buffer.getDatabase()) + if(log.isDebugEnabled()) + log.debug(((AbstractLocalTripleStore) buffer.getDatabase()) .getLocalBTreeBytesWritten(new StringBuilder()) .toString()); } @@ -1060,6 +1064,9 @@ } catch ( Exception ex ) { + // aggregate stats even for exceptions. + totals.add(stats); + /* * Note: discard anything in the buffer in case auto-flush is * disabled. This prevents the buffer from retaining data after a @@ -1096,11 +1103,11 @@ throw ex2; - } finally { +// } finally { +// +// // aggregate regardless of the outcome. +// totals.add(stats); - // aggregate regardless of the outcome. - totals.add(stats); - } } @@ -1436,8 +1443,8 @@ || (name.endsWith(".gz") && RDFFormat.forFileName(name .substring(0, name.length() - 3)) != null); - if (log.isInfoEnabled()) - log.info("dir=" + dir + ", name=" + name + " : isRDF=" + isRDF); + if (log.isDebugEnabled()) + log.debug("dir=" + dir + ", name=" + name + " : isRDF=" + isRDF); return isRDF; Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TaskATest.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TaskATest.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TaskATest.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -475,23 +475,23 @@ // Explicit + (Entailments = Axioms + Inferred) - final long totalTriples = loadStats[run].toldTriples - + (closureStats!=null?closureStats.mutationCount : 0); + final long totalTriples = loadStats[run].toldTriples.get() + + (closureStats!=null?closureStats.mutationCount.get() : 0); // loadTime + closureTime + commitTime. - final long totalTime = loadStats[run].loadTime - + (closureStats != null ? closureStats.elapsed : 0) - + loadStats[run].commitTime; + final long totalTime = loadStats[run].loadTime.get() + + (closureStats != null ? closureStats.elapsed.get() : 0) + + loadStats[run].commitTime.get(); System.out.println( all_sources[ run * 3 ]+ ", " + ( errors[ run ] == null ? "Ok" +", "+loadStats[run].toldTriples - +", "+loadStats[run].loadTime/1000 - +", "+tps(loadStats[run].toldTriples,loadStats[run].loadTime) - +", "+(closureStats!=null?closureStats.mutationCount:"") - +", "+(closureStats!=null?closureStats.elapsed/1000:"") - +", "+(closureStats!=null?tps(closureStats.mutationCount,closureStats.elapsed):"") + +", "+loadStats[run].loadTime.get()/1000 + +", "+tps(loadStats[run].toldTriples.get(),loadStats[run].loadTime.get()) + +", "+(closureStats!=null?closureStats.mutationCount.get():"") + +", "+(closureStats!=null?closureStats.elapsed.get()/1000:"") + +", "+(closureStats!=null?tps(closureStats.mutationCount.get(),closureStats.elapsed.get()):"") +", "+loadStats[run].commitTime +", "+tps(totalTriples,totalTime) Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java 2010-09-14 19:13:44 UTC (rev 3548) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/metrics/TestMetrics.java 2010-09-14 19:14:30 UTC (rev 3549) @@ -1085,7 +1085,7 @@ /* * #of explicit statements loaded. */ - toldTriples = loadStats.toldTriples; + toldTriples = loadStats.toldTriples.get(); /* * This is the elapsed time for the entire transaction in which the file @@ -1093,19 +1093,19 @@ * store, and the time required to perform the transaction commit. */ // transactionTime = System.currentTimeMillis() - begin; - transactionTime = loadStats.totalTime; + transactionTime = loadStats.totalTime.get(); /* * This is the time required to load the triples exclusive of the * startup and commit time for the transaction. */ - loadTime = loadStats.loadTime; + loadTime = loadStats.loadTime.get(); /* * A pragmatic estimate of the commit time that assumes the transaction * start time is zero. */ - commitTime = loadStats.commitTime; + commitTime = loadStats.commitTime.get(); // commitTime = transactionTime - loadTime; /* @@ -1132,7 +1132,7 @@ statementsAdded = statementCount1 - statementCount0; // inferencesAdded = inferenceCount1 - inferenceCount0; - inferencesAdded = loadStats.closureStats.mutationCount; + inferencesAdded = loadStats.closureStats.mutationCount.get(); // int explicitAdded = statementsAdded - inferencesAdded; proofsAdded = proofCount1 - proofCount0; urisAdded = uriCount1 - uriCount0; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-12-19 21:51:51
|
Revision: 4020 http://bigdata.svn.sourceforge.net/bigdata/?rev=4020&view=rev Author: thompsonbry Date: 2010-12-19 21:51:44 +0000 (Sun, 19 Dec 2010) Log Message: ----------- Added support for inlining xsd:dateTime literals. This is disabled by default for backward compatibility. We should consider enabling it by default at the next release and providing a migration path for older KB instances. Modified Paths: -------------- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DefaultExtensionFactory.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IExtensionFactory.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSD.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/SampleExtensionFactory.java branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java Added Paths: ----------- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DateTimeExtension.java Added: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DateTimeExtension.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DateTimeExtension.java (rev 0) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DateTimeExtension.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -0,0 +1,131 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package com.bigdata.rdf.internal; + +import java.util.GregorianCalendar; +import java.util.TimeZone; + +import javax.xml.datatype.DatatypeConfigurationException; +import javax.xml.datatype.DatatypeFactory; +import javax.xml.datatype.XMLGregorianCalendar; + +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.datatypes.XMLDatatypeUtil; + +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; + +/** + * This implementation of {@link IExtension} implements inlining for literals + * that represent xsd:dateTime literals. These literals will be stored as time + * in milliseconds since the epoch. The milliseconds are encoded as an inline + * long. + */ +public class DateTimeExtension<V extends BigdataValue> implements IExtension<V> { + + private final BigdataURI dateTime; + + public DateTimeExtension(final IDatatypeURIResolver resolver) { + + this.dateTime = resolver.resolve(XSD.DATETIME); + + } + + public BigdataURI getDatatype() { + + return dateTime; + + } + + /** + * Attempts to convert the supplied value into an epoch representation. + * Tests for a literal value with the correct datatype that can be converted + * to a positive long integer. Encodes the long in a delegate + * {@link XSDLongIV}, and returns an {@link ExtensionIV} to wrap the native + * type. + */ + public ExtensionIV createIV(final Value value) { + + if (value instanceof Literal == false) + throw new IllegalArgumentException(); + + final Literal lit = (Literal) value; + + final URI dt = lit.getDatatype(); + + if (dt == null || !XSD.DATETIME.stringValue().equals(dt.stringValue())) + throw new IllegalArgumentException(); + + final String s = value.stringValue(); + + final XMLGregorianCalendar c = XMLDatatypeUtil.parseCalendar(s); + + /* + * Returns the current time as UTC milliseconds from the epoch + */ + final long l = c.toGregorianCalendar().getTimeInMillis(); + + final AbstractLiteralIV delegate = new XSDLongIV(l); + + return new ExtensionIV(delegate, (TermId) getDatatype().getIV()); + + } + + /** + * Use the long value of the {@link XSDLongIV} delegate (which represents + * milliseconds since the epoch) to create a an XMLGregorianCalendar + * object (GMT timezone). Use the XMLGregorianCalendar to create a datatype + * literal value with the xsd:dateTime datatype. + */ + public V asValue(final ExtensionIV iv, final BigdataValueFactory vf) { + + /* + * Milliseconds since the epoch. + */ + final long l = iv.getDelegate().longValue(); + + final GregorianCalendar c = + new GregorianCalendar(TimeZone.getTimeZone("GMT")); + c.setTimeInMillis(l); + + try { + + final XMLGregorianCalendar xmlGC = + DatatypeFactory.newInstance().newXMLGregorianCalendar(c); + + return (V) vf.createLiteral(xmlGC); + + } catch (DatatypeConfigurationException ex) { + + throw new IllegalArgumentException("bad iv: " + iv, ex); + + } + + } + +} Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DefaultExtensionFactory.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DefaultExtensionFactory.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/DefaultExtensionFactory.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -1,26 +1,36 @@ -package com.bigdata.rdf.internal; - -/** - * Empty {@link IExtensionFactory}. - */ -public class DefaultExtensionFactory implements IExtensionFactory { - - private final IExtension[] extensions; - - public DefaultExtensionFactory() { - - extensions = new IExtension[0]; - - } - - public void init(final IDatatypeURIResolver resolver) { - - } - - public IExtension[] getExtensions() { - - return extensions; - - } - -} +package com.bigdata.rdf.internal; + +import java.util.Collection; +import java.util.LinkedList; + +/** + * Empty {@link IExtensionFactory}. + */ +public class DefaultExtensionFactory implements IExtensionFactory { + + private final Collection<IExtension> extensions; + + private volatile IExtension[] extensionsArray; + + public DefaultExtensionFactory() { + + extensions = new LinkedList<IExtension>(); + + } + + public void init(final IDatatypeURIResolver resolver, + final boolean inlineDateTimes) { + + if (inlineDateTimes) + extensions.add(new DateTimeExtension(resolver)); + extensionsArray = extensions.toArray(new IExtension[extensions.size()]); + + } + + public IExtension[] getExtensions() { + + return extensionsArray; + + } + +} Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IExtensionFactory.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IExtensionFactory.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/IExtensionFactory.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -1,52 +1,56 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program 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; version 2 of the License. - -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, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package com.bigdata.rdf.internal; - -/** - * IExtensionFactories are responsible for enumerating what extensions are - * supported for a particular database configuration. Bigdata comes packaged - * with a {@link SampleExtensionFactory} that supplies two starter extensions - - * the {@link EpochExtension} (for representing time since the epoch as a long - * integer) and the {@link ColorsEnumExtension} (a sample extension for how to - * represent an enumeration via inline literals). - */ -public interface IExtensionFactory { - - /** - * This will be called very early in the IExtensionFactory lifecycle so that - * the {@link TermId}s for the {@link IExtension}'s datatype URIs will be on - * hand when needed. - * - * @param resolver - * the datatype URI resolver - */ - void init(final IDatatypeURIResolver resolver); - - /** - * Return the supported extensions. - */ - IExtension[] getExtensions(); - -} +/** + +Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package com.bigdata.rdf.internal; + +/** + * IExtensionFactories are responsible for enumerating what extensions are + * supported for a particular database configuration. Bigdata comes packaged + * with a {@link SampleExtensionFactory} that supplies two starter extensions - + * the {@link EpochExtension} (for representing time since the epoch as a long + * integer) and the {@link ColorsEnumExtension} (a sample extension for how to + * represent an enumeration via inline literals). + */ +public interface IExtensionFactory { + + /** + * This will be called very early in the IExtensionFactory lifecycle so that + * the {@link TermId}s for the {@link IExtension}'s datatype URIs will be on + * hand when needed. + * + * @param resolver + * the datatype URI resolver + * @param inlineDateTimes + * if true, inine the xsd:dateTime datatype using the + * {@link DateTimeExtension} class. + */ + void init(final IDatatypeURIResolver resolver, + final boolean inlineDateTimes); + + /** + * Return the supported extensions. + */ + IExtension[] getExtensions(); + +} Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/LexiconConfiguration.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -1,313 +1,315 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program 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; version 2 of the License. - -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, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ -/* - * Created July 10, 2010 - */ - -package com.bigdata.rdf.internal; - -import java.util.HashMap; -import java.util.Map; -import java.util.UUID; -import org.apache.log4j.Logger; -import org.openrdf.model.BNode; -import org.openrdf.model.Literal; -import org.openrdf.model.URI; -import org.openrdf.model.Value; -import org.openrdf.model.datatypes.XMLDatatypeUtil; -import com.bigdata.rdf.model.BigdataURI; -import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactory; - -/** - * An object which describes which kinds of RDF Values are inlined into the - * statement indices and how other RDF Values are coded into the lexicon. - * - * @author <a href="mailto:tho...@us...">Bryan Thompson</a> - * @version $Id$ - */ -public class LexiconConfiguration<V extends BigdataValue> - implements ILexiconConfiguration<V> { - - protected static final Logger log = - Logger.getLogger(LexiconConfiguration.class); - - private final boolean inlineLiterals, inlineBNodes; - - private final IExtensionFactory xFactory; - - private final Map<TermId, IExtension> termIds; - - private final Map<String, IExtension> datatypes; - - public LexiconConfiguration(final boolean inlineLiterals, - final boolean inlineBNodes, final IExtensionFactory xFactory) { - - this.inlineLiterals = inlineLiterals; - this.inlineBNodes = inlineBNodes; - this.xFactory = xFactory; - - termIds = new HashMap<TermId, IExtension>(); - datatypes = new HashMap<String, IExtension>(); - - } - - public void initExtensions(final IDatatypeURIResolver resolver) { - - xFactory.init(resolver); - - for (IExtension extension : xFactory.getExtensions()) { - BigdataURI datatype = extension.getDatatype(); - if (datatype == null) - continue; - termIds.put((TermId) datatype.getIV(), extension); - datatypes.put(datatype.stringValue(), extension); - } - - } - - public V asValue(final ExtensionIV iv, final BigdataValueFactory vf) { - final TermId datatype = iv.getExtensionDatatype(); - return (V) termIds.get(datatype).asValue(iv, vf); - } - - public IV createInlineIV(final Value value) { - - // we know right away we can't handle URIs - if (value instanceof URI) - return null; - - if (value instanceof Literal) { - - final Literal l = (Literal) value; - - final URI datatype = l.getDatatype(); - - // not a datatyped literal - if (datatype == null) - return null; - - if (datatypes.containsKey(datatype.stringValue())) { - - final IExtension xFactory = - datatypes.get(datatype.stringValue()); - - try { - - final IV iv = xFactory.createIV(value); - - if (iv != null && value instanceof BigdataValue) - ((BigdataValue) value).setIV(iv); - - return iv; - - } catch (Exception ex) { - - log.warn("problem creating inline internal value for " + - "extension datatype: " + value.stringValue()); - - /* - * Some sort of parse error in the literal value most - * likely. Resort to term identifiers. - */ - return null; - - } - - } - - // get the native DTE - final DTE dte = DTE.valueOf(datatype); - - // no native DTE for this datatype - if (dte == null) - return null; - - // check to see if we are inlining literals of this type - if (!isInline(VTE.LITERAL, dte)) - return null; - - final String v = value.stringValue(); - - IV iv = null; - - try { - - switch (dte) { - case XSDBoolean: - iv = new XSDBooleanIV(XMLDatatypeUtil.parseBoolean(v)); - break; - case XSDByte: - iv = new XSDByteIV(XMLDatatypeUtil.parseByte(v)); - break; - case XSDShort: - iv = new XSDShortIV(XMLDatatypeUtil.parseShort(v)); - break; - case XSDInt: - iv = new XSDIntIV(XMLDatatypeUtil.parseInt(v)); - break; - case XSDLong: - iv = new XSDLongIV(XMLDatatypeUtil.parseLong(v)); - break; - case XSDFloat: - iv = new XSDFloatIV(XMLDatatypeUtil.parseFloat(v)); - break; - case XSDDouble: - iv = new XSDDoubleIV(XMLDatatypeUtil.parseDouble(v)); - break; - case XSDInteger: - iv = new XSDIntegerIV(XMLDatatypeUtil.parseInteger(v)); - break; - case XSDDecimal: - iv = new XSDDecimalIV(XMLDatatypeUtil.parseDecimal(v)); - break; - case UUID: - iv = new UUIDLiteralIV(UUID.fromString(v)); - break; - default: - iv = null; - } - - } catch (NumberFormatException ex) { - - // some dummy doesn't know how to format a number - // default to term identifier for this term - - log.warn("number format exception: " + v); - - } - - if (iv != null && value instanceof BigdataValue) - ((BigdataValue) value).setIV(iv); - - return iv; - - } else if (value instanceof BNode) { - - final BNode b = (BNode) value; - - final String id = b.getID(); - - final char c = id.charAt(0); - - if (c == 'u') { - - try { - - final UUID uuid = UUID.fromString(id.substring(1)); - - if (!uuid.toString().equals(id.substring(1))) - return null; - - if (!isInline(VTE.BNODE, DTE.UUID)) - return null; - - final IV iv = new UUIDBNodeIV(uuid); - - if (value instanceof BigdataValue) - ((BigdataValue) value).setIV(iv); - - return iv; - - } catch (Exception ex) { - - // string id could not be converted to a UUID - - } - - } else if (c == 'i') { - - try { - - final Integer i = Integer.valueOf(id.substring(1)); - - // cannot normalize id, needs to remain syntactically identical - if (!i.toString().equals(id.substring(1))) - return null; - - if (!isInline(VTE.BNODE, DTE.XSDInt)) - return null; - - final IV iv = new NumericBNodeIV(i); - - if (value instanceof BigdataValue) - ((BigdataValue) value).setIV(iv); - - return iv; - - } catch (Exception ex) { - - // string id could not be converted to an Integer - - } - - } - - } - - return null; - - } - - /** - * See {@link ILexiconConfiguration#isInline(VTE, DTE)}. - */ - public boolean isInline(final VTE vte, final DTE dte) { - - switch (vte) { - case BNODE: - return inlineBNodes && isSupported(dte); - case LITERAL: - return inlineLiterals && isSupported(dte); - default: - return false; - } - - } - - private boolean isSupported(final DTE dte) { - - switch (dte) { - case XSDBoolean: - case XSDByte: - case XSDShort: - case XSDInt: - case XSDLong: - case XSDFloat: - case XSDDouble: - case XSDInteger: - case XSDDecimal: - case UUID: - return true; - case XSDUnsignedByte: // none of the unsigneds are tested yet - case XSDUnsignedShort: // none of the unsigneds are tested yet - case XSDUnsignedInt: // none of the unsigneds are tested yet - case XSDUnsignedLong: // none of the unsigneds are tested yet - default: - return false; - } - - } - -} +/** + +Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +/* + * Created July 10, 2010 + */ + +package com.bigdata.rdf.internal; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.apache.log4j.Logger; +import org.openrdf.model.BNode; +import org.openrdf.model.Literal; +import org.openrdf.model.URI; +import org.openrdf.model.Value; +import org.openrdf.model.datatypes.XMLDatatypeUtil; +import com.bigdata.rdf.model.BigdataURI; +import com.bigdata.rdf.model.BigdataValue; +import com.bigdata.rdf.model.BigdataValueFactory; + +/** + * An object which describes which kinds of RDF Values are inlined into the + * statement indices and how other RDF Values are coded into the lexicon. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + * @version $Id$ + */ +public class LexiconConfiguration<V extends BigdataValue> + implements ILexiconConfiguration<V> { + + protected static final Logger log = + Logger.getLogger(LexiconConfiguration.class); + + private final boolean inlineLiterals, inlineBNodes, inlineDateTimes; + + private final IExtensionFactory xFactory; + + private final Map<TermId, IExtension> termIds; + + private final Map<String, IExtension> datatypes; + + public LexiconConfiguration(final boolean inlineLiterals, + final boolean inlineBNodes, final boolean inlineDateTimes, + final IExtensionFactory xFactory) { + + this.inlineLiterals = inlineLiterals; + this.inlineBNodes = inlineBNodes; + this.inlineDateTimes = inlineDateTimes; + this.xFactory = xFactory; + + termIds = new HashMap<TermId, IExtension>(); + datatypes = new HashMap<String, IExtension>(); + + } + + public void initExtensions(final IDatatypeURIResolver resolver) { + + xFactory.init(resolver, inlineDateTimes); + + for (IExtension extension : xFactory.getExtensions()) { + BigdataURI datatype = extension.getDatatype(); + if (datatype == null) + continue; + termIds.put((TermId) datatype.getIV(), extension); + datatypes.put(datatype.stringValue(), extension); + } + + } + + public V asValue(final ExtensionIV iv, final BigdataValueFactory vf) { + final TermId datatype = iv.getExtensionDatatype(); + return (V) termIds.get(datatype).asValue(iv, vf); + } + + public IV createInlineIV(final Value value) { + + // we know right away we can't handle URIs + if (value instanceof URI) + return null; + + if (value instanceof Literal) { + + final Literal l = (Literal) value; + + final URI datatype = l.getDatatype(); + + // not a datatyped literal + if (datatype == null) + return null; + + if (datatypes.containsKey(datatype.stringValue())) { + + final IExtension xFactory = + datatypes.get(datatype.stringValue()); + + try { + + final IV iv = xFactory.createIV(value); + + if (iv != null && value instanceof BigdataValue) + ((BigdataValue) value).setIV(iv); + + return iv; + + } catch (Exception ex) { + + log.warn("problem creating inline internal value for " + + "extension datatype: " + value.stringValue()); + + /* + * Some sort of parse error in the literal value most + * likely. Resort to term identifiers. + */ + return null; + + } + + } + + // get the native DTE + final DTE dte = DTE.valueOf(datatype); + + // no native DTE for this datatype + if (dte == null) + return null; + + // check to see if we are inlining literals of this type + if (!isInline(VTE.LITERAL, dte)) + return null; + + final String v = value.stringValue(); + + IV iv = null; + + try { + + switch (dte) { + case XSDBoolean: + iv = new XSDBooleanIV(XMLDatatypeUtil.parseBoolean(v)); + break; + case XSDByte: + iv = new XSDByteIV(XMLDatatypeUtil.parseByte(v)); + break; + case XSDShort: + iv = new XSDShortIV(XMLDatatypeUtil.parseShort(v)); + break; + case XSDInt: + iv = new XSDIntIV(XMLDatatypeUtil.parseInt(v)); + break; + case XSDLong: + iv = new XSDLongIV(XMLDatatypeUtil.parseLong(v)); + break; + case XSDFloat: + iv = new XSDFloatIV(XMLDatatypeUtil.parseFloat(v)); + break; + case XSDDouble: + iv = new XSDDoubleIV(XMLDatatypeUtil.parseDouble(v)); + break; + case XSDInteger: + iv = new XSDIntegerIV(XMLDatatypeUtil.parseInteger(v)); + break; + case XSDDecimal: + iv = new XSDDecimalIV(XMLDatatypeUtil.parseDecimal(v)); + break; + case UUID: + iv = new UUIDLiteralIV(UUID.fromString(v)); + break; + default: + iv = null; + } + + } catch (NumberFormatException ex) { + + // some dummy doesn't know how to format a number + // default to term identifier for this term + + log.warn("number format exception: " + v); + + } + + if (iv != null && value instanceof BigdataValue) + ((BigdataValue) value).setIV(iv); + + return iv; + + } else if (value instanceof BNode) { + + final BNode b = (BNode) value; + + final String id = b.getID(); + + final char c = id.charAt(0); + + if (c == 'u') { + + try { + + final UUID uuid = UUID.fromString(id.substring(1)); + + if (!uuid.toString().equals(id.substring(1))) + return null; + + if (!isInline(VTE.BNODE, DTE.UUID)) + return null; + + final IV iv = new UUIDBNodeIV(uuid); + + if (value instanceof BigdataValue) + ((BigdataValue) value).setIV(iv); + + return iv; + + } catch (Exception ex) { + + // string id could not be converted to a UUID + + } + + } else if (c == 'i') { + + try { + + final Integer i = Integer.valueOf(id.substring(1)); + + // cannot normalize id, needs to remain syntactically identical + if (!i.toString().equals(id.substring(1))) + return null; + + if (!isInline(VTE.BNODE, DTE.XSDInt)) + return null; + + final IV iv = new NumericBNodeIV(i); + + if (value instanceof BigdataValue) + ((BigdataValue) value).setIV(iv); + + return iv; + + } catch (Exception ex) { + + // string id could not be converted to an Integer + + } + + } + + } + + return null; + + } + + /** + * See {@link ILexiconConfiguration#isInline(VTE, DTE)}. + */ + public boolean isInline(final VTE vte, final DTE dte) { + + switch (vte) { + case BNODE: + return inlineBNodes && isSupported(dte); + case LITERAL: + return inlineLiterals && isSupported(dte); + default: + return false; + } + + } + + private boolean isSupported(final DTE dte) { + + switch (dte) { + case XSDBoolean: + case XSDByte: + case XSDShort: + case XSDInt: + case XSDLong: + case XSDFloat: + case XSDDouble: + case XSDInteger: + case XSDDecimal: + case UUID: + return true; + case XSDUnsignedByte: // none of the unsigneds are tested yet + case XSDUnsignedShort: // none of the unsigneds are tested yet + case XSDUnsignedInt: // none of the unsigneds are tested yet + case XSDUnsignedLong: // none of the unsigneds are tested yet + default: + return false; + } + + } + +} Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSD.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSD.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/internal/XSD.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -1,83 +1,86 @@ -/** - -Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. - -Contact: - SYSTAP, LLC - 4501 Tower Road - Greensboro, NC 27410 - lic...@bi... - -This program 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; version 2 of the License. - -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, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -*/ - -package com.bigdata.rdf.internal; - -import org.openrdf.model.URI; -import org.openrdf.model.impl.URIImpl; - -/** - * Collects various XSD URIs as constants. - * - * @author <a href="mailto:mrp...@us...">Mike Personick</a> - * @version $Id$ - */ -public interface XSD { - - String NAMESPACE = "http://www.w3.org/2001/XMLSchema#"; - - URI BOOLEAN = new URIImpl(NAMESPACE - + "boolean"); - - URI BYTE = new URIImpl(NAMESPACE - + "byte"); - - URI SHORT = new URIImpl(NAMESPACE - + "short"); - - URI INT = new URIImpl(NAMESPACE - + "int"); - - URI LONG = new URIImpl(NAMESPACE - + "long"); - - URI UNSIGNED_BYTE = new URIImpl(NAMESPACE - + "unsignedByte"); - - URI UNSIGNED_SHORT = new URIImpl(NAMESPACE - + "unsignedShort"); - - URI UNSIGNED_INT = new URIImpl(NAMESPACE - + "unsignedInt"); - - URI UNSIGNED_LONG = new URIImpl(NAMESPACE - + "unsignedLong"); - - URI FLOAT = new URIImpl(NAMESPACE - + "float"); - - URI DOUBLE = new URIImpl(NAMESPACE - + "double"); - - URI INTEGER = new URIImpl(NAMESPACE - + "integer"); - - URI DECIMAL = new URIImpl(NAMESPACE - + "decimal"); - - URI UUID = new URIImpl(NAMESPACE - + "uuid"); - - -} +/** + +Copyright (C) SYSTAP, LLC 2006-2010. All rights reserved. + +Contact: + SYSTAP, LLC + 4501 Tower Road + Greensboro, NC 27410 + lic...@bi... + +This program 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; version 2 of the License. + +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, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +package com.bigdata.rdf.internal; + +import org.openrdf.model.URI; +import org.openrdf.model.impl.URIImpl; + +/** + * Collects various XSD URIs as constants. + * + * @author <a href="mailto:mrp...@us...">Mike Personick</a> + * @version $Id$ + */ +public interface XSD { + + String NAMESPACE = "http://www.w3.org/2001/XMLSchema#"; + + URI BOOLEAN = new URIImpl(NAMESPACE + + "boolean"); + + URI BYTE = new URIImpl(NAMESPACE + + "byte"); + + URI SHORT = new URIImpl(NAMESPACE + + "short"); + + URI INT = new URIImpl(NAMESPACE + + "int"); + + URI LONG = new URIImpl(NAMESPACE + + "long"); + + URI UNSIGNED_BYTE = new URIImpl(NAMESPACE + + "unsignedByte"); + + URI UNSIGNED_SHORT = new URIImpl(NAMESPACE + + "unsignedShort"); + + URI UNSIGNED_INT = new URIImpl(NAMESPACE + + "unsignedInt"); + + URI UNSIGNED_LONG = new URIImpl(NAMESPACE + + "unsignedLong"); + + URI FLOAT = new URIImpl(NAMESPACE + + "float"); + + URI DOUBLE = new URIImpl(NAMESPACE + + "double"); + + URI INTEGER = new URIImpl(NAMESPACE + + "integer"); + + URI DECIMAL = new URIImpl(NAMESPACE + + "decimal"); + + URI UUID = new URIImpl(NAMESPACE + + "uuid"); + + URI DATETIME = new URIImpl(NAMESPACE + + "dateTime"); + + +} Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/lexicon/LexiconRelation.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -384,7 +384,7 @@ } { - + inlineLiterals = Boolean.parseBoolean(getProperty( AbstractTripleStore.Options.INLINE_LITERALS, AbstractTripleStore.Options.DEFAULT_INLINE_LITERALS)); @@ -392,26 +392,35 @@ inlineBNodes = storeBlankNodes && Boolean.parseBoolean(getProperty( AbstractTripleStore.Options.INLINE_BNODES, AbstractTripleStore.Options.DEFAULT_INLINE_BNODES)); - + + inlineDateTimes = Boolean.parseBoolean(getProperty( + AbstractTripleStore.Options.INLINE_DATE_TIMES, + AbstractTripleStore.Options.DEFAULT_INLINE_DATE_TIMES)); + try { - + final Class<IExtensionFactory> xfc = determineExtensionFactoryClass(); + final IExtensionFactory xFactory = xfc.newInstance(); - + lexiconConfiguration = new LexiconConfiguration( - inlineLiterals, inlineBNodes, xFactory); - + inlineLiterals, inlineBNodes, inlineDateTimes, xFactory); + } catch (InstantiationException e) { + throw new IllegalArgumentException( AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException( AbstractTripleStore.Options.EXTENSION_FACTORY_CLASS, e); + } - + } - + } /** @@ -580,7 +589,13 @@ */ final private boolean inlineBNodes; - + /** + * Are xsd:dateTime litersls being inlined into the statement indices. + * + * {@link AbstractTripleStore.Options#INLINE_DATE_TIMES} + */ + final private boolean inlineDateTimes; + /** * Return <code>true</code> if datatype literals are being inlined into * the statement indices. Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/java/com/bigdata/rdf/store/AbstractTripleStore.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -880,15 +880,28 @@ String DEFAULT_INLINE_BNODES = "false"; - /** - * The name of the {@link IExtensionFactory} class. The implementation - * MUST declare a constructor that accepts an - * {@link IDatatypeURIResolver} as its only argument. The - * {@link IExtension}s constructed by the factory need a resolver to - * resolve datatype URIs to term identifiers in the database. - * - * @see #DEFAULT_EXTENSION_FACTORY_CLASS - */ + /** + * Set up database to inline date/times directly into the statement + * indices rather than using the lexicon to map them to term identifiers + * and back. Date times will be converted to UTC, then stored as + * milliseconds since the epoch. Thus if you inline date/times you will + * lose the canonical representation of the date/time, and you will not + * be able to recover the original time zone of the date/time. + */ + String INLINE_DATE_TIMES = AbstractTripleStore.class.getName() + + ".inlineDateTimes"; + + String DEFAULT_INLINE_DATE_TIMES = "false"; + + /** + * The name of the {@link IExtensionFactory} class. The implementation + * MUST declare a constructor that accepts an + * {@link IDatatypeURIResolver} as its only argument. The + * {@link IExtension}s constructed by the factory need a resolver to + * resolve datatype URIs to term identifiers in the database. + * + * @see #DEFAULT_EXTENSION_FACTORY_CLASS + */ String EXTENSION_FACTORY_CLASS = AbstractTripleStore.class.getName() + ".extensionFactoryClass"; Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/SampleExtensionFactory.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/SampleExtensionFactory.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/SampleExtensionFactory.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -20,8 +20,10 @@ } - public void init(final IDatatypeURIResolver resolver) { + public void init(final IDatatypeURIResolver resolver,boolean inlineDateTimes) { + if (inlineDateTimes) + extensions.add(new DateTimeExtension(resolver)); extensions.add(new EpochExtension(resolver)); extensions.add(new ColorsEnumExtension(resolver)); extensionsArray = extensions.toArray(new IExtension[2]); Modified: branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java =================================================================== --- branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java 2010-12-19 21:49:22 UTC (rev 4019) +++ branches/JOURNAL_HA_BRANCH/bigdata-rdf/src/test/com/bigdata/rdf/internal/TestEncodeDecodeKeys.java 2010-12-19 21:51:44 UTC (rev 4020) @@ -31,11 +31,14 @@ import java.math.BigInteger; import java.util.Random; import java.util.UUID; + +import javax.xml.datatype.DatatypeFactory; + +import junit.framework.TestCase2; + import org.openrdf.model.URI; import org.openrdf.model.impl.LiteralImpl; -import junit.framework.TestCase2; - import com.bigdata.btree.keys.IKeyBuilder; import com.bigdata.btree.keys.KeyBuilder; import com.bigdata.rdf.model.BigdataBNode; @@ -335,7 +338,7 @@ * @param e * The array of the expected values. */ - protected void doEncodeDecodeTest(final IV<?, ?>[] e) { + protected IV<?, ?>[] doEncodeDecodeTest(final IV<?, ?>[] e) { /* * Encode. @@ -370,6 +373,8 @@ } + return a; + } } @@ -762,4 +767,61 @@ } + public void test_SPO_encodeDecodeDateTime() throws Exception { + + final BigdataValueFactory vf = BigdataValueFactoryImpl.getInstance("test"); + + final DatatypeFactory df = DatatypeFactory.newInstance(); + + final DateTimeExtension<BigdataValue> ext = + new DateTimeExtension<BigdataValue>(new IDatatypeURIResolver() { + public BigdataURI resolve(URI uri) { + BigdataURI buri = vf.createURI(uri.stringValue()); + buri.setIV(new TermId(VTE.URI, 1024)); + return buri; + } + }); + + final BigdataLiteral[] dt = { + vf.createLiteral( + df.newXMLGregorianCalendar("2001-10-26T21:32:52")), + vf.createLiteral( + df.newXMLGregorianCalendar("2001-10-26T21:32:52+02:00")), + vf.createLiteral( + df.newXMLGregorianCalendar("2001-10-26T19:32:52Z")), + vf.createLiteral( + df.newXMLGregorianCalendar("2001-10-26T19:32:52+00:00")), + vf.createLiteral( + df.newXMLGregorianCalendar("-2001-10-26T21:32:52")), + vf.createLiteral( + df.newXMLGregorianCalendar("2001-10-26T21:32:52.12679")), + vf.createLiteral( + df.newXMLGregorianCalendar("1901-10-26T21:32:52")), + }; + + final IV<?, ?>[] e = {// + ext.createIV(dt[0]), + ext.createIV(dt[1]), + ext.createIV(dt[2]), + ext.createIV(dt[3]), + ext.createIV(dt[4]), + ext.createIV(dt[5]), + ext.createIV(dt[6]), +// ext.createIV(dt[7]), + }; + + final IV<?, ?>[] a = doEncodeDecodeTest(e); + + if (log.isInfoEnabled()) { + for (int i = 0; i < e.length; i++) { + log.info(dt[i]); + log.info(ext.asValue((ExtensionIV) e[i], vf)); + log.info(ext.asValue((ExtensionIV) a[i], vf)); + log.info(""); + } + } + + + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |