/** Gets the an instance of helper that corresponds to this delegator and the specified entity *@param entity The entity to get the helper for *@return GenericHelper that corresponds to this delegator and the specified entity */ public GenericHelper getEntityHelper(ModelEntity entity) throws GenericEntityException { return getEntityHelper(entity.getEntityName()); }
/** Gets the an instance of helper that corresponds to this delegator and the specified entity *@param entity The entity to get the helper for *@return GenericHelper that corresponds to this delegator and the specified entity */ public GenericHelper getEntityHelper(ModelEntity entity) throws GenericEntityException { return getEntityHelper(entity.getEntityName()); }
/** * Gets the helper that corresponds to this delegator and the specified entity. * * @param entity The entity for which to get the helper (required) * @return GenericHelper that corresponds to this delegator and the specified entity */ public GenericHelper getEntityHelper(final ModelEntity entity) throws GenericEntityException { checkIfLocked(); return getEntityHelper(entity.getEntityName()); }
protected String getSchemaName() { try { final GenericHelper helper = getDelegator().getEntityHelper("User"); return EntityConfigUtil.getInstance().getDatasourceInfo(helper.getHelperName()).getSchemaName(); } catch (GenericEntityException ex) { throw new RuntimeException(ex); } }
@Override public void doUpgrade(boolean setupMode) throws Exception { final GenericDelegator delegator = getDelegator(); final String helperName = delegator.getEntityHelper(AUDIT_ITEM_ENTITY).getHelperName(); final ModelEntity entity = delegator.getModelEntity(AUDIT_ITEM_ENTITY); final String tableName = entity.getPlainTableName(); final DatabaseUtil dbUtil = new DatabaseUtil(helperName); final List<String> messages = Lists.newArrayList(); final Map<String, Set<String>> indexes = dbUtil.getIndexInfo(ImmutableSet.of(tableName), messages, true); final String oldIndexName = "idx_audit_item_log_id"; if (indexes != null && indexes.get(tableName) != null) { for(String index : indexes.get(tableName)) { if (oldIndexName.equalsIgnoreCase(index)) { dropIndex(tableName, oldIndexName); break; } } } } }
public List findByAnd(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException { GenericValue dummyValue = new GenericValue(modelEntity); Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName()); GenericHelper helper = getEntityHelper(modelEntity); if (fields != null && !modelEntity.areFields(fields.keySet())) { throw new GenericModelException("At least one of the passed fields is not valid: " + fields.keySet().toString()); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); List list = null; list = helper.findByAnd(modelEntity, fields, orderBy); absorbList(list); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); return list; }
public List findByAnd(ModelEntity modelEntity, Map fields, List orderBy) throws GenericEntityException { GenericValue dummyValue = new GenericValue(modelEntity); Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName()); GenericHelper helper = getEntityHelper(modelEntity); if (fields != null && !modelEntity.areFields(fields.keySet())) { throw new GenericModelException("At least one of the passed fields is not valid: " + fields.keySet().toString()); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); List list = null; list = helper.findByAnd(modelEntity, fields, orderBy); absorbList(list); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); return list; }
/** * Remove a Generic Entity corresponding to the primaryKey. * * @param primaryKey The primary key of the entity to remove. * @param doCacheClear boolean that specifies whether to clear cache entries for this primaryKey to be removed * @return int representing number of rows affected by this operation */ public int removeByPrimaryKey(final GenericPK primaryKey, final boolean doCacheClear) throws GenericEntityException { checkIfLocked(); if (doCacheClear) { // always clear cache before the operation clearCacheLine(primaryKey); } final GenericHelper helper = getEntityHelper(primaryKey.getEntityName()); return helper.removeByPrimaryKey(primaryKey); }
protected Connection getDatabaseConnection() { try { GenericHelper helper = getDelegator().getEntityHelper("User"); DatabaseUtil utils = new DatabaseUtil(helper.getHelperName()); return utils.getConnection(); } catch (SQLException | GenericEntityException ex) { throw new DataAccessException("Unable to obtain a DB connection", ex); } }
@Override public List<GenericValue> transform(final String entityName, final EntityCondition entityCondition, final List<String> orderBy, final String lockField, final Transformation transformation) throws GenericEntityException { checkIfLocked(); final ModelEntity modelEntity = getModelReader().getModelEntity(entityName); final GenericHelper entityHelper = getEntityHelper(entityName); final List<GenericValue> transformedEntities = entityHelper.transform(modelEntity, entityCondition, orderBy, lockField, transformation); for (final GenericValue genericValue : transformedEntities) { genericValue.setDelegator(this); } return transformedEntities; }
/** * Remove a Generic Value from the database. * * @param value The GenericValue object of the entity to remove. * @param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed * @return int representing number of rows affected by this operation */ public int removeValue(final GenericValue value, final boolean doCacheClear) throws GenericEntityException { checkIfLocked(); final GenericHelper helper = getEntityHelper(value.getEntityName()); if (doCacheClear) { clearCacheLine(value); } return helper.removeByPrimaryKey(value.getPrimaryKey()); }
/** Finds Generic Entity records by all of the specified fields (ie: combined using OR) * @param entityName The Name of the Entity as defined in the entity XML file * @param fields The fields of the named entity to query by with their corresponging values * @param order The fields of the named entity to order the query by; * optionally add a " ASC" for ascending or " DESC" for descending * @return List of GenericValue instances that match the query */ public List findByOr(String entityName, Map fields, List orderBy) throws GenericEntityException { ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericValue dummyValue = new GenericValue(modelEntity); Map ecaEventMap = this.getEcaEntityEventMap(modelEntity.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, dummyValue, null, false, false); GenericHelper helper = getEntityHelper(entityName); if (fields != null && !modelEntity.areFields(fields.keySet())) { throw new IllegalArgumentException("[GenericDelegator.findByOr] At least of the passed fields is not valid: " + fields.keySet().toString()); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); List list = null; list = helper.findByOr(modelEntity, fields, orderBy); absorbList(list); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); return list; }
/** Remove a Generic Entity corresponding to the primaryKey *@param primaryKey The primary key of the entity to remove. *@param doCacheClear boolean that specifies whether to clear cache entries for this primaryKey to be removed *@return int representing number of rows effected by this operation */ public int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(primaryKey.getEntityName()); if (doCacheClear) { // always clear cache before the operation this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(primaryKey); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByPrimaryKey(primaryKey); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Remove a Generic Entity corresponding to the primaryKey *@param primaryKey The primary key of the entity to remove. *@param doCacheClear boolean that specifies whether to clear cache entries for this primaryKey to be removed *@return int representing number of rows effected by this operation */ public int removeByPrimaryKey(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(primaryKey.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(primaryKey.getEntityName()); if (doCacheClear) { // always clear cache before the operation this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(primaryKey); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByPrimaryKey(primaryKey); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, primaryKey, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Remove a Generic Value from the database *@param value The GenericValue object of the entity to remove. *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed *@return int representing number of rows effected by this operation */ public int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(value.getEntityName()); if (doCacheClear) { this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(value); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByPrimaryKey(value.getPrimaryKey()); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Remove a Generic Value from the database *@param value The GenericValue object of the entity to remove. *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed *@return int representing number of rows effected by this operation */ public int removeValue(GenericValue value, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(value.getEntityName()); if (doCacheClear) { this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(value); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByPrimaryKey(value.getPrimaryKey()); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, value, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. *@param entityName The Name of the Entity as defined in the entity model XML file *@param entityCondition The EntityCondition object that specifies how to constrain this query *@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 *@return List of GenericValue objects representing the result */ public List findByCondition(String entityName, EntityCondition entityCondition, Collection fieldsToSelect, List orderBy) throws GenericEntityException { ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericValue dummyValue = new GenericValue(modelEntity); Map ecaEventMap = this.getEcaEntityEventMap(entityName); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); if (entityCondition != null) entityCondition.checkCondition(modelEntity); this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(entityName); List list = null; list = helper.findByCondition(modelEntity, entityCondition, fieldsToSelect, orderBy); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_FIND, dummyValue, ecaEventMap, (ecaEventMap == null), false); absorbList(list); return list; }
/** Removes/deletes Generic Entity records found by all of the specified fields (ie: combined using AND) *@param entityName The Name of the Entity as defined in the entity XML file *@param fields The fields of the named entity to query by with their corresponging values *@param doCacheClear boolean that specifies whether to clear cache entries for this value to be removed *@return int representing number of rows effected by this operation */ public int removeByAnd(String entityName, Map fields, boolean doCacheClear) throws GenericEntityException { GenericValue dummyValue = makeValue(entityName, fields); Map ecaEventMap = this.getEcaEntityEventMap(entityName); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); ModelEntity modelEntity = getModelReader().getModelEntity(entityName); GenericHelper helper = getEntityHelper(entityName); if (doCacheClear) { // always clear cache before the operation this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(entityName, fields); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); int num = helper.removeByAnd(modelEntity, dummyValue.getAllFields()); this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_REMOVE, dummyValue, ecaEventMap, (ecaEventMap == null), false); return num; }
/** Store the Entity from the GenericValue to the persistent store *@param value GenericValue instance containing the entity *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation *@return int representing number of rows effected by this operation */ public int store(GenericValue value, boolean doCacheClear) throws GenericEntityException { Map ecaEventMap = this.getEcaEntityEventMap(value.getEntityName()); this.evalEcaRules(EntityEcaHandler.EV_VALIDATE, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); GenericHelper helper = getEntityHelper(value.getEntityName()); if (doCacheClear) { // always clear cache before the operation this.evalEcaRules(EntityEcaHandler.EV_CACHE_CLEAR, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); this.clearCacheLine(value); } this.evalEcaRules(EntityEcaHandler.EV_RUN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); int retVal = helper.store(value); // refresh the valueObject to get the new version if (value.lockEnabled()) { refresh(value, doCacheClear); } this.evalEcaRules(EntityEcaHandler.EV_RETURN, EntityEcaHandler.OP_STORE, value, ecaEventMap, (ecaEventMap == null), false); return retVal; }
@Override public void doUpgrade(boolean setupMode) throws Exception { GenericHelper helper = getDelegator().getEntityHelper("Issue"); DatabaseUtil dbUtil = new DatabaseUtil(helper.getHelperName()); ModelEntity issueEntity = getDelegator().getModelEntity("Issue"); ModelIndex projNumIndex = new ModelIndex(); projNumIndex.setName("issue_proj_num"); projNumIndex.setMainEntity(issueEntity); projNumIndex.setUnique(true); projNumIndex.addIndexField("number"); projNumIndex.addIndexField("project"); dropIndex(dbUtil, issueEntity, projNumIndex); createIndex(dbUtil, issueEntity, projNumIndex); }