001: /*******************************************************************************
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: *******************************************************************************/package org.ofbiz.entity.datasource;
019:
020: import java.util.Collection;
021: import java.util.List;
022: import java.util.Map;
023: import java.util.Set;
024:
025: import org.ofbiz.entity.GenericEntityException;
026: import org.ofbiz.entity.GenericPK;
027: import org.ofbiz.entity.GenericValue;
028: import org.ofbiz.entity.condition.EntityCondition;
029: import org.ofbiz.entity.model.ModelEntity;
030: import org.ofbiz.entity.model.ModelRelation;
031: import org.ofbiz.entity.util.EntityFindOptions;
032: import org.ofbiz.entity.util.EntityListIterator;
033:
034: /**
035: * Generic Entity Helper Class
036: *
037: */
038: public interface GenericHelper {
039:
040: /** Gets the name of the server configuration that corresponds to this helper
041: *@return server configuration name
042: */
043: public String getHelperName();
044:
045: /** Creates a Entity in the form of a GenericValue and write it to the database
046: *@return GenericValue instance containing the new instance
047: */
048: public GenericValue create(GenericValue value)
049: throws GenericEntityException;
050:
051: /** Find a Generic Entity by its Primary Key
052: *@param primaryKey The primary key to find by.
053: *@return The GenericValue corresponding to the primaryKey
054: */
055: public GenericValue findByPrimaryKey(GenericPK primaryKey)
056: throws GenericEntityException;
057:
058: /** Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names)
059: *@param primaryKey The primary key to find by.
060: *@param keys The keys, or names, of the values to retrieve; only these values will be retrieved
061: *@return The GenericValue corresponding to the primaryKey
062: */
063: public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey,
064: Set keys) throws GenericEntityException;
065:
066: /** Find a number of Generic Value objects by their Primary Keys, all at once
067: *@param primaryKeys A List of primary keys to find by.
068: *@return List of GenericValue objects corresponding to the passed primaryKey objects
069: */
070: public List findAllByPrimaryKeys(List primaryKeys)
071: throws GenericEntityException;
072:
073: /** Remove a Generic Entity corresponding to the primaryKey
074: *@param primaryKey The primary key of the entity to remove.
075: *@return int representing number of rows effected by this operation
076: */
077: public int removeByPrimaryKey(GenericPK primaryKey)
078: throws GenericEntityException;
079:
080: public List findByMultiRelation(GenericValue value,
081: ModelRelation modelRelationOne, ModelEntity modelEntityOne,
082: ModelRelation modelRelationTwo, ModelEntity modelEntityTwo,
083: List orderBy) throws GenericEntityException;
084:
085: /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details.
086: *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
087: *@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)
088: *@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)
089: *@param fieldsToSelect The fields of the named entity to get from the database; if empty or null all fields will be retreived
090: *@param orderBy The fields of the named entity to order the query by; optionally add a " ASC" for ascending or " DESC" for descending
091: *@param findOptions An instance of EntityFindOptions that specifies advanced query options. See the EntityFindOptions JavaDoc for more details.
092: *@return EntityListIterator representing the result of the query: NOTE THAT THIS MUST BE CLOSED WHEN YOU ARE
093: * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION.
094: */
095: public EntityListIterator findListIteratorByCondition(
096: ModelEntity modelEntity,
097: EntityCondition whereEntityCondition,
098: EntityCondition havingEntityCondition,
099: Collection fieldsToSelect, List orderBy,
100: EntityFindOptions findOptions)
101: throws GenericEntityException;
102:
103: public long findCountByCondition(ModelEntity modelEntity,
104: EntityCondition whereEntityCondition,
105: EntityCondition havingEntityCondition,
106: EntityFindOptions findOptions)
107: throws GenericEntityException;
108:
109: /** Removes/deletes Generic Entity records found by all the specified condition
110: *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
111: *@param condition The condition that restricts the list of removed values
112: *@return int representing number of rows effected by this operation
113: */
114: public int removeByCondition(ModelEntity modelEntity,
115: EntityCondition condition) throws GenericEntityException;
116:
117: /** Stores a group of values in a single query
118: *@param modelEntity The ModelEntity of the Entity as defined in the entity XML file
119: *@param fieldsToSet The fields of the named entity to set in the database
120: *@param condition The condition that restricts the list of updated values
121: *@return int representing number of rows effected by this operation
122: *@throws GenericEntityException
123: */
124: public int storeByCondition(ModelEntity modelEntity,
125: Map fieldsToSet, EntityCondition condition)
126: throws GenericEntityException;
127:
128: /** Store the Entity from the GenericValue to the persistent store
129: *@param value GenericValue instance containing the entity
130: *@return int representing number of rows effected by this operation
131: */
132: public int store(GenericValue value) throws GenericEntityException;
133:
134: /** Check the datasource to make sure the entity definitions are correct, optionally adding missing entities or fields on the server
135: *@param modelEntities Map of entityName names and ModelEntity values
136: *@param messages List to put any result messages in
137: *@param addMissing Flag indicating whether or not to add missing entities and fields on the server
138: */
139: public void checkDataSource(Map modelEntities, List messages,
140: boolean addMissing) throws GenericEntityException;
141: }
|