From: <tho...@us...> - 2012-08-09 15:24:28
|
Revision: 6428 http://bigdata.svn.sourceforge.net/bigdata/?rev=6428&view=rev Author: thompsonbry Date: 2012-08-09 15:24:19 +0000 (Thu, 09 Aug 2012) Log Message: ----------- - Dropped GOMListener. The existing NSS can be used as is. The ObjectManagerModel now generates a UUID in its constructor. GOMWebUtil was modified to attach the OM instance as a request attribute so the OM is now scoped to the page. I have not yet factored the global object cache out of the OM. It is Ok if the OM has a local object cache (Resource => IGPO), but the global cache needs to be something that can be distributed and must notice invalidation messages from updates using a change log listener. - Test suites were modified to use a base class where possible, to NOT use System.out, to use om.close(), etc. I noticed that many of the tests are not really testing anything. They are more like utility programs to explore the data. Tests need to use assert() and actually test pre-/post- conditions for the API. The test suites were running with truth maintenance enabled due to a spelling error. I have simplified the Journal configuration and turned off TM. - Dropped GOMServlet. It was unused. - Coining new URLs. Use endpoint/gpo/clientUUID/<ID>. This works for each KB instance. Use req.getRequestURL() to get the endpoint URL as actually requested. This should work with virtual hosting. The remote OM version always has the SPARQL endpoint, but we need to have this for the embedded version as well - at least when used from a JSP page. That can be handled by GOMWebUtil since it has the request parameter. The test suites however do not so we need to mock the endpoint URI there. - All classes should declare their own private logger using the class name, not an interface name. - Improper synchronization for the native transaction identifier. I have added an explicit lock for this, but the whole concept of native transactions needs to be reconsidered. I think that we just want to let the Sail handle the buffering.... - Added genId(String:scope) to make it easier to embed some non-opaque information into unique identifiers. @see https://sourceforge.net/apps/trac/bigdata/ticket/560 (Graph API/RDF-GOM) Modified Paths: -------------- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/Alchemist.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLClassSkin.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLOntologySkin.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLPropertySkin.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLSkins.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/BasicSkin.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/GPO.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/LinkSet.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IIDGenerator.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IObjectManager.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/NanoSparqlObjectManager.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectManager.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectMgrModel.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMWebUtil.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestAll.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestGOM.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestOWLSkin.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestOwlGOM.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestRemoteGOM.java branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServlet.java branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataRDFServletContextListener.java branches/BIGDATA_RELEASE_1_2_0/bigdata-sails/src/java/com/bigdata/rdf/sail/webapp/BigdataServlet.java branches/BIGDATA_RELEASE_1_2_0/build.xml Added Paths: ----------- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IDGenerator.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/LocalGOMTestCase.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/TestJavaScriptGOM.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/test/com/bigdata/gom/univ-bench.owl Removed Paths: ------------- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMListener.java branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMServlet.java Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/Alchemist.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/Alchemist.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/Alchemist.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.alchemy; /** Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLClassSkin.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLClassSkin.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLClassSkin.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.alchemy.owl; import java.util.Iterator; @@ -2,4 +25,2 @@ -import org.openrdf.model.vocabulary.OWL; -import org.openrdf.model.vocabulary.RDF; import org.openrdf.model.vocabulary.RDFS; @@ -10,7 +31,6 @@ import com.bigdata.gom.gpo.GPO; import com.bigdata.gom.gpo.IGPO; import com.bigdata.gom.gpo.IGenericSkin; -import com.bigdata.gom.om.IObjectManager; public class OWLClassSkin extends BasicSkin implements IGenericSkin { Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLOntologySkin.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLOntologySkin.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLOntologySkin.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.alchemy.owl; import java.util.Iterator; @@ -4,7 +27,6 @@ import org.openrdf.model.vocabulary.OWL; import org.openrdf.model.vocabulary.RDF; -import org.openrdf.model.vocabulary.RDFS; import com.bigdata.gom.gpo.BasicSkin; import com.bigdata.gom.gpo.GPO; Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLPropertySkin.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLPropertySkin.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLPropertySkin.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.alchemy.owl; import org.openrdf.model.vocabulary.OWL; Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLSkins.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLSkins.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/alchemy/owl/OWLSkins.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,10 +1,28 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.alchemy.owl; -import org.openrdf.model.vocabulary.OWL; - -import com.bigdata.gom.gpo.GPO; -import com.bigdata.gom.gpo.IGPO; -import com.bigdata.gom.om.IObjectManager; import com.bigdata.gom.skin.GenericSkinRegistry; /** Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/BasicSkin.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/BasicSkin.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/BasicSkin.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -10,8 +10,8 @@ /** * The BasicSkin provides standard type wrappers to help with conversions + * * @author Martyn Cutcher - * */ public class BasicSkin implements IGenericSkin { Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/GPO.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/GPO.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/GPO.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -7,17 +7,12 @@ import java.util.Map; import java.util.NoSuchElementException; import java.util.Set; -import java.util.TreeMap; -import java.util.TreeSet; -import java.util.Map.Entry; -import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.openrdf.model.Resource; import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; import org.openrdf.model.impl.URIImpl; import org.openrdf.query.BindingSet; import org.openrdf.repository.RepositoryException; @@ -25,15 +20,7 @@ import com.bigdata.gom.om.IObjectManager; import com.bigdata.gom.om.ObjectMgrModel; import com.bigdata.gom.skin.GenericSkinRegistry; -import com.bigdata.rdf.internal.IV; import com.bigdata.rdf.model.BigdataLiteralImpl; -import com.bigdata.rdf.model.BigdataResource; -import com.bigdata.rdf.model.BigdataStatement; -import com.bigdata.rdf.model.BigdataStatementImpl; -import com.bigdata.rdf.model.BigdataURI; -import com.bigdata.rdf.model.BigdataValue; -import com.bigdata.rdf.model.BigdataValueFactoryImpl; -import com.bigdata.rdf.model.StatementEnum; import com.bigdata.striterator.ICloseableIterator; /** @@ -80,29 +67,45 @@ private static final Logger log = Logger.getLogger(GPO.class); - final ObjectMgrModel m_om; - final Resource m_id; + /** + * The owning {@link IObjectManager}. + */ + private final ObjectMgrModel m_om; - boolean m_materialized = false; + /** + * The identifier for this {@link IGPO}. + */ + private final Resource m_id; - boolean m_clean = true; + private boolean m_materialized = false; - ArrayList<IGenericSkin> m_skins = null; + private boolean m_clean = true; + private GPOEntry m_headEntry = null; + private GPOEntry m_tailEntry = null; + + private ArrayList<IGenericSkin> m_skins = null; + static class LinkValue { - final Value m_value; - LinkValue m_next; + + final Value m_value; - LinkValue(Value value) { - m_value = value; + LinkValue m_next; + + LinkValue(final Value value) { + + m_value = value; + } + } - /** - * The GPOEntry retains the state necessary for providing delta updates to the underlying - * triple data. It supports multi-values against the same property and records values - * removed and added. - */ - static class GPOEntry { + + /** + * The GPOEntry retains the state necessary for providing delta updates to + * the underlying triple data. It supports multi-values against the same + * property and records values removed and added. + */ + static class GPOEntry { final URI m_key; GPOEntry m_next; @@ -269,8 +272,6 @@ return m_values != null || m_addedValues != null; } } - GPOEntry m_headEntry = null; - GPOEntry m_tailEntry = null; GPOEntry establishEntry(final URI key) { final URI fkey = m_om.internKey(key); Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/LinkSet.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/LinkSet.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/gpo/LinkSet.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -8,7 +8,6 @@ import org.openrdf.model.Resource; import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.impl.URIImpl; import org.openrdf.query.BindingSet; import com.bigdata.gom.om.IObjectManager; Added: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IDGenerator.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IDGenerator.java (rev 0) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IDGenerator.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -0,0 +1,100 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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 on Aug 9, 2012 + */ +package com.bigdata.gom.om; + +import java.util.UUID; +import java.util.concurrent.atomic.AtomicInteger; + +import org.openrdf.model.URI; +import org.openrdf.model.ValueFactory; + +/** + * Generator for globally unique URIs. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ +public class IDGenerator implements IIDGenerator { + + private final ValueFactory valueFactory; + + private final String prefix; + + private final AtomicInteger nextId = new AtomicInteger(0); + + /** + * + * @param endpoint + * The SPARQL endpoint. + * @param uuid + * The {@link UUID} for the {@link IObjectManager}. This is used + * to avoid collisions between different {@link IObjectManager}s. + * @param valueFactory + * The {@link ValueFactory} that will be used when new + * {@link URI}s are generated. + */ + public IDGenerator(final String endpoint, final UUID uuid, + final ValueFactory valueFactory) { + + if(endpoint == null) + throw new IllegalArgumentException(); + + if(uuid == null) + throw new IllegalArgumentException(); + + if(valueFactory == null) + throw new IllegalArgumentException(); + + this.valueFactory = valueFactory; + + // Setup the prefix that we will reuse for each new URI. + this.prefix = endpoint + "/gpo/" + uuid + "/"; + + } + + @Override + public URI genId() { + + return valueFactory.createURI(prefix + nextId.incrementAndGet()); + + } + + @Override + public URI genId(final String scope) { + + return valueFactory.createURI(prefix + scope + "/" + + nextId.incrementAndGet()); + + } + + @Override + public void rollback() { + + nextId.set(0); + + } + +} Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IIDGenerator.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IIDGenerator.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IIDGenerator.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,26 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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.gom.om; import org.openrdf.model.URI; @@ -13,12 +36,30 @@ * */ public interface IIDGenerator { - - URI genId(); - /** - * A rollback hook is required - */ + /** + * Generate a globally unique URI. + * + * @return The URI. + */ + URI genId(); + + /** + * Generate a globally unique URI. + * + * @param scope + * The scope will be incorporated into the URI. This is not + * necessary to make the URI globally unique, but it can make it + * easier to embed some non-opaque semantics into a globally + * unique URI. + * + * @return The URI. + */ + URI genId(final String scope); + + /** + * A rollback hook is required + */ void rollback(); } Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IObjectManager.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IObjectManager.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/IObjectManager.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -36,7 +36,6 @@ import org.openrdf.model.Value; import org.openrdf.model.ValueFactory; import org.openrdf.query.BindingSet; -import org.openrdf.repository.RepositoryException; import com.bigdata.gom.gpo.IGPO; import com.bigdata.striterator.ICloseableIterator; @@ -45,13 +44,16 @@ * The object manager is the abstraction for a connection the back end. */ public interface IObjectManager extends INativeTransaction { - - /** - * @return the UUID that identifies this ObjectManager - */ - UUID getID(); /** + * @return the UUID that identifies this ObjectManager + * + * @deprecated Why do we need this? It should be hidden in how we generate + * URIs, not part of the public API. + */ + UUID getID(); + + /** * Return a canonical {@link IGPO} for the {@link Resource} (canonical * within the scope of this object manager) and never <code>null</code>. * @@ -95,6 +97,8 @@ */ boolean isPersistent(); + ValueFactory getValueFactory(); + /** * */ @@ -105,6 +109,8 @@ */ void execute(String updateStr); + ICloseableIterator<Statement> evaluateGraph(String query); + URI internKey(URI key); /** @@ -119,12 +125,14 @@ * Simple save/recall interface that the ObjectManager provides to simplify * other pattern implementations. Internally it uses a NameManager GPO */ + @Deprecated // Just use the URI directly... void save(URI key, Value value); /** * Simple save/recall interface that the ObjectManager provides to simplify * other pattern implementations. Internally it uses a NameManager GPO */ + @Deprecated // Just use the URI directly... Value recall(URI key); IGPO recallAsGPO(URI key); @@ -133,13 +141,12 @@ * Return the list of names that have been used to save references. These * are the properties of the internal NameManager. */ + @Deprecated // Just use URIs directly... Iterator<URI> getNames(); + /** + * Remove all assertions involving the specified object. + */ void remove(IGPO gpo); - ICloseableIterator<Statement> evaluateGraph(String query); - - ValueFactory getValueFactory(); - - void checkValue(Value newValue); } Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/NanoSparqlObjectManager.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/NanoSparqlObjectManager.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/NanoSparqlObjectManager.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,29 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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 on Mar 19, 2012 + */ package com.bigdata.gom.om; import java.util.ArrayList; @@ -2,16 +28,12 @@ import java.util.Iterator; -import java.util.UUID; +import org.apache.log4j.Logger; import org.openrdf.model.Resource; import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; import org.openrdf.query.BindingSet; -import org.openrdf.query.GraphQuery; import org.openrdf.query.GraphQueryResult; import org.openrdf.query.MalformedQueryException; import org.openrdf.query.QueryEvaluationException; -import org.openrdf.query.QueryLanguage; -import org.openrdf.query.TupleQuery; import org.openrdf.query.TupleQueryResult; @@ -21,34 +43,41 @@ import com.bigdata.gom.gpo.GPO; import com.bigdata.gom.gpo.IGPO; -import com.bigdata.rdf.model.BigdataResource; -import com.bigdata.rdf.model.BigdataStatementImpl; -import com.bigdata.rdf.model.BigdataURI; -import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactoryImpl; -import com.bigdata.rdf.model.StatementEnum; import com.bigdata.rdf.sail.webapp.client.IPreparedGraphQuery; import com.bigdata.rdf.sail.webapp.client.IPreparedTupleQuery; -import com.bigdata.rdf.sail.webapp.client.IRemoteRepository; import com.bigdata.rdf.sail.webapp.client.RemoteRepository; import com.bigdata.rdf.sail.webapp.client.RemoteRepository.AddOp; import com.bigdata.rdf.sail.webapp.client.RemoteRepository.RemoveOp; -import com.bigdata.rdf.spo.ISPO; -import com.bigdata.rdf.spo.SPO; import com.bigdata.striterator.CloseableIteratorWrapper; import com.bigdata.striterator.ICloseableIterator; +/** + * Remote {@link IObjectManager} using the <a href= + * "https://sourceforge.net/apps/mediawiki/bigdata/index.php?title=NanoSparqlServer" + * > NanoSparqlServer REST API </a> to communicate with the database. + * + * @author <a href="mailto:mar...@us...">Martyn Cutcher</a> + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ public class NanoSparqlObjectManager extends ObjectMgrModel { - final RemoteRepository m_repo; + + private static final Logger log = Logger + .getLogger(NanoSparqlObjectManager.class); + + private final RemoteRepository m_repo; - public NanoSparqlObjectManager(final UUID uuid, final RemoteRepository repo, final String namespace) { - super(uuid, BigdataValueFactoryImpl.getInstance(namespace)); + public NanoSparqlObjectManager(final RemoteRepository repo, final String namespace) { + super(repo.getSparqlEndPoint(), BigdataValueFactoryImpl + .getInstance(namespace)); + m_repo = repo; } @Override public void close() { + super.close(); // m_repo.close(); } @@ -163,14 +192,14 @@ } @Override - void doCommit() { + protected void doCommit() { // FIXME: The current NanoSparqlServer commits each update. This // needs to change to associate with an IsolatedTransaction with // an additional commit/rollback protocol } @Override - void doRollback() { + protected void doRollback() { // FIXME: see comment above for doCommit() } Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectManager.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectManager.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectManager.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,29 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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 on Mar 19, 2012 + */ package com.bigdata.gom.om; import java.util.Iterator; @@ -2,3 +28,2 @@ import java.util.List; -import java.util.UUID; @@ -9,7 +34,6 @@ import org.openrdf.model.Statement; import org.openrdf.model.URI; import org.openrdf.model.Value; -import org.openrdf.model.ValueFactory; import org.openrdf.query.BindingSet; import org.openrdf.query.GraphQuery; import org.openrdf.query.GraphQueryResult; @@ -35,16 +59,35 @@ import com.bigdata.striterator.CloseableIteratorWrapper; import com.bigdata.striterator.ICloseableIterator; +/** + * An {@link IObjectManager} for use with an embedded database, including JSP + * pages running in the same webapp as the NanoSparqlServer and applications + * that do not expose a public web interface. + * + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ public class ObjectManager extends ObjectMgrModel { - private static final Logger log = Logger.getLogger(IObjectManager.class); + + private static final Logger log = Logger.getLogger(ObjectManager.class); - final BigdataSailRepository m_repo; - BigdataSailRepositoryConnection m_cxn = null; + final private BigdataSailRepository m_repo; + private BigdataSailRepositoryConnection m_cxn; - public ObjectManager(final UUID uuid, final BigdataSailRepository cxn) { - super(uuid, cxn.getValueFactory()); - m_repo = cxn; - } + /** + * + * @param endpoint + * A SPARQL endpoint that may be used to communicate with the + * database. + * @param cxn + * A connection to the database. + */ + public ObjectManager(final String endpoint, final BigdataSailRepository cxn) { + + super(endpoint, cxn.getValueFactory()); + + m_repo = cxn; + + } /** * @return direct repository connection @@ -56,30 +99,18 @@ @Override public void close() { try { - m_repo.shutDown(); + if (m_repo.getSail().isOpen()) + m_repo.shutDown(); } catch (RepositoryException e) { - log.warn("Problem with close", e); + log.error("Problem with close", e); } - m_dict.clear(); + super.close(); } - public BigdataSailRepositoryConnection establishUnisolatedConnection() { - if (m_cxn == null) { - try { - m_cxn = m_repo.getUnisolatedConnection(); - m_cxn.setAutoCommit(false); - } catch (RepositoryException e) { - throw new RuntimeException("Unable to establish unisolated connection", e); - } - } - - return m_cxn; - } - @Override public ICloseableIterator<BindingSet> evaluate(final String query) { try { - final TupleQuery q = establishUnisolatedConnection().prepareTupleQuery(QueryLanguage.SPARQL, query); + final TupleQuery q = getUnisolatedConnection().prepareTupleQuery(QueryLanguage.SPARQL, query); final TupleQueryResult res = q.evaluate(); return new CloseableIteratorWrapper<BindingSet>(new Iterator<BindingSet>() { @@ -120,7 +151,7 @@ public ICloseableIterator<Statement> evaluateGraph(final String query) { try { - final GraphQuery q = establishUnisolatedConnection().prepareGraphQuery(QueryLanguage.SPARQL, query); + final GraphQuery q = getUnisolatedConnection().prepareGraphQuery(QueryLanguage.SPARQL, query); final GraphQueryResult res = q.evaluate(); return new CloseableIteratorWrapper<Statement>(new Iterator<Statement>() { @@ -223,13 +254,13 @@ // experiment with adding using batch syntax if (false) { // m_cxn.getTripleStore().addStatement(id, key, val); - establishUnisolatedConnection().add(id, key, val); + getUnisolatedConnection().add(id, key, val); } else { final ISPO spo = new BigdataStatementImpl((BigdataResource) id, (BigdataURI) key, (BigdataValue) val, null, StatementEnum.Explicit, false); - establishUnisolatedConnection().getTripleStore().addStatements(new ISPO[] {spo}, 1); + getUnisolatedConnection().getTripleStore().addStatements(new ISPO[] {spo}, 1); } } @@ -237,12 +268,25 @@ public void retract(Resource id, URI key, Value val) throws RepositoryException { if (log.isTraceEnabled()) log.trace("Removing statement: " + id.stringValue() + " " + key.stringValue() + " " + val.stringValue()); - establishUnisolatedConnection().remove(id, key, val); + getUnisolatedConnection().remove(id, key, val); } + private BigdataSailRepositoryConnection getUnisolatedConnection() { + if (m_cxn == null) { + try { + m_cxn = m_repo.getUnisolatedConnection(); + m_cxn.setAutoCommit(false); + } catch (RepositoryException e) { + throw new RuntimeException("Unable to establish unisolated connection", e); + } + } + + return m_cxn; + } + @Override - void doCommit() { - establishUnisolatedConnection().getTripleStore().commit(); + protected void doCommit() { + getUnisolatedConnection().getTripleStore().commit(); try { m_cxn.close(); } catch (RepositoryException e) { @@ -252,13 +296,13 @@ } } - /** - * doRollback handles the "partial" updates written to maintain referential integrity and also - * incremental updates of "dirty" objects. - */ - @Override - void doRollback() { - establishUnisolatedConnection().getTripleStore().abort(); + /** + * doRollback handles the "partial" updates written to maintain referential + * integrity and also incremental updates of "dirty" objects. + */ + @Override + protected void doRollback() { + getUnisolatedConnection().getTripleStore().abort(); try { m_cxn.close(); } catch (RepositoryException e) { @@ -268,30 +312,27 @@ } } - @Override - public void remove(IGPO gpo) { - try { - // Removes all references - establishUnisolatedConnection().remove(gpo.getId(), null, null); - establishUnisolatedConnection().remove((Resource) null, null, gpo.getId()); - } catch (RepositoryException e) { - throw new RuntimeException("Unable to remove object", e); - } - } + @Override + public void remove(final IGPO gpo) { + try { + // Removes all references + final BigdataSailRepositoryConnection cxn = getUnisolatedConnection(); + cxn.remove(gpo.getId(), null, null); + cxn.remove((Resource) null, null, gpo.getId()); + // TODO This is not marking the IGPO as removed? + } catch (RepositoryException e) { + throw new RuntimeException("Unable to remove object", e); + } + } @Override - public ValueFactory getValueFactory() { - return m_valueFactory; - } - - @Override void flushTerms() { if (m_terms.size() > 0) { final BigdataValue[] terms = new BigdataValue[m_terms.size()]; m_terms.toArray(terms); m_terms.clear(); final long start = System.currentTimeMillis(); - establishUnisolatedConnection().getTripleStore().addTerms(terms); + getUnisolatedConnection().getTripleStore().addTerms(terms); if (log.isTraceEnabled()) log.trace("Added " + terms.length + " terms: " + (System.currentTimeMillis()-start) + "ms"); } @@ -303,31 +344,45 @@ if (m_removes.size() > 0) { final ISPO[] spos = statementsToSPO(m_removes); m_removes.clear(); - establishUnisolatedConnection().getTripleStore().removeStatements(spos, spos.length); + getUnisolatedConnection().getTripleStore().removeStatements(spos, spos.length); + } + + // handle batch inserts + if (m_inserts.size() > 0) { + + final ISPO[] spos = statementsToSPO(m_inserts); + + m_inserts.clear(); + + getUnisolatedConnection().getTripleStore().addStatements( + spos, spos.length); + } - - // handle batch inserts - if (m_inserts.size() > 0) { - final ISPO[] spos = statementsToSPO(m_inserts); - m_inserts.clear(); - establishUnisolatedConnection().getTripleStore().addStatements(spos, spos.length); - - } + } - SPO[] statementsToSPO(List<Statement> statements) { - final int size = statements.size(); - SPO[] ret = new SPO[size]; - - for (int i = 0; i < size; i++) { - final BigdataStatement s = (BigdataStatement) statements.get(i); - ret[i] = new SPO(s.getSubject().getIV(), s.getPredicate().getIV(), s.getObject().getIV(), StatementEnum.Explicit); - if (ret[i].s == null || ret[i].p == null || ret[i].o == null) { - throw new IllegalStateException("Values must be bound"); - } - } - - return ret; - } + SPO[] statementsToSPO(final List<Statement> statements) { + final int size = statements.size(); + final SPO[] ret = new SPO[size]; + + for (int i = 0; i < size; i++) { + + final BigdataStatement s = (BigdataStatement) statements.get(i); + + ret[i] = new SPO(s.getSubject().getIV(), s.getPredicate().getIV(), + s.getObject().getIV(), StatementEnum.Explicit); + + if (ret[i].s == null || ret[i].p == null || ret[i].o == null) { + + throw new IllegalStateException("Values must be bound"); + + } + + } + + return ret; + + } + } Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectMgrModel.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectMgrModel.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/om/ObjectMgrModel.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,3 +1,29 @@ +/** + +Copyright (C) SYSTAP, LLC 2006-2012. 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 on Mar 19, 2012 + */ package com.bigdata.gom.om; import java.util.ArrayList; @@ -2,5 +28,8 @@ import java.util.Iterator; +import java.util.List; import java.util.UUID; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantLock; @@ -12,98 +41,167 @@ import org.openrdf.model.URI; import org.openrdf.model.Value; import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.URIImpl; import org.openrdf.repository.RepositoryException; -import com.bigdata.gom.gpo.BasicSkin; import com.bigdata.gom.gpo.GPO; import com.bigdata.gom.gpo.IGPO; -import com.bigdata.rdf.internal.IV; -import com.bigdata.rdf.model.BigdataResource; import com.bigdata.rdf.model.BigdataURI; import com.bigdata.rdf.model.BigdataValue; import com.bigdata.rdf.model.BigdataValueFactory; -import com.bigdata.rdf.model.StatementEnum; -import com.bigdata.rdf.sail.webapp.client.RemoteRepository.AddOp; -import com.bigdata.rdf.spo.SPO; +/** + * Base class for {@link IObjectManager} implementations. This class handles + * {@link IObjectManager} protocol for maintaining an transaction edit list. + * Concrete implementations need to provide for communication with the database + * (either remote or embedded) and the DESCRIBE (aka Object) cache. + * + * @author <a href="mailto:mar...@us...">Martyn + * Cutcher</a> + * @author <a href="mailto:tho...@us...">Bryan Thompson</a> + */ public abstract class ObjectMgrModel implements IObjectManager { - protected static final Logger log = Logger.getLogger(IObjectManager.class); + private static final Logger log = Logger.getLogger(ObjectMgrModel.class); - final WeakHashMap<Resource, IGPO> m_dict = new WeakHashMap<Resource, IGPO>(); + /** + * The {@link UUID} for this object manager instance. + */ + private final UUID m_uuid; + + // TODO Should this be a BigdataValueFactory? + protected final ValueFactory m_valueFactory; + + /** Object Creation and ID Management patterns. */ + private final IIDGenerator m_idGenerator; + + /** + * Local cache. + */ + private final WeakHashMap<Resource, IGPO> m_dict = new WeakHashMap<Resource, IGPO>(); - final ConcurrentHashMap<URI, URI> m_internedKeys = new ConcurrentHashMap<URI, URI>(); - - final ValueFactory m_valueFactory; - - final UUID m_uuid; - + /** + * TODO The {@link BigdataValueFactory} handles this with + * {@link BigdataValueFactory#asValue(Value)}. Use that instead? + */ + private final ConcurrentHashMap<URI, URI> m_internedKeys = new ConcurrentHashMap<URI, URI>(); + + /* + * We need to maintain a dirty list in order to pin object references that + * are dirty. On commit, we need to send the retracts and the asserts in a + * single operation, which is why these things are tracked on separate + * lists. + * + * FIXME The OM should not be tracking the terms. The StatementBuffer or + * Sail will handle this. + */ // new terms cache to enable batch term registration on update/flush - final ArrayList<BigdataValue> m_terms = new ArrayList<BigdataValue>(); - final ArrayList<Statement> m_inserts = new ArrayList<Statement>(); - final ArrayList<Statement> m_removes = new ArrayList<Statement>(); + protected final List<BigdataValue> m_terms = new ArrayList<BigdataValue>(); + protected final List<Statement> m_inserts = new ArrayList<Statement>(); + protected final List<Statement> m_removes = new ArrayList<Statement>(); - final URI s_nmeMgr; + private final ArrayList<GPO> m_dirtyGPOs = new ArrayList<GPO>(); + + private final int m_maxDirtyListSize = 1000; // 5000; // FIXME: Init from property file - // Object Creation and ID Management patterns for default idGenerator - IIDGenerator m_idGenerator = null; + private final URI s_nmeMgr; - int m_transactionCounter = 0; + /** + * A lock for things which need to be serialized, initially just the native + * transaction stuff. Avoid using "synchronized(this)" or the synchronized + * keyword as that forces everything to contend for the same lock. If you + * can use different locks for different types of things then you have + * better concurrency (but, of course, only as appropriate). + */ + private final Lock lock = new ReentrantLock(); - ObjectMgrModel(final UUID uuid, final ValueFactory valueFactory) { + /** + * The native transaction counter. + */ + private int m_transactionCounter = 0; + + /** + * + * @param endpoint + * The SPARQL endpoint that can be used to communicate with the + * database. + * @param valueFactory + * The value factory. + */ + public ObjectMgrModel( + final String endpoint, + final ValueFactory valueFactory) { + m_valueFactory = valueFactory; - m_uuid = uuid; + m_uuid = UUID.randomUUID(); + + m_idGenerator = new IDGenerator(endpoint, m_uuid, m_valueFactory); + + /* + * FIXME UUIG COINING. Plus this needs to be global if we have a + * "name manager" object. Frankly, I do not see any reason to have + * "named roots" in RDF GOM. Any URI can be a named root - you just need + * to use the URI! + */ s_nmeMgr = m_valueFactory.createURI("gpo:nmeMgr/"+m_uuid); - addNewTerm((BigdataValue) s_nmeMgr); + + addNewTerm((BigdataValue) s_nmeMgr); + } public IGPO getDefaultNameMgr() { - return getGPO(s_nmeMgr); + + return getGPO(s_nmeMgr); + } - public void setIDGenerator(final IIDGenerator idgenerator) { - m_idGenerator = idgenerator; - } - public UUID getID() { - return m_uuid; + + return m_uuid; + } - class DefaultIDGenerator implements IIDGenerator { - final URI s_idMgr; - final URI s_idMgrNextId; - BasicSkin m_idMgr; - - DefaultIDGenerator() { - s_idMgr = m_valueFactory.createURI("gpo:idMgr/"+m_uuid); - s_idMgrNextId = m_valueFactory.createURI("gpo:idMgr/"+m_uuid + "#nextId"); - - m_idMgr = new BasicSkin(getGPO(s_idMgr)); + @Override + final public ValueFactory getValueFactory() { - addNewTerm((BigdataValue) s_idMgr); - addNewTerm((BigdataValue) s_idMgrNextId ); - } - - /** - * Default IIDGenerator implementation for ObjectManagers. - */ - public URI genId() { - if (m_idMgr == null) { - m_idMgr = new BasicSkin(getGPO(s_idMgr)); - } - - int nxtId = m_idMgr.getIntValue(s_idMgrNextId)+1; - m_idMgr.setValue(s_idMgrNextId, nxtId); - - return getValueFactory().createURI("gpo:" + m_uuid + "/" + nxtId); - } + return m_valueFactory; - public void rollback() { - m_idMgr = null; // force reload to committed state on next access - } - } + } + +// class DefaultIDGenerator implements IIDGenerator { +// final URI s_idMgr; +// final URI s_idMgrNextId; +// BasicSkin m_idMgr; +// +// DefaultIDGenerator() { +// s_idMgr = m_valueFactory.createURI("gpo:idMgr/"+m_uuid); +// s_idMgrNextId = m_valueFactory.createURI("gpo:idMgr/"+m_uuid + "#nextId"); +// +// m_idMgr = new BasicSkin(getGPO(s_idMgr)); +// +// addNewTerm((BigdataValue) s_idMgr); +// addNewTerm((BigdataValue) s_idMgrNextId ); +// } +// +// /** +// * Default IIDGenerator implementation for ObjectManagers. +// */ +// public URI genId() { +// if (m_idMgr == null) { +// m_idMgr = new BasicSkin(getGPO(s_idMgr)); +// } +// +// final int nxtId = m_idMgr.getIntValue(s_idMgrNextId) + 1; +// +// m_idMgr.setValue(s_idMgrNextId, nxtId); +// +// return getValueFactory().createURI("gpo:" + m_uuid + "/" + nxtId); +// } +// +// public void rollback() { +// m_idMgr = null; // force reload to committed state on next access +// } +// } @Override public URI internKey(final URI key) { @@ -118,10 +216,6 @@ return uri; } - final ArrayList<GPO> m_dirtyGPOs = new ArrayList<GPO>(); - - final int m_maxDirtyListSize = 1000; // 5000; // FIXME: Init from property file - /** * GPOs are added to the dirty list when initially modified. * @@ -143,7 +237,7 @@ private void flushDirtyObjects() { // prepare values - Iterator<GPO> newValues = m_dirtyGPOs.iterator(); + final Iterator<GPO> newValues = m_dirtyGPOs.iterator(); while (newValues.hasNext()) { final GPO gpo = newValues.next(); gpo.prepareBatchTerms(); @@ -156,7 +250,7 @@ final long count = m_dirtyGPOs.size(); if (true) { - Iterator<GPO> updates = m_dirtyGPOs.iterator(); + final Iterator<GPO> updates = m_dirtyGPOs.iterator(); while (updates.hasNext()) { updates.next().prepareBatchUpdate(); } @@ -164,7 +258,7 @@ flushStatements(); } else { // update dirty objects - is it worth while batching SPO[]? - Iterator<GPO> updates = m_dirtyGPOs.iterator(); + final Iterator<GPO> updates = m_dirtyGPOs.iterator(); while (updates.hasNext()) { try { updates.next().update(); @@ -174,8 +268,9 @@ } } m_dirtyGPOs.clear(); - if (log.isTraceEnabled()) - log.trace("Flush took " + (System.currentTimeMillis()-start) + "ms for " + count + " objects"); + if (log.isTraceEnabled()) + log.trace("Flush took " + (System.currentTimeMillis() - start) + + "ms for " + count + " objects"); } abstract void flushStatements(); @@ -193,53 +288,74 @@ } @Override - public synchronized int beginNativeTransaction() { - return m_transactionCounter++; - } + public int beginNativeTransaction() { + lock.lock(); + try { + return m_transactionCounter++; + } finally { + lock.unlock(); + } + } - @Override - public int commitNativeTransaction(final int expectedCounter) { - final int ret = --m_transactionCounter; - if (ret != expectedCounter) { - throw new IllegalArgumentException("Unexpected transaction counter"); - } - - if (ret == 0) { - flushDirtyObjects(); - } - - doCommit(); - - return ret; + @Override + public int commitNativeTransaction(final int expectedCounter) { + lock.lock(); + try { + final int ret = --m_transactionCounter; + if (ret != expectedCounter) { + throw new IllegalArgumentException( + "Unexpected transaction counter"); + } + + if (ret == 0) { + flushDirtyObjects(); + } + + doCommit(); + + return ret; + } finally { + lock.unlock(); + } } - abstract void doCommit(); + /** + * Hook for extended commit processing. + */ + protected abstract void doCommit(); - @Override - public int getNativeTransactionCounter() { - return m_transactionCounter; + @Override + public int getNativeTransactionCounter() { + /* + * Note: You must obtain the lock for visibility of the current value + * unless the transaction counter is either volatile or an + * AtomicInteger. + */ + lock.lock(); + try { + return m_transactionCounter; + } finally { + lock.unlock(); + } } @Override - public void rollbackNativeTransaction() { - // just clear the cache for now - m_dict.clear(); - m_dirtyGPOs.clear(); - m_transactionCounter = 0; - if (m_idGenerator != null) { - m_idGenerator.rollback(); - } - - doRollback(); + public void rollbackNativeTransaction() { + clearCache(); + m_transactionCounter = 0; + if (m_idGenerator != null) { + m_idGenerator.rollback(); + } + doRollback(); } - abstract void doRollback(); + /** + * Hook for extended rollback processing. + */ + abstract protected void doRollback(); @Override public IGPO createGPO() { - if (m_idGenerator == null) { - m_idGenerator = new DefaultIDGenerator(); - } final Resource uri = m_idGenerator.genId(); addNewTerm((BigdataValue) uri); @@ -249,13 +365,19 @@ return ret; } - + + @Deprecated // Let the BigdataSail handle this. protected void addNewTerm(final BigdataValue uri) { - if (uri.isRealIV()) - throw new IllegalArgumentException("IV already available: " + uri.stringValue()); - System.out.println("Adding term: " + uri); - m_terms.add(uri); + if (uri.isRealIV()) + throw new IllegalArgumentException("IV already available: " + + uri.stringValue()); + + if (log.isDebugEnabled()) + log.debug("Adding term: " + uri); + + m_terms.add(uri); + } @@ -263,6 +385,7 @@ * Simple save/recall interface that the ObjectManager provides to simplify * other pattern implementations. Internally it uses a NameManager GPO */ + @Deprecated // no need for explicit save/recall. public void save(final URI key, Value value) { getGPO(s_nmeMgr).setValue(key, value); } @@ -271,13 +394,16 @@ * Simple save/recall interface that the ObjectManager provides to simplify * other pattern implementations. Internally it uses a NameManager GPO */ + @Deprecated // no need for explicit recall. public Value recall(final URI key) { return getGPO(s_nmeMgr).getValue(key); } + @Deprecated // no need for explicit recall. public IGPO recallAsGPO(final URI key) { - Value val = recall(key); + final Value val = recall(key); + if (val instanceof Resource) { return getGPO((Resource) val); } else { @@ -290,11 +416,13 @@ * are the properties of the internal NameManager. */ public Iterator<URI> getNames() { - final GPO nmgr = (GPO) getGPO(s_nmeMgr); + + final GPO nmgr = (GPO) getGPO(s_nmeMgr); return nmgr.getPropertyURIs(); } + @Deprecated // The OM should not be worrying about IVs like this. public void checkValue(Value newValue) { final BigdataValue v = (BigdataValue) newValue; if (!v.isRealIV()) { @@ -302,26 +430,32 @@ } } + @Override + public void close() { + + clearCache(); + + } + public void clearCache() { m_dict.clear(); m_dirtyGPOs.clear(); } - abstract public void insert(final Resource id, final URI key, final Value val) throws RepositoryException; + abstract public void insert(final Resource id, final URI key, + final Value val) throws RepositoryException; - abstract public void retract(final Resource id, final URI key, final Value val) throws RepositoryException; + abstract public void retract(final Resource id, final URI key, + final Value val) throws RepositoryException; - public void insertBatch(final Resource m_id, final URI bigdataURI, final Value v) { - m_inserts.add(m_valueFactory.createStatement(m_id, bigdataURI, v)); - } + public void insertBatch(final Resource m_id, final URI bigdataURI, + final Value v) { + m_inserts.add(m_valueFactory.createStatement(m_id, bigdataURI, v)); + } - public void removeBatch(final Resource m_id, final URI bigdataURI, final Value v) { - m_removes.add(m_valueFactory.createStatement(m_id, bigdataURI, v)); - } + public void removeBatch(final Resource m_id, final URI bigdataURI, + final Value v) { + m_removes.add(m_valueFactory.createStatement(m_id, bigdataURI, v)); + } - @Override - public ValueFactory getValueFactory() { - return m_valueFactory; - } - } Deleted: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMListener.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMListener.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMListener.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,71 +0,0 @@ -package com.bigdata.gom.web; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.util.Properties; -import java.util.UUID; - -import javax.servlet.ServletContext; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; - -import org.openrdf.repository.RepositoryException; -import org.openrdf.sail.SailException; - -import com.bigdata.gom.om.IObjectManager; -import com.bigdata.gom.om.ObjectManager; -import com.bigdata.journal.ITx; -import com.bigdata.rdf.sail.BigdataSail; -import com.bigdata.rdf.sail.BigdataSailRepository; -import com.bigdata.rdf.sail.BigdataSailRepositoryConnection; -import com.bigdata.rdf.sail.webapp.BigdataRDFServletContextListener; -import com.bigdata.rdf.sail.webapp.ConfigParams; -import com.bigdata.rdf.store.AbstractTripleStore; - -/** - * Extends the BigdataRDFServletContextListener to add a local ObjectManager - * initialization. - * - * @author Martyn Cutcher - * - */ -public class GOMListener extends BigdataRDFServletContextListener { - @Override - public void contextDestroyed(ServletContextEvent ev) { - super.contextDestroyed(ev); - } - - @Override - public void contextInitialized(ServletContextEvent ev) { - super.contextInitialized(ev); - - final ServletContext context = ev.getServletContext(); - - final UUID uuid = UUID.fromString(context.getInitParameter("om-uuid")); - - final String namespace = getBigdataRDFContext().getConfig().namespace; - try { - final AbstractTripleStore tripleStore = (AbstractTripleStore) getBigdataRDFContext().getIndexManager() - .getResourceLocator().locate(namespace, ITx.UNISOLATED); - - if (tripleStore == null) { - throw new RuntimeException("Not found: namespace=" + namespace); - } - - // Wrap with SAIL. - final BigdataSail sail = new BigdataSail(tripleStore); - - final BigdataSailRepository repo = new BigdataSailRepository(sail); - - repo.initialize(); - - final ObjectManager om = new ObjectManager(uuid, repo); - context.setAttribute(ObjectManager.class.getName(), om); - } catch (RepositoryException e) { - throw new RuntimeException(e); - } - } - -} Deleted: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMServlet.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMServlet.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMServlet.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,7 +0,0 @@ -package com.bigdata.gom.web; - -import com.bigdata.rdf.sail.webapp.BigdataServlet; - -public class GOMServlet extends BigdataServlet { - -} Modified: branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMWebUtil.java =================================================================== --- branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMWebUtil.java 2012-08-09 11:56:37 UTC (rev 6427) +++ branches/BIGDATA_RELEASE_1_2_0/bigdata-gom/src/java/com/bigdata/gom/web/GOMWebUtil.java 2012-08-09 15:24:19 UTC (rev 6428) @@ -1,28 +1,119 @@ package com.bigdata.gom.web; +import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; +import org.openrdf.reposit... [truncated message content] |