http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/fileinput/RdfFileInputToolTest.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/fileinput/RdfFileInputToolTest.java b/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/fileinput/RdfFileInputToolTest.java deleted file mode 100644 index 02b8357..0000000 --- a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/fileinput/RdfFileInputToolTest.java +++ /dev/null @@ -1,146 +0,0 @@ -package mvm.rya.accumulo.mr.fileinput; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - - -import java.util.Iterator; -import java.util.Map; - -import junit.framework.TestCase; -import mvm.rya.accumulo.AccumuloRdfConfiguration; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.RdfCloudTripleStoreConstants.TABLE_LAYOUT; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.resolver.RyaContext; -import mvm.rya.api.resolver.RyaTripleContext; -import mvm.rya.api.resolver.triple.TripleRow; - -import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.client.Connector; -import org.apache.accumulo.core.client.Scanner; -import org.apache.accumulo.core.client.admin.SecurityOperations; -import org.apache.accumulo.core.client.mock.MockInstance; -import org.apache.accumulo.core.data.Key; -import org.apache.accumulo.core.data.Range; -import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.security.Authorizations; -import org.apache.accumulo.core.security.TablePermission; -import org.apache.hadoop.io.Text; -import org.openrdf.model.ValueFactory; -import org.openrdf.model.impl.ValueFactoryImpl; -import org.openrdf.rio.RDFFormat; - -/** - * Created by IntelliJ IDEA. - * Date: 4/25/12 - * Time: 10:51 AM - * To change this template use File | Settings | File Templates. - */ -public class RdfFileInputToolTest extends TestCase { - - private String user = "user"; - private String pwd = "pwd"; - private String instance = "myinstance"; - private String tablePrefix = "t_"; - private Authorizations auths = Constants.NO_AUTHS; - private Connector connector; - - @Override - public void setUp() throws Exception { - super.setUp(); - connector = new MockInstance(instance).getConnector(user, pwd.getBytes()); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX); - SecurityOperations secOps = connector.securityOperations(); - secOps.createUser(user, pwd.getBytes(), auths); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, TablePermission.WRITE); - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX); - } - - public void testNTriplesInput() throws Exception { - RdfFileInputTool.main(new String[]{ - "-Dac.mock=true", - "-Dac.instance=" + instance, - "-Dac.username=" + user, - "-Dac.pwd=" + pwd, - "-Drdf.tablePrefix=" + tablePrefix, - "-Drdf.format=" + RDFFormat.NTRIPLES.getName(), - "src/test/resources/test.ntriples", - }); - - Scanner scanner = connector.createScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, auths); - scanner.setRange(new Range()); - Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator(); - ValueFactory vf = new ValueFactoryImpl(); - assertTrue(iterator.hasNext()); - RyaStatement rs = new RyaStatement(new RyaURI("urn:lubm:rdfts#GraduateStudent01"), - new RyaURI("urn:lubm:rdfts#hasFriend"), - new RyaURI("urn:lubm:rdfts#GraduateStudent02")); - assertEquals(new Text(RyaTripleContext.getInstance(new AccumuloRdfConfiguration()).serializeTriple(rs).get(TABLE_LAYOUT.SPO).getRow()), iterator.next().getKey().getRow()); - } - - public void testInputContext() throws Exception { - RdfFileInputTool.main(new String[]{ - "-Dac.mock=true", - "-Dac.instance=" + instance, - "-Dac.username=" + user, - "-Dac.pwd=" + pwd, - "-Drdf.tablePrefix=" + tablePrefix, - "-Drdf.format=" + RDFFormat.TRIG.getName(), - "src/test/resources/namedgraphs.trig", - }); - - Scanner scanner = connector.createScanner(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX, auths); - scanner.setRange(new Range()); - Iterator<Map.Entry<Key, Value>> iterator = scanner.iterator(); - ValueFactory vf = new ValueFactoryImpl(); - assertTrue(iterator.hasNext()); - RyaStatement rs = new RyaStatement(new RyaURI("http://www.example.org/exampleDocument#Monica"), - new RyaURI("http://www.example.org/vocabulary#name"), - new RyaType("Monica Murphy"), - new RyaURI("http://www.example.org/exampleDocument#G1")); - Key key = iterator.next().getKey(); - - TripleRow tripleRow = RyaTripleContext.getInstance(new AccumuloRdfConfiguration()).serializeTriple(rs).get(TABLE_LAYOUT.SPO); - assertEquals(new Text(tripleRow.getRow()), key.getRow()); - assertEquals(new Text(tripleRow.getColumnFamily()), key.getColumnFamily()); - } - -}
http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/Upgrade322ToolTest.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/Upgrade322ToolTest.java b/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/Upgrade322ToolTest.java deleted file mode 100644 index 5ac2d74..0000000 --- a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/Upgrade322ToolTest.java +++ /dev/null @@ -1,319 +0,0 @@ -package mvm.rya.accumulo.mr.upgrade; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - - -import junit.framework.TestCase; -import mvm.rya.accumulo.AccumuloRdfConfiguration; -import mvm.rya.accumulo.AccumuloRyaDAO; -import mvm.rya.accumulo.query.AccumuloRyaQueryEngine; -import mvm.rya.api.RdfCloudTripleStoreConstants; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.query.RyaQuery; -import org.apache.accumulo.core.Constants; -import org.apache.accumulo.core.client.*; -import org.apache.accumulo.core.client.admin.SecurityOperations; -import org.apache.accumulo.core.client.mock.MockInstance; -import org.apache.accumulo.core.data.Key; -import org.apache.accumulo.core.data.Mutation; -import org.apache.accumulo.core.data.Range; -import org.apache.accumulo.core.data.Value; -import org.apache.accumulo.core.security.Authorizations; -import org.apache.accumulo.core.security.TablePermission; -import org.calrissian.mango.collect.CloseableIterable; -import org.openrdf.model.vocabulary.XMLSchema; - -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; - -/** - * Created by IntelliJ IDEA. - * Date: 4/25/12 - * Time: 10:51 AM - * To change this template use File | Settings | File Templates. - */ -public class Upgrade322ToolTest extends TestCase { - - private String user = "user"; - private String pwd = "pwd"; - private String instance = "myinstance"; - private String tablePrefix = "t_"; - private Authorizations auths = Constants.NO_AUTHS; - private Connector connector; - - @Override - public void setUp() throws Exception { - super.setUp(); - - final String spoTable = tablePrefix + - RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX; - final String poTable = tablePrefix + - RdfCloudTripleStoreConstants.TBL_PO_SUFFIX; - final String ospTable = tablePrefix + - RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX; - - connector = new MockInstance(instance).getConnector(user, pwd.getBytes()); - - connector.tableOperations().create(spoTable); - connector.tableOperations().create(poTable); - connector.tableOperations().create(ospTable); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX); - connector.tableOperations().create(tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX); - SecurityOperations secOps = connector.securityOperations(); - secOps.createUser(user, pwd.getBytes(), auths); - secOps.grantTablePermission(user, spoTable, TablePermission.READ); - secOps.grantTablePermission(user, poTable, TablePermission.READ); - secOps.grantTablePermission(user, ospTable, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, TablePermission.READ); - secOps.grantTablePermission(user, tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX, TablePermission.WRITE); - - //load data - final BatchWriter ospWriter = connector - .createBatchWriter(ospTable, new BatchWriterConfig()); - ospWriter.addMutation(getMutation("00000000000000000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0000http://here/2010/tracked-data-provenance/ns#longLit\u0001\u0004")); - ospWriter.addMutation(getMutation("00000000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#intLit\u0001\u0005")); - ospWriter.addMutation(getMutation("00000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#byteLit\u0001\t")); - ospWriter.addMutation(getMutation("00001 1.0\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#doubleLit\u0001\u0006")); - ospWriter.addMutation(getMutation("10\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0000http" + - "://here/2010/tracked-data-provenance/ns#shortLit\u0001http://www.w3" + - ".org/2001/XMLSchema#short\u0001\b")); - ospWriter.addMutation(getMutation("10.0\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#floatLit\u0001http" + - "://www.w3.org/2001/XMLSchema#float\u0001\b")); - ospWriter.addMutation(getMutation("3.0.0\u0000urn:mvm.rya/2012/05#rts\u0000urn:mvm" + - ".rya/2012/05#version\u0001\u0003")); - ospWriter.addMutation(getMutation("9223370726404375807\u0000http://here/2010/tracked-data-provenance/ns" + - "#uuid10\u0000http://here/2010/tracked-data-provenance/ns#dateLit" + - "\u0001\u0007")); - ospWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#Created\u0000http://here" + - "/2010/tracked-data-provenance/ns#uuid10\u0000http://www.w3" + - ".org/1999/02/22-rdf-syntax-ns#type\u0001\u0002")); - ospWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#objectuuid1\u0000http" + - "://here/2010/tracked-data-provenance/ns#uuid10\u0000http://here/2010" + - "/tracked-data-provenance/ns#uriLit\u0001\u0002")); - ospWriter.addMutation(getMutation("stringLit\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#stringLit\u0001" + - "\u0003")); - ospWriter.addMutation(getMutation("true\u0000http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#booleanLit\u0001\n")); - ospWriter.flush(); - ospWriter.close(); - - final BatchWriter spoWriter = connector - .createBatchWriter(spoTable, new BatchWriterConfig()); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10\u0000http://here/2010/tracked-data-provenance/ns#longLit\u000000000000000000000010\u0001\u0004")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#intLit\u000000000000010\u0001\u0005")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#byteLit\u000000000010\u0001\t")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#doubleLit\u000000001 1.0\u0001\u0006")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10\u0000http" + - "://here/2010/tracked-data-provenance/ns#shortLit\u000010\u0001http://www.w3" + - ".org/2001/XMLSchema#short\u0001\b")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#floatLit\u0001http" + - "://www.w3.org/2001/XMLSchema#float\u000010.0\u0001\b")); - spoWriter.addMutation(getMutation("urn:mvm.rya/2012/05#rts\u0000urn:mvm" + - ".rya/2012/05#version\u00003.0.0\u0001\u0003")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns" + - "#uuid10\u0000http://here/2010/tracked-data-provenance/ns#dateLit" + - "\u00009223370726404375807\u0001\u0007")); - spoWriter.addMutation(getMutation("http://here" + - "/2010/tracked-data-provenance/ns#uuid10\u0000http://www.w3" + - ".org/1999/02/22-rdf-syntax-ns#type\u0000http://here/2010/tracked-data-provenance/ns#Created\u0001\u0002")); - spoWriter.addMutation(getMutation("http" + - "://here/2010/tracked-data-provenance/ns#uuid10\u0000http://here/2010" + - "/tracked-data-provenance/ns#uriLit\u0000http://here/2010/tracked-data-provenance/ns#objectuuid1\u0001\u0002")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#stringLit\u0000stringLit\u0001" + - "\u0003")); - spoWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#uuid10" + - "\u0000http://here/2010/tracked-data-provenance/ns#booleanLit\u0000true\u0001\n")); - spoWriter.flush(); - spoWriter.close(); - - final BatchWriter poWriter = connector - .createBatchWriter(poTable, new BatchWriterConfig()); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#longLit\u000000000000000000000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0004")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#intLit\u000000000000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0005")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#byteLit\u000000000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\t")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#doubleLit\u000000001 1.0\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0006")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#shortLit\u000010\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001http://www.w3" + - ".org/2001/XMLSchema#short\u0001\b")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#floatLit\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001http" + - "://www.w3.org/2001/XMLSchema#float\u000010.0\u0001\b")); - poWriter.addMutation(getMutation("urn:mvm" + - ".rya/2012/05#version\u00003.0.0\u0000urn:mvm.rya/2012/05#rts\u0001\u0003")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#dateLit" + - "\u00009223370726404375807\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0007")); - poWriter.addMutation(getMutation("http://www.w3" + - ".org/1999/02/22-rdf-syntax-ns#type\u0000http://here/2010/tracked-data-provenance/ns#Created\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0002")); - poWriter.addMutation(getMutation("http://here/2010" + - "/tracked-data-provenance/ns#uriLit\u0000http://here/2010/tracked-data-provenance/ns#objectuuid1\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\u0002")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#stringLit\u0000stringLit\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001" + - "\u0003")); - poWriter.addMutation(getMutation("http://here/2010/tracked-data-provenance/ns#booleanLit\u0000true\u0000http://here/2010/tracked-data-provenance/ns#uuid10\u0001\n")); - poWriter.flush(); - poWriter.close(); - } - - public Mutation getMutation(String row) { - final Mutation mutation = new Mutation(row); - mutation.put("", "", ""); - return mutation; - } - - @Override - public void tearDown() throws Exception { - super.tearDown(); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_SPO_SUFFIX); - connector.tableOperations().delete( - tablePrefix + RdfCloudTripleStoreConstants.TBL_PO_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_OSP_SUFFIX); - connector.tableOperations().delete(tablePrefix + RdfCloudTripleStoreConstants.TBL_NS_SUFFIX); - connector.tableOperations().delete( - tablePrefix + RdfCloudTripleStoreConstants.TBL_EVAL_SUFFIX); - } - - public void testUpgrade() throws Exception { - Upgrade322Tool.main(new String[]{ - "-Dac.mock=true", - "-Dac.instance=" + instance, - "-Dac.username=" + user, - "-Dac.pwd=" + pwd, - "-Drdf.tablePrefix=" + tablePrefix, - }); - - final AccumuloRdfConfiguration configuration = new AccumuloRdfConfiguration(); - configuration.setTablePrefix(tablePrefix); - final AccumuloRyaDAO ryaDAO = new AccumuloRyaDAO(); - ryaDAO.setConnector(connector); - ryaDAO.setConf(configuration); - ryaDAO.init(); - - final AccumuloRyaQueryEngine queryEngine = ryaDAO.getQueryEngine(); - - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#booleanLit"), - new RyaType(XMLSchema.BOOLEAN, "true")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#longLit"), - new RyaType(XMLSchema.LONG, "10")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#intLit"), - new RyaType(XMLSchema.INTEGER, "10")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#byteLit"), - new RyaType(XMLSchema.BYTE, "10")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#doubleLit"), - new RyaType(XMLSchema.DOUBLE, "10.0")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#dateLit"), - new RyaType(XMLSchema.DATETIME, "2011-07-12T06:00:00.000Z")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#stringLit"), - new RyaType("stringLit")), queryEngine); - verify(new RyaStatement( - new RyaURI("http://here/2010/tracked-data-provenance/ns#uuid10"), - new RyaURI("http://here/2010/tracked-data-provenance/ns#uriLit"), - new RyaURI("http://here/2010/tracked-data-provenance/ns" + - "#objectuuid1")), queryEngine); - verify(new RyaStatement( - new RyaURI("urn:mvm.rya/2012/05#rts"), - new RyaURI("urn:mvm.rya/2012/05#version"), - new RyaType("3.0.0")), queryEngine); - } - - private void verify(RyaStatement ryaStatement, AccumuloRyaQueryEngine queryEngine) - throws RyaDAOException, IOException { - - //check osp - CloseableIterable<RyaStatement> statements = - queryEngine.query(RyaQuery.builder(new RyaStatement(null, null, ryaStatement.getObject())) - .build()); - try { - verifyFirstStatement(ryaStatement, statements); - } finally { - statements.close(); - } - - //check po - statements = queryEngine.query(RyaQuery.builder( - new RyaStatement(null, ryaStatement.getPredicate(), - ryaStatement.getObject())).build()); - try { - verifyFirstStatement(ryaStatement, statements); - } finally { - statements.close(); - } - - //check spo - statements = queryEngine.query(RyaQuery.builder( - new RyaStatement(ryaStatement.getSubject(), - ryaStatement.getPredicate(), - ryaStatement.getObject())).build()); - try { - verifyFirstStatement(ryaStatement, statements); - } finally { - statements.close(); - } - } - - private void verifyFirstStatement( - RyaStatement ryaStatement, CloseableIterable<RyaStatement> statements) { - final Iterator<RyaStatement> iterator = statements.iterator(); - assertTrue(iterator.hasNext()); - final RyaStatement first = iterator.next(); - assertEquals(ryaStatement.getSubject(), first.getSubject()); - assertEquals(ryaStatement.getPredicate(), first.getPredicate()); - assertEquals(ryaStatement.getObject(), first.getObject()); - assertFalse(iterator.hasNext()); - } - - public void printTableData(String tableName) - throws TableNotFoundException{ - Scanner scanner = connector.createScanner(tableName, auths); - scanner.setRange(new Range()); - for(Map.Entry<Key, Value> entry : scanner) { - final Key key = entry.getKey(); - final Value value = entry.getValue(); - System.out.println(key.getRow() + " " + key.getColumnFamily() + " " + key.getColumnQualifier() + " " + key.getTimestamp() + " " + value.toString()); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/UpgradeObjectSerializationTest.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/UpgradeObjectSerializationTest.java b/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/UpgradeObjectSerializationTest.java deleted file mode 100644 index b138292..0000000 --- a/dao/accumulo.rya/src/test/java/mvm/rya/accumulo/mr/upgrade/UpgradeObjectSerializationTest.java +++ /dev/null @@ -1,119 +0,0 @@ -package mvm.rya.accumulo.mr.upgrade; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - - -import mvm.rya.api.resolver.impl.*; -import org.junit.Test; - -import static mvm.rya.accumulo.mr.upgrade.Upgrade322Tool.UpgradeObjectSerialization; -import static org.junit.Assert.*; - -public class UpgradeObjectSerializationTest { - - @Test - public void testBooleanUpgrade() throws Exception { - String object = "true"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, BooleanRyaTypeResolver.BOOLEAN_LITERAL_MARKER); - - assertEquals("1", upgrade); - } - - @Test - public void testBooleanUpgradeFalse() throws Exception { - String object = "false"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, BooleanRyaTypeResolver.BOOLEAN_LITERAL_MARKER); - - assertEquals("0", upgrade); - } - - @Test - public void testByteUpgradeLowest() throws Exception { - String object = "-127"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, ByteRyaTypeResolver.LITERAL_MARKER); - - assertEquals("81", upgrade); - } - - @Test - public void testByteUpgradeHighest() throws Exception { - String object = "127"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, ByteRyaTypeResolver.LITERAL_MARKER); - - assertEquals("7f", upgrade); - } - - @Test - public void testLongUpgrade() throws Exception { - String object = "00000000000000000010"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, LongRyaTypeResolver.LONG_LITERAL_MARKER); - - assertEquals("800000000000000a", upgrade); - } - - @Test - public void testIntUpgrade() throws Exception { - String object = "00000000010"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, IntegerRyaTypeResolver.INTEGER_LITERAL_MARKER); - - assertEquals("8000000a", upgrade); - } - - @Test - public void testDateTimeUpgrade() throws Exception { - String object = "9223370726404375807"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, DateTimeRyaTypeResolver.DATETIME_LITERAL_MARKER); - - assertEquals("800001311cee3b00", upgrade); - } - - @Test - public void testDoubleUpgrade() throws Exception { - String object = "00001 1.0"; - final UpgradeObjectSerialization upgradeObjectSerialization - = new UpgradeObjectSerialization(); - final String upgrade = upgradeObjectSerialization - .upgrade(object, DoubleRyaTypeResolver.DOUBLE_LITERAL_MARKER); - - assertEquals("c024000000000000", upgrade); - } -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/accumulo.rya/src/test/resources/namedgraphs.trig ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/test/resources/namedgraphs.trig b/dao/accumulo.rya/src/test/resources/namedgraphs.trig deleted file mode 100644 index b647632..0000000 --- a/dao/accumulo.rya/src/test/resources/namedgraphs.trig +++ /dev/null @@ -1,7 +0,0 @@ -@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> . -@prefix xsd: <http://www.w3.org/2001/XMLSchema#> . -@prefix swp: <http://www.w3.org/2004/03/trix/swp-1/> . -@prefix dc: <http://purl.org/dc/elements/1.1/> . -@prefix ex: <http://www.example.org/vocabulary#> . -@prefix : <http://www.example.org/exampleDocument#> . -:G1 { :Monica ex:name "Monica Murphy" . } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/accumulo.rya/src/test/resources/test.ntriples ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/test/resources/test.ntriples b/dao/accumulo.rya/src/test/resources/test.ntriples deleted file mode 100644 index 26a0a17..0000000 --- a/dao/accumulo.rya/src/test/resources/test.ntriples +++ /dev/null @@ -1 +0,0 @@ -<urn:lubm:rdfts#GraduateStudent01> <urn:lubm:rdfts#hasFriend> <urn:lubm:rdfts#GraduateStudent02> . \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/pom.xml ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/pom.xml b/dao/mongodb.rya/pom.xml deleted file mode 100644 index 0d87fa5..0000000 --- a/dao/mongodb.rya/pom.xml +++ /dev/null @@ -1,48 +0,0 @@ -<?xml version='1.0'?> -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.rya</groupId> - <artifactId>rya.dao</artifactId> - <version>3.2.10-SNAPSHOT</version> - </parent> - - <artifactId>mongodb.rya</artifactId> - <name>Apache Rya MongoDB DAO</name> - - <dependencies> - <dependency> - <groupId>org.apache.rya</groupId> - <artifactId>rya.api</artifactId> - </dependency> - - <dependency> - <groupId>org.mongodb</groupId> - <artifactId>mongo-java-driver</artifactId> - </dependency> - <dependency> - <groupId>de.flapdoodle.embed</groupId> - <artifactId>de.flapdoodle.embed.mongo</artifactId> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBQueryEngine.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBQueryEngine.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBQueryEngine.java deleted file mode 100644 index 57548ec..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBQueryEngine.java +++ /dev/null @@ -1,207 +0,0 @@ -package mvm.rya.mongodb; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.io.Closeable; -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.query.BatchRyaQuery; -import mvm.rya.api.persist.query.RyaQuery; -import mvm.rya.api.persist.query.RyaQueryEngine; -import mvm.rya.mongodb.dao.MongoDBStorageStrategy; -import mvm.rya.mongodb.dao.SimpleMongoDBStorageStrategy; -import mvm.rya.mongodb.iter.NonCloseableRyaStatementCursorIterator; -import mvm.rya.mongodb.iter.RyaStatementBindingSetCursorIterator; -import mvm.rya.mongodb.iter.RyaStatementCursorIterable; -import mvm.rya.mongodb.iter.RyaStatementCursorIterator; - -import org.calrissian.mango.collect.CloseableIterable; -import org.openrdf.query.BindingSet; - -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.MongoClient; - -/** - * Date: 7/17/12 - * Time: 9:28 AM - */ -public class MongoDBQueryEngine implements RyaQueryEngine<MongoDBRdfConfiguration>, Closeable { - - private MongoDBRdfConfiguration configuration; - private MongoClient mongoClient; - private DBCollection coll; - private MongoDBStorageStrategy strategy; - - public MongoDBQueryEngine(MongoDBRdfConfiguration conf) throws NumberFormatException, UnknownHostException{ - mongoClient = new MongoClient(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE), - Integer.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT))); - DB db = mongoClient.getDB( conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); - coll = db.getCollection(conf.getTriplesCollectionName()); - this.strategy = new SimpleMongoDBStorageStrategy(); - } - - - @Override - public void setConf(MongoDBRdfConfiguration conf) { - configuration = conf; - } - - @Override - public MongoDBRdfConfiguration getConf() { - return configuration; - } - - @Override - public CloseableIteration<RyaStatement, RyaDAOException> query( - RyaStatement stmt, MongoDBRdfConfiguration conf) - throws RyaDAOException { - if (conf == null) { - conf = configuration; - } - Long maxResults = conf.getLimit(); - Set<DBObject> queries = new HashSet<DBObject>(); - DBObject query = strategy.getQuery(stmt); - queries.add(query); - RyaStatementCursorIterator iterator = new RyaStatementCursorIterator(coll, queries, strategy); - - if (maxResults != null) { - iterator.setMaxResults(maxResults); - } - return iterator; - } - @Override - public CloseableIteration<? extends Entry<RyaStatement, BindingSet>, RyaDAOException> queryWithBindingSet( - Collection<Entry<RyaStatement, BindingSet>> stmts, - MongoDBRdfConfiguration conf) throws RyaDAOException { - if (conf == null) { - conf = configuration; - } - Long maxResults = conf.getLimit(); - Map<DBObject, BindingSet> rangeMap = new HashMap<DBObject, BindingSet>(); - - //TODO: cannot span multiple tables here - try { - for (Map.Entry<RyaStatement, BindingSet> stmtbs : stmts) { - RyaStatement stmt = stmtbs.getKey(); - BindingSet bs = stmtbs.getValue(); - DBObject query = strategy.getQuery(stmt); - rangeMap.put(query, bs); - } - - // TODO not sure what to do about regex ranges? - RyaStatementBindingSetCursorIterator iterator = new RyaStatementBindingSetCursorIterator(coll, rangeMap, strategy); - - if (maxResults != null) { - iterator.setMaxResults(maxResults); - } - return iterator; - } catch (Exception e) { - throw new RyaDAOException(e); - } - - } - @Override - public CloseableIteration<RyaStatement, RyaDAOException> batchQuery( - Collection<RyaStatement> stmts, MongoDBRdfConfiguration conf) - throws RyaDAOException { - if (conf == null) { - conf = configuration; - } - Long maxResults = conf.getLimit(); - Set<DBObject> queries = new HashSet<DBObject>(); - - try { - for (RyaStatement stmt : stmts) { - queries.add( strategy.getQuery(stmt)); - } - - // TODO not sure what to do about regex ranges? - RyaStatementCursorIterator iterator = new RyaStatementCursorIterator(coll, queries, strategy); - - if (maxResults != null) { - iterator.setMaxResults(maxResults); - } - return iterator; - } catch (Exception e) { - throw new RyaDAOException(e); - } - - } - @Override - public CloseableIterable<RyaStatement> query(RyaQuery ryaQuery) - throws RyaDAOException { - Set<DBObject> queries = new HashSet<DBObject>(); - - try { - queries.add( strategy.getQuery(ryaQuery)); - - // TODO not sure what to do about regex ranges? - // TODO this is gross - RyaStatementCursorIterable iterator = new RyaStatementCursorIterable(new NonCloseableRyaStatementCursorIterator(new RyaStatementCursorIterator(coll, queries, strategy))); - - return iterator; - } catch (Exception e) { - throw new RyaDAOException(e); - } - } - @Override - public CloseableIterable<RyaStatement> query(BatchRyaQuery batchRyaQuery) - throws RyaDAOException { - try { - Set<DBObject> queries = new HashSet<DBObject>(); - for (RyaStatement statement : batchRyaQuery.getQueries()){ - queries.add( strategy.getQuery(statement)); - - } - - // TODO not sure what to do about regex ranges? - // TODO this is gross - RyaStatementCursorIterable iterator = new RyaStatementCursorIterable(new NonCloseableRyaStatementCursorIterator(new RyaStatementCursorIterator(coll, queries, strategy))); - - return iterator; - } catch (Exception e) { - throw new RyaDAOException(e); - } - } - - @Override - public void close() throws IOException { - if (mongoClient != null){ mongoClient.close(); } - } - - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRdfConfiguration.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRdfConfiguration.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRdfConfiguration.java deleted file mode 100644 index 3c5a8ef..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRdfConfiguration.java +++ /dev/null @@ -1,121 +0,0 @@ -package mvm.rya.mongodb; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - - -import java.util.List; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.persist.index.RyaSecondaryIndexer; - -import org.apache.hadoop.conf.Configuration; - -import com.google.common.collect.Lists; - -public class MongoDBRdfConfiguration extends RdfCloudTripleStoreConfiguration { - public static final String MONGO_INSTANCE = "mongo.db.instance"; - public static final String MONGO_INSTANCE_PORT = "mongo.db.port"; - public static final String MONGO_GEO_MAXDISTANCE = "mongo.geo.maxdist"; - public static final String MONGO_DB_NAME = "mongo.db.name"; - public static final String MONGO_COLLECTION_PREFIX = "mongo.db.collectionprefix"; - public static final String MONGO_USER = "mongo.db.user"; - public static final String MONGO_USER_PASSWORD = "mongo.db.userpassword"; - public static final String USE_TEST_MONGO = "mongo.db.test"; - public static final String CONF_ADDITIONAL_INDEXERS = "ac.additional.indexers"; - - public MongoDBRdfConfiguration() { - super(); - } - - public MongoDBRdfConfiguration(Configuration other) { - super(other); - } - - @Override - public MongoDBRdfConfiguration clone() { - return new MongoDBRdfConfiguration(this); - } - - public boolean getUseTestMongo() { - return this.getBoolean(USE_TEST_MONGO, false); - } - - public void setUseTestMongo(boolean useTestMongo) { - this.setBoolean(USE_TEST_MONGO, useTestMongo); - } - - public String getTriplesCollectionName() { - return this.get(MONGO_COLLECTION_PREFIX, "rya") + "_triples"; - } - - public String getCollectionName() { - return this.get(MONGO_COLLECTION_PREFIX, "rya"); - } - - public void setCollectionName(String name) { - this.set(MONGO_COLLECTION_PREFIX, name); - } - - public String getMongoInstance() { - return this.get(MONGO_INSTANCE, "localhost"); - } - - public void setMongoInstance(String name) { - this.set(MONGO_INSTANCE, name); - } - - public String getMongoPort() { - return this.get(MONGO_INSTANCE_PORT, "27017"); - } - - public void setMongoPort(String name) { - this.set(MONGO_INSTANCE_PORT, name); - } - - public String getMongoDBName() { - return this.get(MONGO_DB_NAME, "rya"); - } - - public void setMongoDBName(String name) { - this.set(MONGO_DB_NAME, name); - } - - public String getNameSpacesCollectionName() { - return this.get(MONGO_COLLECTION_PREFIX, "rya") + "_ns"; - } - - public void setAdditionalIndexers(Class<? extends RyaSecondaryIndexer>... indexers) { - List<String> strs = Lists.newArrayList(); - for (Class<?> ai : indexers){ - strs.add(ai.getName()); - } - - setStrings(CONF_ADDITIONAL_INDEXERS, strs.toArray(new String[]{})); - } - - public List<RyaSecondaryIndexer> getAdditionalIndexers() { - return getInstances(CONF_ADDITIONAL_INDEXERS, RyaSecondaryIndexer.class); - } - - - - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRyaDAO.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRyaDAO.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRyaDAO.java deleted file mode 100644 index 1f341dc..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/MongoDBRyaDAO.java +++ /dev/null @@ -1,222 +0,0 @@ -package mvm.rya.mongodb; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import java.io.IOException; -import java.net.UnknownHostException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; - -import mvm.rya.api.RdfCloudTripleStoreConfiguration; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.persist.RyaDAO; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.api.persist.RyaNamespaceManager; -import mvm.rya.api.persist.index.RyaSecondaryIndexer; -import mvm.rya.api.persist.query.RyaQueryEngine; -import mvm.rya.mongodb.dao.MongoDBNamespaceManager; -import mvm.rya.mongodb.dao.MongoDBStorageStrategy; -import mvm.rya.mongodb.dao.SimpleMongoDBNamespaceManager; -import mvm.rya.mongodb.dao.SimpleMongoDBStorageStrategy; - -import org.apache.commons.io.IOUtils; - -import com.mongodb.DB; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; -import com.mongodb.InsertOptions; -import com.mongodb.MongoClient; -import com.mongodb.MongoCredential; -import com.mongodb.ServerAddress; - -import de.flapdoodle.embed.mongo.distribution.Version; -import de.flapdoodle.embed.mongo.tests.MongodForTestsFactory; - -public class MongoDBRyaDAO implements RyaDAO<MongoDBRdfConfiguration>{ - - - private MongoDBRdfConfiguration conf; - private MongoClient mongoClient; - private DB db; - private DBCollection coll; - private MongoDBQueryEngine queryEngine; - private MongoDBStorageStrategy storageStrategy; - private MongoDBNamespaceManager nameSpaceManager; - private MongodForTestsFactory testsFactory; - - private List<RyaSecondaryIndexer> secondaryIndexers; - - public MongoDBRyaDAO(MongoDBRdfConfiguration conf) throws RyaDAOException{ - this.conf = conf; - init(); - } - - public void setConf(MongoDBRdfConfiguration conf) { - this.conf = conf; - } - - public MongoDBRdfConfiguration getConf() { - return conf; - } - - public void init() throws RyaDAOException { - try { - boolean useMongoTest = conf.getUseTestMongo(); - if (useMongoTest) { - testsFactory = MongodForTestsFactory.with(Version.Main.PRODUCTION); - mongoClient = testsFactory.newMongo(); - int port = mongoClient.getServerAddressList().get(0).getPort(); - conf.set(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT, Integer.toString(port)); - } else { - ServerAddress server = new ServerAddress(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE), - Integer.valueOf(conf.get(MongoDBRdfConfiguration.MONGO_INSTANCE_PORT))); - if (conf.get(MongoDBRdfConfiguration.MONGO_USER) != null) { - MongoCredential cred = MongoCredential.createCredential( - conf.get(MongoDBRdfConfiguration.MONGO_USER), - conf.get(MongoDBRdfConfiguration.MONGO_USER_PASSWORD), - conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME).toCharArray()); - mongoClient = new MongoClient(server, Arrays.asList(cred)); - } else { - mongoClient = new MongoClient(server); - } - } - secondaryIndexers = conf.getAdditionalIndexers(); - for(RyaSecondaryIndexer index: secondaryIndexers) { - index.setConf(conf); - } - - db = mongoClient.getDB(conf.get(MongoDBRdfConfiguration.MONGO_DB_NAME)); - coll = db.getCollection(conf.getTriplesCollectionName()); - nameSpaceManager = new SimpleMongoDBNamespaceManager(db.getCollection(conf.getNameSpacesCollectionName())); - queryEngine = new MongoDBQueryEngine(conf); - storageStrategy = new SimpleMongoDBStorageStrategy(); - storageStrategy.createIndices(coll); - - } catch (UnknownHostException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - } - - public boolean isInitialized() throws RyaDAOException { - return true; - } - - public void destroy() throws RyaDAOException { - if (mongoClient != null) { - mongoClient.close(); - } - if (conf.getUseTestMongo()) { - testsFactory.shutdown(); - } - - IOUtils.closeQuietly(queryEngine); - } - - public void add(RyaStatement statement) throws RyaDAOException { - // add it to the collection - try { - coll.insert(storageStrategy.serialize(statement)); - for(RyaSecondaryIndexer index: secondaryIndexers) { - index.storeStatement(statement); - } - } - catch (com.mongodb.MongoException.DuplicateKey exception){ - // ignore - } - catch (com.mongodb.DuplicateKeyException exception){ - // ignore - } - catch (Exception ex){ - // ignore single exceptions - ex.printStackTrace(); - } - } - - public void add(Iterator<RyaStatement> statement) throws RyaDAOException { - List<DBObject> dbInserts = new ArrayList<DBObject>(); - while (statement.hasNext()){ - RyaStatement ryaStatement = statement.next(); - DBObject insert = storageStrategy.serialize(ryaStatement); - dbInserts.add(insert); - - try { - for (RyaSecondaryIndexer index : secondaryIndexers) { - index.storeStatement(ryaStatement); - } - } catch (IOException e) { - throw new RyaDAOException(e); - } - - } - coll.insert(dbInserts, new InsertOptions().continueOnError(true)); - } - - public void delete(RyaStatement statement, MongoDBRdfConfiguration conf) - throws RyaDAOException { - DBObject obj = storageStrategy.serialize(statement); - coll.remove(obj); - } - - public void dropGraph(MongoDBRdfConfiguration conf, RyaURI... graphs) - throws RyaDAOException { - - } - - public void delete(Iterator<RyaStatement> statements, - MongoDBRdfConfiguration conf) throws RyaDAOException { - while (statements.hasNext()){ - RyaStatement ryaStatement = statements.next(); - coll.remove(storageStrategy.serialize(ryaStatement)); - } - - } - - public String getVersion() throws RyaDAOException { - return "1.0"; - } - - public RyaQueryEngine<MongoDBRdfConfiguration> getQueryEngine() { - return queryEngine; - } - - public RyaNamespaceManager<MongoDBRdfConfiguration> getNamespaceManager() { - return nameSpaceManager; - } - - public void purge(RdfCloudTripleStoreConfiguration configuration) { - // TODO Auto-generated method stub - - } - - public void dropAndDestroy() throws RyaDAOException { - db.dropDatabase(); // this is dangerous! - } - - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBNamespaceManager.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBNamespaceManager.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBNamespaceManager.java deleted file mode 100644 index fd9b659..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBNamespaceManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package mvm.rya.mongodb.dao; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaNamespaceManager; -import mvm.rya.api.persist.query.RyaQuery; -import mvm.rya.mongodb.MongoDBRdfConfiguration; - -import com.mongodb.DBCollection; -import com.mongodb.DBObject; - -public interface MongoDBNamespaceManager extends RyaNamespaceManager<MongoDBRdfConfiguration>{ - - public void createIndices(DBCollection coll); - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBStorageStrategy.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBStorageStrategy.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBStorageStrategy.java deleted file mode 100644 index 8a1004f..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/MongoDBStorageStrategy.java +++ /dev/null @@ -1,41 +0,0 @@ -package mvm.rya.mongodb.dao; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.query.RyaQuery; - -import com.mongodb.DBCollection; -import com.mongodb.DBObject; - -public interface MongoDBStorageStrategy { - - public DBObject getQuery(RyaStatement stmt); - - public RyaStatement deserializeDBObject(DBObject queryResult); - - public DBObject serialize(RyaStatement statement); - - public DBObject getQuery(RyaQuery ryaQuery); - - public void createIndices(DBCollection coll); - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java deleted file mode 100644 index 259420b..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBNamespaceManager.java +++ /dev/null @@ -1,181 +0,0 @@ -package mvm.rya.mongodb.dao; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.mongodb.MongoDBRdfConfiguration; - -import org.apache.commons.codec.binary.Hex; -import org.openrdf.model.Namespace; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; - -public class SimpleMongoDBNamespaceManager implements MongoDBNamespaceManager { - - public class NamespaceImplementation implements Namespace { - - private String namespace; - private String prefix; - - public NamespaceImplementation(String namespace, String prefix) { - this.namespace = namespace; - this.prefix = prefix; - } - - @Override - public int compareTo(Namespace o) { - if (!namespace.equalsIgnoreCase(o.getName())) return namespace.compareTo(o.getName()); - if (!prefix.equalsIgnoreCase(o.getPrefix())) return prefix.compareTo(o.getPrefix()); - return 0; - } - - @Override - public String getName() { - return namespace; - } - - @Override - public String getPrefix() { - return prefix; - } - - } - - public class MongoCursorIteration implements - CloseableIteration<Namespace, RyaDAOException> { - private DBCursor cursor; - - public MongoCursorIteration(DBCursor cursor2) { - this.cursor = cursor2; - } - - @Override - public boolean hasNext() throws RyaDAOException { - return cursor.hasNext(); - } - - @Override - public Namespace next() throws RyaDAOException { - DBObject ns = cursor.next(); - Map values = ns.toMap(); - String namespace = (String) values.get(NAMESPACE); - String prefix = (String) values.get(PREFIX); - - Namespace temp = new NamespaceImplementation(namespace, prefix); - return temp; - } - - @Override - public void remove() throws RyaDAOException { - next(); - } - - @Override - public void close() throws RyaDAOException { - cursor.close(); - } - - } - - private static final String ID = "_id"; - private static final String PREFIX = "prefix"; - private static final String NAMESPACE = "namespace"; - private MongoDBRdfConfiguration conf; - private DBCollection nsColl; - - - public SimpleMongoDBNamespaceManager(DBCollection nameSpaceCollection) { - nsColl = nameSpaceCollection; - } - - @Override - public void createIndices(DBCollection coll){ - coll.createIndex(PREFIX); - coll.createIndex(NAMESPACE); - } - - - @Override - public void setConf(MongoDBRdfConfiguration paramC) { - this.conf = paramC; - } - - @Override - public MongoDBRdfConfiguration getConf() { - // TODO Auto-generated method stub - return conf; - } - - @Override - public void addNamespace(String prefix, String namespace) - throws RyaDAOException { - String id = prefix; - byte[] bytes = id.getBytes(); - try { - MessageDigest digest = MessageDigest.getInstance("SHA-1"); - bytes = digest.digest(bytes); - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))) - .append(PREFIX, prefix) - .append(NAMESPACE, namespace); - nsColl.insert(doc); - - } - - @Override - public String getNamespace(String prefix) throws RyaDAOException { - DBObject query = new BasicDBObject().append(PREFIX, prefix); - DBCursor cursor = nsColl.find(query); - String nameSpace = prefix; - while (cursor.hasNext()){ - DBObject obj = cursor.next(); - nameSpace = (String) obj.toMap().get(NAMESPACE); - } - return nameSpace; - } - - @Override - public void removeNamespace(String prefix) throws RyaDAOException { - DBObject query = new BasicDBObject().append(PREFIX, prefix); - nsColl.remove(query); - } - - @Override - public CloseableIteration<? extends Namespace, RyaDAOException> iterateNamespace() - throws RyaDAOException { - DBObject query = new BasicDBObject(); - DBCursor cursor = nsColl.find(query); - return new MongoCursorIteration(cursor); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java deleted file mode 100644 index 24d16c1..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/dao/SimpleMongoDBStorageStrategy.java +++ /dev/null @@ -1,152 +0,0 @@ -package mvm.rya.mongodb.dao; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.Map; - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.domain.RyaType; -import mvm.rya.api.domain.RyaURI; -import mvm.rya.api.persist.query.RyaQuery; - -import org.apache.commons.codec.binary.Hex; -import org.openrdf.model.impl.ValueFactoryImpl; - -import com.mongodb.BasicDBObject; -import com.mongodb.DBCollection; -import com.mongodb.DBObject; - -public class SimpleMongoDBStorageStrategy implements MongoDBStorageStrategy { - - private static final String ID = "_id"; - private static final String OBJECT_TYPE = "objectType"; - private static final String CONTEXT = "context"; - private static final String PREDICATE = "predicate"; - private static final String OBJECT = "object"; - private static final String SUBJECT = "subject"; - private ValueFactoryImpl factory = new ValueFactoryImpl(); - - - public SimpleMongoDBStorageStrategy() { - } - - @Override - public void createIndices(DBCollection coll){ - coll.createIndex("subject"); - coll.createIndex("predicate"); - BasicDBObject doc = new BasicDBObject(); - doc.put(SUBJECT, 1); - doc.put(PREDICATE, 1); - coll.createIndex(doc); - doc = new BasicDBObject(OBJECT, 1); - doc.put(OBJECT_TYPE, 1); - doc.put(PREDICATE, 1); - coll.createIndex(doc); - doc = new BasicDBObject(OBJECT, 1); - doc.put(OBJECT_TYPE, 1); - coll.createIndex(doc); - doc = new BasicDBObject(OBJECT, 1); - doc = new BasicDBObject(OBJECT_TYPE, 1); - doc.put(SUBJECT, 1); - coll.createIndex(doc); - } - - @Override - public DBObject getQuery(RyaStatement stmt) { - RyaURI subject = stmt.getSubject(); - RyaURI predicate = stmt.getPredicate(); - RyaType object = stmt.getObject(); - RyaURI context = stmt.getContext(); - BasicDBObject query = new BasicDBObject(); - if (subject != null){ - query.append(SUBJECT, subject.getData()); - } - if (object != null){ - query.append(OBJECT, object.getData()); - query.append(OBJECT_TYPE, object.getDataType().toString()); - } - if (predicate != null){ - query.append(PREDICATE, predicate.getData()); - } - if (context != null){ - query.append(CONTEXT, context.getData()); - } - - return query; - } - - @Override - public RyaStatement deserializeDBObject(DBObject queryResult) { - Map result = queryResult.toMap(); - String subject = (String) result.get(SUBJECT); - String object = (String) result.get(OBJECT); - String objectType = (String) result.get(OBJECT_TYPE); - String predicate = (String) result.get(PREDICATE); - String context = (String) result.get(CONTEXT); - RyaType objectRya = null; - if (objectType.equalsIgnoreCase("http://www.w3.org/2001/XMLSchema#anyURI")){ - objectRya = new RyaURI(object); - } - else { - objectRya = new RyaType(factory.createURI(objectType), object); - } - - if (!context.isEmpty()){ - return new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya, - new RyaURI(context)); - } - return new RyaStatement(new RyaURI(subject), new RyaURI(predicate), objectRya); - } - - @Override - public DBObject serialize(RyaStatement statement){ - String context = ""; - if (statement.getContext() != null){ - context = statement.getContext().getData(); - } - String id = statement.getSubject().getData() + " " + - statement.getPredicate().getData() + " " + statement.getObject().getData() + " " + context; - byte[] bytes = id.getBytes(); - try { - MessageDigest digest = MessageDigest.getInstance("SHA-1"); - bytes = digest.digest(bytes); - } catch (NoSuchAlgorithmException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - BasicDBObject doc = new BasicDBObject(ID, new String(Hex.encodeHex(bytes))) - .append(SUBJECT, statement.getSubject().getData()) - .append(PREDICATE, statement.getPredicate().getData()) - .append(OBJECT, statement.getObject().getData()) - .append(OBJECT_TYPE, statement.getObject().getDataType().toString()) - .append(CONTEXT, context); - return doc; - - } - - @Override - public DBObject getQuery(RyaQuery ryaQuery) { - return getQuery(ryaQuery.getQuery()); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/NonCloseableRyaStatementCursorIterator.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/NonCloseableRyaStatementCursorIterator.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/NonCloseableRyaStatementCursorIterator.java deleted file mode 100644 index ba37ca1..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/NonCloseableRyaStatementCursorIterator.java +++ /dev/null @@ -1,57 +0,0 @@ -package mvm.rya.mongodb.iter; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import java.util.Iterator; - -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAOException; - -public class NonCloseableRyaStatementCursorIterator implements Iterator<RyaStatement> { - - RyaStatementCursorIterator iterator; - - @Override - public boolean hasNext() { - return iterator.hasNext(); - } - - @Override - public RyaStatement next() { - return iterator.next(); - } - - public NonCloseableRyaStatementCursorIterator( - RyaStatementCursorIterator iterator) { - this.iterator = iterator; - } - - @Override - public void remove() { - try { - iterator.remove(); - } catch (RyaDAOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java deleted file mode 100644 index ce21ff7..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementBindingSetCursorIterator.java +++ /dev/null @@ -1,108 +0,0 @@ -package mvm.rya.mongodb.iter; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.util.Iterator; -import java.util.Map; -import java.util.Map.Entry; - -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.mongodb.dao.MongoDBStorageStrategy; - -import org.openrdf.query.BindingSet; - -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; - -public class RyaStatementBindingSetCursorIterator implements CloseableIteration<Entry<RyaStatement, BindingSet>, RyaDAOException> { - - private DBCollection coll; - private Map<DBObject, BindingSet> rangeMap; - private Iterator<DBObject> queryIterator; - private Long maxResults; - private DBCursor currentCursor; - private BindingSet currentBindingSet; - private MongoDBStorageStrategy strategy; - - public RyaStatementBindingSetCursorIterator(DBCollection coll, - Map<DBObject, BindingSet> rangeMap, MongoDBStorageStrategy strategy) { - this.coll = coll; - this.rangeMap = rangeMap; - this.queryIterator = rangeMap.keySet().iterator(); - this.strategy = strategy; - } - - @Override - public boolean hasNext() { - if (!currentCursorIsValid()) { - findNextValidCursor(); - } - return currentCursorIsValid(); - } - - @Override - public Entry<RyaStatement, BindingSet> next() { - if (!currentCursorIsValid()) { - findNextValidCursor(); - } - if (currentCursorIsValid()) { - // convert to Rya Statement - DBObject queryResult = currentCursor.next(); - RyaStatement statement = strategy.deserializeDBObject(queryResult); - return new RdfCloudTripleStoreUtils.CustomEntry<RyaStatement, BindingSet>(statement, currentBindingSet); - } - return null; - } - - private void findNextValidCursor() { - while (queryIterator.hasNext()){ - DBObject currentQuery = queryIterator.next(); - currentCursor = coll.find(currentQuery); - currentBindingSet = rangeMap.get(currentQuery); - if (currentCursor.hasNext()) break; - } - } - - private boolean currentCursorIsValid() { - return (currentCursor != null) && currentCursor.hasNext(); - } - - - public void setMaxResults(Long maxResults) { - this.maxResults = maxResults; - } - - @Override - public void close() throws RyaDAOException { - // TODO don't know what to do here - } - - @Override - public void remove() throws RyaDAOException { - next(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterable.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterable.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterable.java deleted file mode 100644 index 83bd2d4..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterable.java +++ /dev/null @@ -1,67 +0,0 @@ -package mvm.rya.mongodb.iter; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.io.IOException; -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; - -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAOException; - -import org.calrissian.mango.collect.CloseableIterable; -import org.calrissian.mango.collect.CloseableIterator; -import org.openrdf.query.BindingSet; - -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; - -public class RyaStatementCursorIterable implements CloseableIterable<RyaStatement> { - - - private NonCloseableRyaStatementCursorIterator iterator; - - public RyaStatementCursorIterable(NonCloseableRyaStatementCursorIterator iterator) { - this.iterator = iterator; - } - - @Override - public Iterator<RyaStatement> iterator() { - // TODO Auto-generated method stub - return iterator; - } - - @Override - public void closeQuietly() { - //TODO don't know what to do here - } - - @Override - public void close() throws IOException { - // TODO Auto-generated method stub - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterator.java ---------------------------------------------------------------------- diff --git a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterator.java b/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterator.java deleted file mode 100644 index 8df2c60..0000000 --- a/dao/mongodb.rya/src/main/java/mvm/rya/mongodb/iter/RyaStatementCursorIterator.java +++ /dev/null @@ -1,104 +0,0 @@ -package mvm.rya.mongodb.iter; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -import info.aduna.iteration.CloseableIteration; - -import java.util.Iterator; -import java.util.Map.Entry; -import java.util.Set; - -import mvm.rya.api.RdfCloudTripleStoreUtils; -import mvm.rya.api.domain.RyaStatement; -import mvm.rya.api.persist.RyaDAOException; -import mvm.rya.mongodb.dao.MongoDBStorageStrategy; - -import org.calrissian.mango.collect.CloseableIterable; -import org.openrdf.query.BindingSet; - -import com.mongodb.DBCollection; -import com.mongodb.DBCursor; -import com.mongodb.DBObject; - -public class RyaStatementCursorIterator implements CloseableIteration<RyaStatement, RyaDAOException> { - - private DBCollection coll; - private Iterator<DBObject> queryIterator; - private DBCursor currentCursor; - private MongoDBStorageStrategy strategy; - private Long maxResults; - - public RyaStatementCursorIterator(DBCollection coll, Set<DBObject> queries, MongoDBStorageStrategy strategy) { - this.coll = coll; - this.queryIterator = queries.iterator(); - this.strategy = strategy; - } - - @Override - public boolean hasNext() { - if (!currentCursorIsValid()) { - findNextValidCursor(); - } - return currentCursorIsValid(); - } - - @Override - public RyaStatement next() { - if (!currentCursorIsValid()) { - findNextValidCursor(); - } - if (currentCursorIsValid()) { - // convert to Rya Statement - DBObject queryResult = currentCursor.next(); - RyaStatement statement = strategy.deserializeDBObject(queryResult); - return statement; - } - return null; - } - - private void findNextValidCursor() { - while (queryIterator.hasNext()){ - DBObject currentQuery = queryIterator.next(); - currentCursor = coll.find(currentQuery); - if (currentCursor.hasNext()) break; - } - } - - private boolean currentCursorIsValid() { - return (currentCursor != null) && currentCursor.hasNext(); - } - - - public void setMaxResults(Long maxResults) { - this.maxResults = maxResults; - } - - @Override - public void close() throws RyaDAOException { - // TODO don't know what to do here - } - - @Override - public void remove() throws RyaDAOException { - next(); - } - -} http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/5a03ef61/dao/pom.xml ---------------------------------------------------------------------- diff --git a/dao/pom.xml b/dao/pom.xml deleted file mode 100644 index 604b30c..0000000 --- a/dao/pom.xml +++ /dev/null @@ -1,39 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> - -<!-- -Licensed to the Apache Software Foundation (ASF) under one -or more contributor license agreements. See the NOTICE file -distributed with this work for additional information -regarding copyright ownership. The ASF licenses this file -to you under the Apache License, Version 2.0 (the -"License"); you may not use this file except in compliance -with the License. You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, -software distributed under the License is distributed on an -"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -KIND, either express or implied. See the License for the -specific language governing permissions and limitations -under the License. ---> - -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - <parent> - <groupId>org.apache.rya</groupId> - <artifactId>rya-project</artifactId> - <version>3.2.10-SNAPSHOT</version> - </parent> - - <artifactId>rya.dao</artifactId> - <name>Apache Rya DAO Projects</name> - - <packaging>pom</packaging> - - <modules> - <module>accumulo.rya</module> - <module>mongodb.rya</module> - </modules> -</project>
