Repository: incubator-rya Updated Branches: refs/heads/develop d3323fac9 -> 1d92d1991
move delete mutation creation to RyaTableMutationsFactory so it can be reused (i.e. applications needing to migrate data within Rya) Project: http://git-wip-us.apache.org/repos/asf/incubator-rya/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-rya/commit/b6d271c6 Tree: http://git-wip-us.apache.org/repos/asf/incubator-rya/tree/b6d271c6 Diff: http://git-wip-us.apache.org/repos/asf/incubator-rya/diff/b6d271c6 Branch: refs/heads/develop Commit: b6d271c6c85d45d0bc8993bcbf19503d299ba17a Parents: 358c13b Author: jej2003 <[email protected]> Authored: Thu Mar 17 17:08:39 2016 -0400 Committer: jej2003 <[email protected]> Committed: Thu Mar 17 17:08:39 2016 -0400 ---------------------------------------------------------------------- .../java/mvm/rya/accumulo/AccumuloRyaDAO.java | 27 +++--------- .../rya/accumulo/RyaTableMutationsFactory.java | 46 ++++++++++++++++++++ 2 files changed, 52 insertions(+), 21 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/b6d271c6/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRyaDAO.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRyaDAO.java b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRyaDAO.java index e251fd3..b10c522 100644 --- a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRyaDAO.java +++ b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/AccumuloRyaDAO.java @@ -32,6 +32,7 @@ import static mvm.rya.api.RdfCloudTripleStoreConstants.RTS_SUBJECT_RYA; import static mvm.rya.api.RdfCloudTripleStoreConstants.RTS_VERSION_PREDICATE_RYA; import static mvm.rya.api.RdfCloudTripleStoreConstants.VERSION_RYA; +import java.io.IOException; import java.util.Collection; import java.util.Collections; import java.util.Iterator; @@ -55,7 +56,6 @@ 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.ColumnVisibility; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.hadoop.io.Text; @@ -255,26 +255,11 @@ public class AccumuloRyaDAO implements RyaDAO<AccumuloRdfConfiguration>, RyaName } - protected void deleteSingleRyaStatement(RyaStatement stmt) throws TripleRowResolverException, MutationsRejectedException { - Map<TABLE_LAYOUT, TripleRow> map = ryaContext.serializeTriple(stmt); - bw_spo.addMutation(deleteMutation(map.get(TABLE_LAYOUT.SPO))); - bw_po.addMutation(deleteMutation(map.get(TABLE_LAYOUT.PO))); - bw_osp.addMutation(deleteMutation(map.get(TABLE_LAYOUT.OSP))); - - } - - protected Mutation deleteMutation(TripleRow tripleRow) { - Mutation m = new Mutation(new Text(tripleRow.getRow())); - - byte[] columnFamily = tripleRow.getColumnFamily(); - Text cfText = columnFamily == null ? EMPTY_TEXT : new Text(columnFamily); - - byte[] columnQualifier = tripleRow.getColumnQualifier(); - Text cqText = columnQualifier == null ? EMPTY_TEXT : new Text(columnQualifier); - - m.putDelete(cfText, cqText, new ColumnVisibility(tripleRow.getColumnVisibility()), - tripleRow.getTimestamp()); - return m; + protected void deleteSingleRyaStatement(RyaStatement stmt) throws IOException, MutationsRejectedException { + Map<TABLE_LAYOUT, Collection<Mutation>> map = ryaTableMutationsFactory.serializeDelete(stmt); + bw_spo.addMutations(map.get(TABLE_LAYOUT.SPO)); + bw_po.addMutations(map.get(TABLE_LAYOUT.PO)); + bw_osp.addMutations(map.get(TABLE_LAYOUT.OSP)); } protected void commit(Iterator<RyaStatement> commitStatements) throws RyaDAOException { http://git-wip-us.apache.org/repos/asf/incubator-rya/blob/b6d271c6/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/RyaTableMutationsFactory.java ---------------------------------------------------------------------- diff --git a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/RyaTableMutationsFactory.java b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/RyaTableMutationsFactory.java index 0dbafc1..2a4871d 100644 --- a/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/RyaTableMutationsFactory.java +++ b/dao/accumulo.rya/src/main/java/mvm/rya/accumulo/RyaTableMutationsFactory.java @@ -84,6 +84,52 @@ public class RyaTableMutationsFactory { return mutations; } + public Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> serializeDelete( + RyaStatement stmt) throws IOException { + + Collection<Mutation> spo_muts = new ArrayList<Mutation>(); + Collection<Mutation> po_muts = new ArrayList<Mutation>(); + Collection<Mutation> osp_muts = new ArrayList<Mutation>(); + /** + * TODO: If there are contexts, do we still replicate the information into the default graph as well + * as the named graphs? + */ + try { + Map<TABLE_LAYOUT, TripleRow> rowMap = ryaContext.serializeTriple(stmt); + TripleRow tripleRow = rowMap.get(TABLE_LAYOUT.SPO); + spo_muts.add(deleteMutation(tripleRow)); + tripleRow = rowMap.get(TABLE_LAYOUT.PO); + po_muts.add(deleteMutation(tripleRow)); + tripleRow = rowMap.get(TABLE_LAYOUT.OSP); + osp_muts.add(deleteMutation(tripleRow)); + } catch (TripleRowResolverException fe) { + throw new IOException(fe); + } + + Map<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>> mutations = + new HashMap<RdfCloudTripleStoreConstants.TABLE_LAYOUT, Collection<Mutation>>(); + mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.SPO, spo_muts); + mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.PO, po_muts); + mutations.put(RdfCloudTripleStoreConstants.TABLE_LAYOUT.OSP, osp_muts); + + return mutations; + + } + + protected Mutation deleteMutation(TripleRow tripleRow) { + Mutation m = new Mutation(new Text(tripleRow.getRow())); + + byte[] columnFamily = tripleRow.getColumnFamily(); + Text cfText = columnFamily == null ? EMPTY_TEXT : new Text(columnFamily); + + byte[] columnQualifier = tripleRow.getColumnQualifier(); + Text cqText = columnQualifier == null ? EMPTY_TEXT : new Text(columnQualifier); + + m.putDelete(cfText, cqText, new ColumnVisibility(tripleRow.getColumnVisibility()), + tripleRow.getTimestamp()); + return m; + } + protected Mutation createMutation(TripleRow tripleRow) { Mutation mutation = new Mutation(new Text(tripleRow.getRow())); byte[] columnVisibility = tripleRow.getColumnVisibility();
