@Override public int deleteAll(Class<?> clazz, boolean shouldNotify) throws StormException { final CachedTable table = super.getCachedTable(clazz); final int result = deleteInner(table.getTableName(), null); if (shouldNotify && result > 0) { manager.notifyChange(table.getNotificationUri()); } return result; }
/** * If values' size hit {@link #MAX}, then query will be split (size % MAX + [1]) * * <p>{@inheritDoc} */ @Override public int delete(List<?> values, boolean shouldNotify) throws StormException { final CachedTable table = super.getCachedTable(values); FieldHolder primaryKey; try { primaryKey = getPrimaryKey(table); } catch (NoPrimaryKeyFoundException e) { throw new StormException(e); } final List<Selection> selections = new ArrayList<>(); final int size = values.size(); int x = size / MAX; final int steps = x == 0 ? 1 : size % MAX != 0 ? x + 1 : x; if (steps > 1) { for (int i = 0, end = MAX, start = 0; i < steps; i++, start = end, end += Math.min(size - (MAX * i), MAX)) { selections.add(getSelection(primaryKey, values.subList(start, end))); } } else { selections.add(getSelection(primaryKey, values)); } int result = 0; beginTransaction(); try { for (Selection selection : selections) { result += deleteInner(table.getTableName(), selection); } setTransactionSuccessful(); } finally { endTransaction(); } if (shouldNotify && result > 0) { manager.notifyChange(table.getNotificationUri()); } return result; }
@Override public int delete(Object value, boolean shouldNotify) throws StormException { final CachedTable table = super.getCachedTable(value); Selection selection; try { selection = getSelection(table, value); } catch (NoPrimaryKeyFoundException | IllegalAccessException e) { throw new StormException(e); } final int result = deleteInner(table.getTableName(), selection); if (shouldNotify && result > 0) { manager.notifyChange(table.getNotificationUri()); } return result; }