Skip to content

Commit

Permalink
Delete mapped properties
Browse files Browse the repository at this point in the history
  • Loading branch information
ghelmling committed Feb 13, 2010
1 parent c7365ff commit 96f9f1f
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/java/meetup/beeno/EntityService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 96f9f1f

Please sign in to comment.