public int store(GenericValue value) throws GenericEntityException { if (addToCache(value)) { return 1; } else { return 0; } }
public int removeByCondition(final ModelEntity modelEntity, final EntityCondition whereCondition) throws GenericEntityException { Map<GenericEntity, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { return 0; } List<GenericValue> foundValues = findByCondition(modelEntity, whereCondition, null, null); return removeAll(foundValues); }
public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException { ArrayList result = new ArrayList(primaryKeys.size()); for (Iterator iterator = primaryKeys.iterator(); iterator.hasNext();) { GenericPK pk = (GenericPK) iterator.next(); result.add(this.findByPrimaryKey(pk)); } return result; }
for (Map.Entry<?, GenericValue> mapEntry : entityCache.entrySet()) { GenericValue value = mapEntry.getValue(); if (checkEntityExpr(value, entityExpr)) result.add(value); EntityCondition subEntityCondition = entityConditionList.getCondition(i); if (EntityOperator.AND.equals(entityConditionList.getOperator())) { tempResult = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); List<GenericValue> list = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); for (GenericValue o : list) { if (!tempResult.contains(o)) return findByAnd(modelEntity, entityCond.fieldMap, orderBy); } else { return findByOr(modelEntity, entityCond.fieldMap, orderBy);
private boolean addToCache(GenericValue value) { if (value == null) { return false; } if (!veryifyValue(value)) { return false; } value = (GenericValue) value.clone(); // we need to be sure that no-one accesses the underlying cache // between calling 'get' and 'put' synchronized (cache) { Map<GenericEntity, GenericValue> entityCache = cache.get(value.getEntityName()); if (entityCache == null) { entityCache = getNewCache(); cache.put(value.getEntityName(), entityCache); } entityCache.put(value.getPrimaryKey(), value); } return true; }
public GenericValue findByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { return findFromCache(primaryKey); }
public int count(final ModelEntity modelEntity, final String fieldName, final EntityCondition entityCondition, final EntityFindOptions findOptions) throws GenericEntityException { Map<GenericEntity, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { return 0; } List<GenericValue> genericValues = this.findByCondition(modelEntity, entityCondition, Lists.newArrayList(fieldName), null); return genericValues.size(); }
public static void clearCache() { cache = getNewCache(); }
public List findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection fieldsToSelect, List orderBy) throws GenericEntityException { Map entityCache = (Map) cache.get(modelEntity.getEntityName()); if (entityCache == null) { return Collections.EMPTY_LIST; } List result = findByConditionWorker(entityCache, modelEntity, entityCondition, fieldsToSelect, orderBy); return result; }
public GenericValue create(GenericPK primaryKey) throws GenericEntityException { return create(new GenericValue(primaryKey)); }
Map.Entry mapEntry = (Map.Entry) iterator.next(); GenericValue value = (GenericValue) mapEntry.getValue(); if (checkEntityExpr(value, entityExpr)) result.add(value); EntityCondition subEntityCondition = entityConditionList.getCondition(i); if (EntityOperator.AND.equals(entityConditionList.getOperator())) { tempResult = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); List list = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); for (Iterator iterator = list.iterator(); iterator.hasNext();) return findByAnd(modelEntity, entityCond.fieldMap, orderBy); } else return findByOr(modelEntity, entityCond.fieldMap, orderBy);
private boolean addToCache(GenericValue value) { if (value == null) { return false; } if (!veryifyValue(value)) { return false; } value = (GenericValue) value.clone(); // we need to be sure that no-one accesses the underlying cache // between calling 'get' and 'put' synchronized (cache) { Map entityCache = (Map) cache.get(value.getEntityName()); if (entityCache == null) { entityCache = getNewCache(); cache.put(value.getEntityName(), entityCache); } entityCache.put(value.getPrimaryKey(), value); } return true; }
public GenericValue findByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { return findFromCache(primaryKey); }
/** * The memory implementation does the *minimum* that it can to allow tests to work. In particular it will * return *all* values for a particular entity from this method. */ public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) throws GenericEntityException { final Iterator<GenericValue> entities = (new ArrayList<GenericValue>(findByCondition(modelEntity, whereEntityCondition, fieldsToSelect, orderBy))).iterator(); // hack in the minimum that we can for this. return new EntityListIterator(new ReadOnlySQLProcessor(null), modelEntity, null, modelFieldTypeReader) { public GenericValue next() { if (entities.hasNext()) return entities.next(); else return null; } public void close() { //do nothing } }; }
public static void clearCache() { cache = getNewCache(); }
public List<GenericValue> findByCondition(ModelEntity modelEntity, EntityCondition entityCondition, Collection<String> fieldsToSelect, List<String> orderBy) throws GenericEntityException { Map<GenericEntity, GenericValue> entityCache = cache.get(modelEntity.getEntityName()); if (entityCache == null) { return Collections.emptyList(); } return findByConditionWorker(entityCache, modelEntity, entityCondition, fieldsToSelect, orderBy); }
public GenericValue create(GenericPK primaryKey) throws GenericEntityException { return create(new GenericValue(primaryKey)); }
Map.Entry mapEntry = (Map.Entry) iterator.next(); GenericValue value = (GenericValue) mapEntry.getValue(); if (checkEntityExpr(value, entityExpr)) result.add(value); EntityCondition subEntityCondition = entityConditionList.getCondition(i); if (EntityOperator.AND.equals(entityConditionList.getOperator())) { tempResult = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); List list = findByConditionWorker(tempEntityCache, modelEntity, subEntityCondition, fieldsToSelect, orderBy); for (Iterator iterator = list.iterator(); iterator.hasNext();) return findByAnd(modelEntity, entityCond.fieldMap, orderBy); } else return findByOr(modelEntity, entityCond.fieldMap, orderBy);
private boolean addToCache(GenericValue value) { if (value == null) { return false; } if (!veryifyValue(value)) { return false; } value = (GenericValue) value.clone(); // we need to be sure that no-one accesses the underlying cache // between calling 'get' and 'put' synchronized (cache) { Map entityCache = (Map) cache.get(value.getEntityName()); if (entityCache == null) { entityCache = getNewCache(); cache.put(value.getEntityName(), entityCache); } entityCache.put(value.getPrimaryKey(), value); } return true; }
public int store(GenericValue value) throws GenericEntityException { if (addToCache(value)) { return 1; } else { return 0; } }