From 96f9f1f20901c4b3d8ae98e35ec5533fd701a729 Mon Sep 17 00:00:00 2001 From: Gary Helmling Date: Sat, 13 Feb 2010 17:01:33 -0500 Subject: [PATCH] Delete mapped properties --- src/java/meetup/beeno/EntityService.java | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/java/meetup/beeno/EntityService.java b/src/java/meetup/beeno/EntityService.java index 7334743..3656f05 100644 --- a/src/java/meetup/beeno/EntityService.java +++ b/src/java/meetup/beeno/EntityService.java @@ -18,6 +18,7 @@ import meetup.beeno.mapping.EntityMetadata; import meetup.beeno.mapping.FieldMapping; import meetup.beeno.mapping.IndexMapping; +import meetup.beeno.mapping.MapField; import meetup.beeno.mapping.MappingException; import meetup.beeno.util.HUtil; import meetup.beeno.util.PBUtil; @@ -303,6 +304,64 @@ public void delete(String rowKey) throws HBaseException { } } + + public void deleteProperty(String rowKey, String propertyName) + throws HBaseException { + + EntityInfo info = getInfo(); + FieldMapping field = info.getPropertyMapping(propertyName); + if (field == null) + throw new IllegalArgumentException( String.format("Unknown property name '%s'", propertyName) ); + + // commit the delete + HTable table = null; + try { + table = HUtil.getTable(info.getTablename()); + Delete op = new Delete( Bytes.toBytes(rowKey) ); + op.deleteColumn( Bytes.toBytes(field.getFamily()), Bytes.toBytes(field.getColumn()) ); + table.delete(op); + + if (log.isDebugEnabled()) + log.debug(String.format("Deleted column '%s' for row '%s'", field.getFieldName(), rowKey)); + } + catch (IOException ioe) { + throw new HBaseException(String.format("Error deleting column '%s' for row '%s'", field.getFieldName(), rowKey)); + } + finally { + HUtil.releaseTable(table); + } + } + + + public void deleteMapProperty(String rowKey, String propertyName, String mapKey) + throws HBaseException { + + EntityInfo info = getInfo(); + FieldMapping field = info.getPropertyMapping(propertyName); + if (field == null) + throw new IllegalArgumentException( String.format("Unknown property name '%s'", propertyName) ); + else if (!(field instanceof MapField)) + throw new IllegalArgumentException( String.format("Property '%s' is not a Map type", propertyName) ); + + String columnName = field.getColumn() + mapKey; + HTable table = null; + try { + table = HUtil.getTable(info.getTablename()); + Delete op = new Delete( Bytes.toBytes(rowKey) ); + op.deleteColumn( Bytes.toBytes(field.getFamily()), Bytes.toBytes(columnName) ); + table.delete(op); + + if (log.isDebugEnabled()) + log.debug(String.format("Deleted column '%s:%s' for row '%s'", field.getFamily(), columnName, rowKey)); + } + catch (IOException ioe) { + throw new HBaseException(String.format("Error deleting column '%s:%s' for row '%s'", field.getFamily(), columnName, rowKey)); + } + finally { + HUtil.releaseTable(table); + } + } + /** * Updates any indexes based on entity annotations for the instance