}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public void remove(Object entity) {
MetaClass metaClass = metaInfo.getMetaClass(entity.getClass());
if(metaClass == null)
throw new IllegalArgumentException("Entity type="+entity.getClass().getName()+" was not scanned and added to meta information on startup. It is either missing @NoSqlEntity annotation or it was not in list of scanned packages");
Object proxy = entity;
Object pk = metaClass.fetchId(entity);
MetaIdField idField = metaClass.getIdField();
byte[] rowKey = idField.convertIdToNonVirtKey(pk);
byte[] virtKey = idField.formVirtRowKey(rowKey);
DboTableMeta metaDbo = metaClass.getMetaDbo();
if(!metaClass.hasIndexedField(entity)) {
session.remove(metaDbo, virtKey);
return;
} else if(!(entity instanceof NoSqlProxy)) {
//then we don't have the database information for indexes so we need to read from the database
proxy = find(metaClass.getMetaClass(), pk);
}
List<IndexData> indexToRemove = metaClass.findIndexRemoves((NoSqlProxy)proxy, rowKey);
//REMOVE EVERYTHING HERE, we are probably removing extra and could optimize this later
for(IndexData ind : indexToRemove) {
session.removeFromIndex(metaDbo, ind.getColumnFamilyName(), ind.getRowKeyBytes(), ind.getIndexColumn());
}