From 082d629aa953d0516d90dd8a069a5485b176f64a Mon Sep 17 00:00:00 2001 From: Nicolas Malin Date: Fri, 11 Aug 2017 17:09:08 +0000 Subject: [PATCH] Implemented: Connect OFBiz to a read only database (OFBIZ-6401) Add a DAO helper class to use a datasource as readonly This helper is disable by default. To enable it change the helper class on your datasource use in entityengine.xml like keys) throws GenericEntityException { + if (primaryKey == null) { + return null; + } + GenericValue genericValue = GenericValue.create(primaryKey); + + genericDAO.partialSelect(genericValue, keys); + return genericValue; + } + + /** Find a number of Generic Value objects by their Primary Keys, all at once + * This is done here for the DAO GenericHelper; for a client-server helper it + * would be done on the server side to reduce network round trips. + *@param primaryKeys A List of primary keys to find by. + *@return List of GenericValue objects corresponding to the passed primaryKey objects + */ + public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException { + if (primaryKeys == null) return null; + List results = new LinkedList(); + + for (GenericPK primaryKey: primaryKeys) { + GenericValue result = this.findByPrimaryKey(primaryKey); + + if (result != null) results.add(result); + } + return results; + } + + /** Read only, no remove realize on the database + *@return 0 + */ + public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { + return 0; + } + + /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. + *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file + *@param whereEntityCondition The EntityCondition object that specifies how to constrain this query before any groupings are done (if this is a view entity with group-by aliases) + *@param havingEntityCondition The EntityCondition object that specifies how to constrain this query after any groupings are done (if this is a view entity with group-by aliases) + *@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived + *@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending + *@param findOptions An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details. + *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE + * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. + */ + public EntityListIterator findListIteratorByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, + EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) + throws GenericEntityException { + return genericDAO.selectListIteratorByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); + } + + public List findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, + ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException { + return genericDAO.selectByMultiRelation(value, modelRelationOne, modelEntityOne, modelRelationTwo, modelEntityTwo, orderBy); + } + + public long findCountByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException { + return genericDAO.selectCountByCondition(delegator, modelEntity, whereEntityCondition, havingEntityCondition, findOptions); + } + + + /** Read only, no remove realize on the database + *@return 0 + */ + public int removeByCondition(Delegator delegator, ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { + return 0; + } + + /** Read only, no store realize on the database + *@return 0 + */ + public int store(GenericValue value) throws GenericEntityException { + return 0; + } + + /** Read only, no store realize on the database + *@return 0 + */ + public int storeByCondition(Delegator delegator, ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException { + return 0; + } + + /** Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server + *@param modelEntities Map of entityName names and ModelEntity values + *@param messages List to put any result messages in + *@param addMissing Flag indicating whether or not to add missing entities and fields on the server by force to false on read only mode + */ + public void checkDataSource(Map modelEntities, List messages, boolean addMissing) throws GenericEntityException { + genericDAO.checkDb(modelEntities, messages, false); + } +}