1 25 package org.ofbiz.entity.datasource; 26 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.LinkedList ; 30 import java.util.List ; 31 import java.util.Map ; 32 import java.util.Set ; 33 34 import org.ofbiz.base.util.Debug; 35 import org.ofbiz.entity.GenericEntityException; 36 import org.ofbiz.entity.GenericPK; 37 import org.ofbiz.entity.GenericValue; 38 import org.ofbiz.entity.condition.EntityCondition; 39 import org.ofbiz.entity.model.ModelEntity; 40 import org.ofbiz.entity.model.ModelRelation; 41 import org.ofbiz.entity.util.EntityFindOptions; 42 import org.ofbiz.entity.util.EntityListIterator; 43 44 52 public class GenericHelperDAO implements GenericHelper { 53 54 public static final String module = GenericHelperDAO.class.getName(); 55 56 protected GenericDAO genericDAO; 57 protected String helperName; 58 59 public GenericHelperDAO(String helperName) { 60 this.helperName = helperName; 61 genericDAO = GenericDAO.getGenericDAO(helperName); 62 } 63 64 public String getHelperName() { 65 return helperName; 66 } 67 68 71 public GenericValue create(GenericValue value) throws GenericEntityException { 72 if (value == null) { 73 return null; 74 } 75 int retVal = genericDAO.insert(value); 76 if (Debug.verboseOn()) Debug.logVerbose("Insert Return Value : " + retVal, module); 77 return value; 78 } 79 80 84 public GenericValue findByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { 85 if (primaryKey == null) { 86 return null; 87 } 88 GenericValue genericValue = GenericValue.create(primaryKey); 89 90 genericDAO.select(genericValue); 91 return genericValue; 92 } 93 94 99 public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set keys) throws GenericEntityException { 100 if (primaryKey == null) { 101 return null; 102 } 103 GenericValue genericValue = GenericValue.create(primaryKey); 104 105 genericDAO.partialSelect(genericValue, keys); 106 return genericValue; 107 } 108 109 115 public List findAllByPrimaryKeys(List primaryKeys) throws GenericEntityException { 116 if (primaryKeys == null) return null; 117 List results = new LinkedList (); 118 119 Iterator pkiter = primaryKeys.iterator(); 120 121 while (pkiter.hasNext()) { 122 GenericPK primaryKey = (GenericPK) pkiter.next(); 123 GenericValue result = this.findByPrimaryKey(primaryKey); 124 125 if (result != null) results.add(result); 126 } 127 return results; 128 } 129 130 134 public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException { 135 if (primaryKey == null) return 0; 136 if (Debug.verboseOn()) Debug.logVerbose("Removing GenericPK: " + primaryKey.toString(), module); 137 return genericDAO.delete(primaryKey); 138 } 139 140 150 public EntityListIterator findListIteratorByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, 151 EntityCondition havingEntityCondition, Collection fieldsToSelect, List orderBy, EntityFindOptions findOptions) 152 throws GenericEntityException { 153 return genericDAO.selectListIteratorByCondition(modelEntity, whereEntityCondition, havingEntityCondition, fieldsToSelect, orderBy, findOptions); 154 } 155 156 public List findByMultiRelation(GenericValue value, ModelRelation modelRelationOne, ModelEntity modelEntityOne, 157 ModelRelation modelRelationTwo, ModelEntity modelEntityTwo, List orderBy) throws GenericEntityException { 158 return genericDAO.selectByMultiRelation(value, modelRelationOne, modelEntityOne, modelRelationTwo, modelEntityTwo, orderBy); 159 } 160 161 public long findCountByCondition(ModelEntity modelEntity, EntityCondition whereEntityCondition, EntityCondition havingEntityCondition) throws GenericEntityException { 162 return genericDAO.selectCountByCondition(modelEntity, whereEntityCondition, havingEntityCondition); 163 } 164 165 170 public int removeByCondition(ModelEntity modelEntity, EntityCondition condition) throws GenericEntityException { 171 if (modelEntity == null || condition == null) { 172 return 0; 173 } 174 return genericDAO.deleteByCondition(modelEntity, condition); 175 } 176 177 181 public int store(GenericValue value) throws GenericEntityException { 182 if (value == null) { 183 return 0; 184 } 185 return genericDAO.update(value); 186 } 187 188 195 public int storeByCondition(ModelEntity modelEntity, Map fieldsToSet, EntityCondition condition) throws GenericEntityException { 196 if (modelEntity == null || condition == null) { 197 return 0; 198 } 199 return genericDAO.updateByCondition(modelEntity, fieldsToSet, condition); 200 } 201 202 207 public void checkDataSource(Map modelEntities, List messages, boolean addMissing) throws GenericEntityException { 208 genericDAO.checkDb(modelEntities, messages, addMissing); 209 } 210 } 211 | Popular Tags |