Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,107 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.ofbiz.context.entity; + + +import java.util.List; +import java.util.ListIterator; + + +/** + * Generic Entity Cursor List Iterator for Handling Cursored DB Results + */ +public interface EntityListIterator extends ListIterator<GenericValue> { + + public void setDelegator(GenericDelegator delegator); + + /** Sets the cursor position to just after the last result so that previous() will return the last result */ + public void afterLast() throws GenericEntityException; + + /** Sets the cursor position to just before the first result so that next() will return the first result */ + public void beforeFirst() throws GenericEntityException; + + /** Sets the cursor position to last result; if result set is empty returns false */ + public boolean last() throws GenericEntityException; + + /** Sets the cursor position to last result; if result set is empty returns false */ + public boolean first() throws GenericEntityException; + + public void close() throws GenericEntityException; + + /** NOTE: Calling this method does return the current value, but so does calling next() or previous(), so calling one of those AND this method will cause the value to be created twice */ + public GenericValue currentGenericValue() throws GenericEntityException; + + public int currentIndex() throws GenericEntityException; + + /** performs the same function as the ResultSet.absolute method; + * if rowNum is positive, goes to that position relative to the beginning of the list; + * if rowNum is negative, goes to that position relative to the end of the list; + * a rowNum of 1 is the same as first(); a rowNum of -1 is the same as last() + */ + public boolean absolute(int rowNum) throws GenericEntityException; + + /** performs the same function as the ResultSet.relative method; + * if rows is positive, goes forward relative to the current position; + * if rows is negative, goes backward relative to the current position; + */ + public boolean relative(int rows) throws GenericEntityException; + + /** + * PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient; it is much better to just use next() until it returns null + * For example, you could use the following to iterate through the results in an EntityListIterator: + * + * GenericValue nextValue = null; + * while ((nextValue = (GenericValue) this.next()) != null) { ... } + * + */ + public boolean hasNext(); + + /** PLEASE NOTE: Because of the nature of the JDBC ResultSet interface this method can be very inefficient; it is much better to just use previous() until it returns null */ + public boolean hasPrevious(); + + /** Moves the cursor to the next position and returns the GenericValue object for that position; if there is no next, returns null + * For example, you could use the following to iterate through the results in an EntityListIterator: + * + * GenericValue nextValue = null; + * while ((nextValue = (GenericValue) this.next()) != null) { ... } + * + */ + public GenericValue next(); + + /** Returns the index of the next result, but does not guarantee that there will be a next result */ + public int nextIndex(); + + /** Moves the cursor to the previous position and returns the GenericValue object for that position; if there is no previous, returns null */ + public GenericValue previous(); + + /** Returns the index of the previous result, but does not guarantee that there will be a previous result */ + public int previousIndex(); + + public void setFetchSize(int rows) throws GenericEntityException; + + public List<GenericValue> getCompleteList() throws GenericEntityException; + + /** Gets a partial list of results starting at start and containing at most number elements. + * Start is a one based value, ie 1 is the first element. + */ + public List<GenericValue> getPartialList(int start, int number) throws GenericEntityException; + + public int getResultsSizeAfterPartialList() throws GenericEntityException; +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/EntityListIterator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,706 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ofbiz.context.entity; + +import java.net.URL; +import java.util.Collection; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.xml.sax.SAXException; + +/** + * Delegator Interface + */ +public interface GenericDelegator { + + public String getDelegatorName(); + + /** Gets the name of the server configuration that corresponds to this delegator + * @return server configuration name + */ + public String getOriginalDelegatorName(); + + public ModelEntityInterface getModelEntity(String entityName); + + /** Gets the helper name that corresponds to this delegator and the specified entityName + *@param entityName The name of the entity to get the helper for + *@return String with the helper name that corresponds to this delegator and the specified entityName + */ + public String getEntityGroupName(String entityName); + + /** Gets the helper name that corresponds to this delegator and the specified entityName + *@param groupName The name of the group to get the helper name for + *@return String with the helper name that corresponds to this delegator and the specified entityName + */ + public String getGroupHelperName(String groupName); + + /** Gets the helper name that corresponds to this delegator and the specified entityName + *@param entityName The name of the entity to get the helper name for + *@return String with the helper name that corresponds to this delegator and the specified entityName + */ + public String getEntityHelperName(String entityName); + + /** Creates a Entity in the form of a GenericValue without persisting it */ + public GenericValue makeValue(String entityName); + + /** Creates a Entity in the form of a GenericValue without persisting it */ + public GenericValue makeValue(String entityName, Object... fields); + + /** Creates a Entity in the form of a GenericValue without persisting it */ + public GenericValue makeValue(String entityName, Map<String, ? extends Object> fields); + + /** Creates a Entity in the form of a GenericValue without persisting it */ + public GenericValue makeValueSingle(String entityName, Object singlePkValue); + + /** Creates a Entity in the form of a GenericValue without persisting it; only valid fields will be pulled from the fields Map */ + public GenericValue makeValidValue(String entityName, Object... fields); + + /** Creates a Entity in the form of a GenericValue without persisting it; only valid fields will be pulled from the fields Map */ + public GenericValue makeValidValue(String entityName, Map<String, ? extends Object> fields); + + /** Creates a Primary Key in the form of a GenericPK without persisting it */ + public GenericPK makePK(String entityName); + + /** Creates a Primary Key in the form of a GenericPK without persisting it */ + public GenericPK makePK(String entityName, Object... fields); + + /** Creates a Primary Key in the form of a GenericPK without persisting it */ + public GenericPK makePK(String entityName, Map<String, ? extends Object> fields); + + /** Creates a Primary Key in the form of a GenericPK without persisting it */ + public GenericPK makePKSingle(String entityName, Object singlePkValue); + + /** Creates a Entity in the form of a GenericValue and write it to the datasource + *@param primaryKey The GenericPK to create a value in the datasource from + *@return GenericValue instance containing the new instance + */ + public GenericValue create(GenericPK primaryKey) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the datasource + *@param primaryKey The GenericPK to create a value in the datasource from + *@param doCacheClear boolean that specifies whether to clear related cache entries for this primaryKey to be created + *@return GenericValue instance containing the new instance + */ + public GenericValue create(GenericPK primaryKey, boolean doCacheClear) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the database + *@return GenericValue instance containing the new instance + */ + public GenericValue create(String entityName, Object... fields) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the database + *@return GenericValue instance containing the new instance + */ + public GenericValue create(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the database + *@return GenericValue instance containing the new instance + */ + public GenericValue createSingle(String entityName, Object singlePkValue) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the datasource + *@param value The GenericValue to create a value in the datasource from + *@return GenericValue instance containing the new instance + */ + public GenericValue create(GenericValue value) throws GenericEntityException; + + /** Sets the sequenced ID (for entity with one primary key field ONLY), and then does a create in the database + * as normal. The reason to do it this way is that it will retry and fix the sequence if somehow the sequencer + * is in a bad state and returning a value that already exists. + *@param value The GenericValue to create a value in the datasource from + *@return GenericValue instance containing the new instance + */ + public GenericValue createSetNextSeqId(GenericValue value) throws GenericEntityException; + + /** Creates a Entity in the form of a GenericValue and write it to the datasource + *@param value The GenericValue to create a value in the datasource from + *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation + *@return GenericValue instance containing the new instance + */ + public GenericValue create(GenericValue value, boolean doCacheClear) throws GenericEntityException; + + /** Creates or stores an Entity + *@param value The GenericValue instance containing the new or existing instance + *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation + *@return GenericValue instance containing the new or updated instance + */ + public GenericValue createOrStore(GenericValue value, boolean doCacheClear) throws GenericEntityException; + + /** Creates or stores an Entity + *@param value The GenericValue instance containing the new or existing instance + *@return GenericValue instance containing the new or updated instance + */ + public GenericValue createOrStore(GenericValue value) throws GenericEntityException; + + /** Remove a Generic Entity corresponding to the primaryKey + *@param primaryKey The primary key of the entity to remove. + *@return int representing number of rows effected by this operation + */ + public int removeByPrimaryKey(GenericPK primaryKey) throws GenericEntityException; + + /** 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; + + /** Remove a Generic Value from the database + *@param value The GenericValue object of the entity to remove. + *@return int representing number of rows effected by this operation + */ + public int removeValue(GenericValue value) throws GenericEntityException; + + /** 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; + + /** 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 corresponding values + *@return int representing number of rows effected by this operation + */ + public int removeByAnd(String entityName, Object... fields) throws GenericEntityException; + + /** 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 corresponding values + *@return int representing number of rows effected by this operation + */ + public int removeByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** 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 doCacheClear boolean that specifies whether to clear cache entries for this value to be removed + *@param fields The fields of the named entity to query by with their corresponding values + *@return int representing number of rows effected by this operation + */ + public int removeByAnd(String entityName, boolean doCacheClear, Object... fields) throws GenericEntityException; + + /** 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 corresponding 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<String, ? extends Object> fields, boolean doCacheClear) throws GenericEntityException; + + /** Removes/deletes Generic Entity records found by the condition + *@param entityName The Name of the Entity as defined in the entity XML file + *@param condition The condition used to restrict the removing + *@return int representing number of rows effected by this operation + */ + public int removeByCondition(String entityName, EntityConditionInterface condition) throws GenericEntityException; + + /** Removes/deletes Generic Entity records found by the condition + *@param entityName The Name of the Entity as defined in the entity XML file + *@param condition The condition used to restrict the removing + *@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 removeByCondition(String entityName, EntityConditionInterface condition, boolean doCacheClear) throws GenericEntityException; + + /** Remove the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + *@param value GenericValue instance containing the entity + *@return int representing number of rows effected by this operation + */ + public int removeRelated(String relationName, GenericValue value) throws GenericEntityException; + + /** Remove the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + *@param value GenericValue instance containing the entity + *@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 removeRelated(String relationName, GenericValue value, boolean doCacheClear) throws GenericEntityException; + + /** Refresh the Entity for the GenericValue from the persistent store + *@param value GenericValue instance containing the entity to refresh + */ + public void refresh(GenericValue value) throws GenericEntityException; + + /** Refresh the Entity for the GenericValue from the persistent store + *@param value GenericValue instance containing the entity to refresh + *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation + */ + public void refresh(GenericValue value, boolean doCacheClear) throws GenericEntityException; + + /** Refresh the Entity for the GenericValue from the cache + *@param value GenericValue instance containing the entity to refresh + */ + public void refreshFromCache(GenericValue value) throws GenericEntityException; + + /** Store a group of values + *@param entityName The name of the Entity as defined in the entity XML file + *@param fieldsToSet The fields of the named entity to set in the database + *@param condition The condition that restricts the list of stored values + *@return int representing number of rows effected by this operation + *@throws GenericEntityException + */ + public int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityConditionInterface condition) throws GenericEntityException; + + /** Store a group of values + *@param entityName The name of the Entity as defined in the entity XML file + *@param fieldsToSet The fields of the named entity to set in the database + *@param condition The condition that restricts the list of stored values + *@param doCacheClear boolean that specifies whether to clear cache entries for these values + *@return int representing number of rows effected by this operation + *@throws GenericEntityException + */ + public int storeByCondition(String entityName, Map<String, ? extends Object> fieldsToSet, EntityConditionInterface condition, boolean doCacheClear) throws GenericEntityException; + + /** Store the Entity from the GenericValue to the persistent store + *@param value GenericValue instance containing the entity + *@return int representing number of rows effected by this operation + */ + public int store(GenericValue value) throws GenericEntityException; + + /** 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; + + /** Store the Entities from the List GenericValue instances to the persistent store. + * <br/>This is different than the normal store method in that the store method only does + * an update, while the storeAll method checks to see if each entity exists, then + * either does an insert or an update as appropriate. + * <br/>These updates all happen in one transaction, so they will either all succeed or all fail, + * if the data source supports transactions. This is just like to othersToStore feature + * of the GenericEntity on a create or store. + *@param values List of GenericValue instances containing the entities to store + *@return int representing number of rows effected by this operation + */ + public int storeAll(List<GenericValue> values) throws GenericEntityException; + + /** Store the Entities from the List GenericValue instances to the persistent store. + * <br/>This is different than the normal store method in that the store method only does + * an update, while the storeAll method checks to see if each entity exists, then + * either does an insert or an update as appropriate. + * <br/>These updates all happen in one transaction, so they will either all succeed or all fail, + * if the data source supports transactions. This is just like to othersToStore feature + * of the GenericEntity on a create or store. + *@param values List of GenericValue instances containing the entities to store + *@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 storeAll(List<GenericValue> values, boolean doCacheClear) throws GenericEntityException; + + /** Store the Entities from the List GenericValue instances to the persistent store. + * <br/>This is different than the normal store method in that the store method only does + * an update, while the storeAll method checks to see if each entity exists, then + * either does an insert or an update as appropriate. + * <br/>These updates all happen in one transaction, so they will either all succeed or all fail, + * if the data source supports transactions. This is just like to othersToStore feature + * of the GenericEntity on a create or store. + *@param values List of GenericValue instances containing the entities to store + *@param doCacheClear boolean that specifies whether or not to automatically clear cache entries related to this operation + *@param createDummyFks boolean that specifies whether or not to automatically create "dummy" place holder FKs + *@return int representing number of rows effected by this operation + */ + public int storeAll(List<GenericValue> values, boolean doCacheClear, boolean createDummyFks) throws GenericEntityException; + + public int removeAll(String entityName) throws GenericEntityException; + + /** Remove the Entities from the List from the persistent store. + * <br/>The List contains GenericEntity objects, can be either GenericPK or GenericValue. + * <br/>If a certain entity contains a complete primary key, the entity in the datasource corresponding + * to that primary key will be removed, this is like a removeByPrimary Key. + * <br/>On the other hand, if a certain entity is an incomplete or non primary key, + * if will behave like the removeByAnd method. + * <br/>These updates all happen in one transaction, so they will either all succeed or all fail, + * if the data source supports transactions. + *@param dummyPKs Collection of GenericEntity instances containing the entities or by and fields to remove + *@return int representing number of rows effected by this operation + */ + public int removeAll(List<? extends GenericEntity> dummyPKs) throws GenericEntityException; + + /** Remove the Entities from the List from the persistent store. + * <br/>The List contains GenericEntity objects, can be either GenericPK or GenericValue. + * <br/>If a certain entity contains a complete primary key, the entity in the datasource corresponding + * to that primary key will be removed, this is like a removeByPrimary Key. + * <br/>On the other hand, if a certain entity is an incomplete or non primary key, + * if will behave like the removeByAnd method. + * <br/>These updates all happen in one transaction, so they will either all succeed or all fail, + * if the data source supports transactions. + *@param dummyPKs Collection of GenericEntity instances containing the entities or by and fields to remove + *@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 removeAll(List<? extends GenericEntity> dummyPKs, boolean doCacheClear) throws GenericEntityException; + + // ====================================== + // ======= Find Methods ================= + // ====================================== + + /** Find a Generic Entity by its Primary Key + * NOTE 20080502: 6 references + *@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 corresponding values + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findOne(String entityName, boolean useCache, Object... fields) throws GenericEntityException; + + /** Find a Generic Entity by its Primary Key + * NOTE 20080502: 6 references + *@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 corresponding values + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findOne(String entityName, Map<String, ? extends Object> fields, boolean useCache) throws GenericEntityException; + + /** Find a Generic Entity by its Primary Key + * NOTE 20080502: 550 references (20080503 521 left); needs to be deprecated, should use findOne instead, but lots of stuff to replace! + *@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 corresponding values + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findByPrimaryKey(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Find a CACHED Generic Entity by its Primary Key + * NOTE 20080502: 2 references + *@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 corresponding values + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findByPrimaryKeyCache(String entityName, Object... fields) throws GenericEntityException; + + /** Find a CACHED Generic Entity by its Primary Key + * NOTE 20080502: 218 references + *@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 corresponding values + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findByPrimaryKeyCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Find a Generic Entity by its Primary Key and only returns the values requested by the passed keys (names) + * NOTE 20080502: 3 references + *@param primaryKey The primary key to find by. + *@param keys The keys, or names, of the values to retrieve; only these values will be retrieved + *@return The GenericValue corresponding to the primaryKey + */ + public GenericValue findByPrimaryKeyPartial(GenericPK primaryKey, Set<String> keys) throws GenericEntityException; + + /** Finds Generic Entity records by all of the specified fields (ie: combined using AND) + * NOTE 20080502: 1 references + * @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 corresponding values + * @return List of GenericValue instances that match the query + */ + public List<GenericValue> findByAnd(String entityName, Object... fields) throws GenericEntityException; + + /** Finds Generic Entity records by all of the specified fields (ie: combined using AND) + * NOTE 20080502: 264 references + * @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 corresponding values + * @return List of GenericValue instances that match the query + */ + public List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Finds Generic Entity records by all of the specified fields (ie: combined using AND) + * NOTE 20080502: 72 references + * @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 corresponding values + * @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 instances that match the query + */ + public List<GenericValue> findByAnd(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; + + /** Finds Generic Entity records by all of the specified fields (ie: combined using AND), looking first in the cache; uses orderBy for lookup, but only keys results on the entityName and fields + * NOTE 20080502: 91 references + *@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 corresponding values + *@return List of GenericValue instances that match the query + */ + public List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Finds Generic Entity records by all of the specified fields (ie: combined using AND), looking first in the cache; uses orderBy for lookup, but only keys results on the entityName and fields + * NOTE 20080502: 56 references + *@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 corresponding values + *@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 instances that match the query + */ + public List<GenericValue> findByAndCache(String entityName, Map<String, ? extends Object> fields, List<String> orderBy) throws GenericEntityException; + + /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. + * NOTE 20080502: 3 references + *@param entityName The name 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 (preferably in a finally block) WHEN YOU ARE + * DONE WITH IT, AND DON'T LEAVE IT OPEN TOO LONG BEACUSE IT WILL MAINTAIN A DATABASE CONNECTION. + */ + public EntityListIterator find(String entityName, EntityConditionInterface whereEntityCondition, + EntityConditionInterface havingEntityCondition, Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) + throws GenericEntityException; + + /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. + * NOTE 20080502: 12 references + *@param entityName The name of the Entity as defined in the entity XML file + *@param entityCondition 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 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 List of GenericValue objects representing the result + */ + public List<GenericValue> findList(String entityName, EntityConditionInterface entityCondition, + Set<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions, boolean useCache) + throws GenericEntityException; + + /** Finds GenericValues by the conditions specified in the EntityCondition object, the the EntityCondition javadoc for more details. + * NOTE 20080502: 9 references + *@param dynamicViewEntity The DynamicViewEntity to use for the entity model for this query; generally created on the fly for limited use + *@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(DynamicViewEntityInterface dynamicViewEntity, EntityConditionInterface whereEntityCondition, + EntityConditionInterface havingEntityCondition, Collection<String> fieldsToSelect, List<String> orderBy, EntityFindOptions findOptions) + throws GenericEntityException; + + /** + * NOTE 20080502: 2 references + */ + public long findCountByCondition(String entityName, EntityConditionInterface whereEntityCondition, + EntityConditionInterface havingEntityCondition, EntityFindOptions findOptions) throws GenericEntityException; + + /** + * Get the named Related Entity for the GenericValue from the persistent store across another Relation. + * Helps to get related Values in a multi-to-multi relationship. + * NOTE 20080502: 3 references + * @param relationNameOne String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file, for first relation + * @param relationNameTwo String containing the relation name for second relation + * @param value GenericValue instance containing the entity + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + * @return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getMultiRelation(GenericValue value, String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store + * NOTE 20080502: 5 references + * @param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + * @param value GenericValue instance containing the entity + * @return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy, GenericValue value) throws GenericEntityException; + + /** Get a dummy primary key for the named Related Entity for the GenericValue + * NOTE 20080502: 2 references + * @param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @param value GenericValue instance containing the entity + * @return GenericPK containing a possibly incomplete PrimaryKey object representing the related entity or entities + */ + public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields, GenericValue value) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store, checking first in the cache to see if the desired value is there + * NOTE 20080502: 4 references + * @param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + * @param value GenericValue instance containing the entity + * @return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedCache(String relationName, GenericValue value) throws GenericEntityException; + + /** Get related entity where relation is of type one, uses findByPrimaryKey + * NOTE 20080502: 7 references + * @throws IllegalArgumentException if the list found has more than one item + */ + public GenericValue getRelatedOne(String relationName, GenericValue value) throws GenericEntityException; + + /** Get related entity where relation is of type one, uses findByPrimaryKey, checking first in the cache to see if the desired value is there + * NOTE 20080502: 1 references + * @throws IllegalArgumentException if the list found has more than one item + */ + public GenericValue getRelatedOneCache(String relationName, GenericValue value) throws GenericEntityException; + + + // ====================================== + // ======= Cache Related Methods ======== + // ====================================== + + /** This method is a shortcut to completely clear all entity engine caches. + * For performance reasons this should not be called very often. + */ + public void clearAllCaches(); + + public void clearAllCaches(boolean distribute); + + /** Remove all CACHED Generic Entity (List) from the cache + *@param entityName The Name of the Entity as defined in the entity XML file + */ + public void clearCacheLine(String entityName); + + /** Remove a CACHED Generic Entity (List) from the cache, either a PK, ByAnd, or All + *@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 corresponding values + */ + public void clearCacheLine(String entityName, Object... fields); + + /** Remove a CACHED Generic Entity (List) from the cache, either a PK, ByAnd, or All + *@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 corresponding values + */ + public void clearCacheLine(String entityName, Map<String, ? extends Object> fields); + + /** Remove a CACHED Generic Entity from the cache by its primary key. + * Checks to see if the passed GenericPK is a complete primary key, if + * it is then the cache line will be removed from the primaryKeyCache; if it + * is NOT a complete primary key it will remove the cache line from the andCache. + * If the fields map is empty, then the allCache for the entity will be cleared. + *@param dummyPK The dummy primary key to clear by. + */ + public void clearCacheLineFlexible(GenericEntity dummyPK); + + public void clearCacheLineFlexible(GenericEntity dummyPK, boolean distribute); + + public void clearCacheLineByCondition(String entityName, EntityConditionInterface condition); + + public void clearCacheLineByCondition(String entityName, EntityConditionInterface condition, boolean distribute); + + /** Remove a CACHED Generic Entity from the cache by its primary key, does NOT + * check to see if the passed GenericPK is a complete primary key. + * Also tries to clear the corresponding all cache entry. + *@param primaryKey The primary key to clear by. + */ + public void clearCacheLine(GenericPK primaryKey); + + public void clearCacheLine(GenericPK primaryKey, boolean distribute); + + /** Remove a CACHED GenericValue from as many caches as it can. Automatically + * tries to remove entries from the all cache, the by primary key cache, and + * the by and cache. This is the ONLY method that tries to clear automatically + * from the by and cache. + *@param value The GenericValue to clear by. + */ + public void clearCacheLine(GenericValue value); + + public void clearCacheLine(GenericValue value, boolean distribute); + + public void clearAllCacheLinesByDummyPK(Collection<GenericPK> dummyPKs); + + public void clearAllCacheLinesByValue(Collection<GenericValue> values); + + public GenericValue getFromPrimaryKeyCache(GenericPK primaryKey); + + public void putInPrimaryKeyCache(GenericPK primaryKey, GenericValue value); + + public void putAllInPrimaryKeyCache(List<GenericValue> values); + + // ======= XML Related Methods ======== + public List<GenericValue> readXmlDocument(URL url) throws SAXException, ParserConfigurationException, java.io.IOException; + + public List<GenericValue> makeValues(Document document); + + public GenericPK makePK(Element element); + + public GenericValue makeValue(Element element); + + // ======= Misc Methods ======== + + public void setEntityEcaHandler(EntityEcaHandler entityEcaHandler); + + public EntityEcaHandler getEntityEcaHandler(); + + /** Get the next guaranteed unique seq id from the sequence with the given sequence name; + * if the named sequence doesn't exist, it will be created + *@param seqName The name of the sequence to get the next seq id from + *@return String with the next sequenced id for the given sequence name + */ + public String getNextSeqId(String seqName); + + /** Get the next guaranteed unique seq id from the sequence with the given sequence name; + * if the named sequence doesn't exist, it will be created + *@param seqName The name of the sequence to get the next seq id from + *@param staggerMax The maximum amount to stagger the sequenced ID, if 1 the sequence will be incremented by 1, otherwise the current sequence ID will be incremented by a value between 1 and staggerMax + *@return Long with the next seq id for the given sequence name + */ + public String getNextSeqId(String seqName, long staggerMax); + + /** Get the next guaranteed unique seq id from the sequence with the given sequence name; + * if the named sequence doesn't exist, it will be created + *@param seqName The name of the sequence to get the next seq id from + *@return Long with the next sequenced id for the given sequence name + */ + public Long getNextSeqIdLong(String seqName); + + /** Get the next guaranteed unique seq id from the sequence with the given sequence name; + * if the named sequence doesn't exist, it will be created + *@param seqName The name of the sequence to get the next seq id from + *@param staggerMax The maximum amount to stagger the sequenced ID, if 1 the sequence will be incremented by 1, otherwise the current sequence ID will be incremented by a value between 1 and staggerMax + *@return Long with the next seq id for the given sequence name + */ + public Long getNextSeqIdLong(String seqName, long staggerMax); + + /** Refreshes the ID sequencer clearing all cached bank values. */ + public void refreshSequencer(); + + + /** Look at existing values for a sub-entity with a sequenced secondary ID, and get the highest plus 1 */ + public void setNextSubSeqId(GenericValue value, String seqFieldName, int numericPadding, int incrementBy); + + public void encryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + + public void encryptFields(GenericEntity entity) throws GenericEntityException; + + public Object encryptFieldValue(String entityName, Object fieldValue) throws GenericEntityException; + + public void decryptFields(List<? extends GenericEntity> entities) throws GenericEntityException; + + public void decryptFields(GenericEntity entity) throws GenericEntityException; + + public GenericDelegator cloneDelegator(String delegatorName); + + public GenericDelegator cloneDelegator(); +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericDelegator.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,263 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.ofbiz.context.entity; + +import java.io.PrintWriter; +import java.io.Serializable; +import java.math.BigDecimal; +import java.util.Collection; +import java.util.Locale; +import java.util.Map; + +import javolution.lang.Reusable; + +import org.ofbiz.base.util.collections.LocalizedMap; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +/** + * Generic Entity Value Object - Handles persistence for any defined entity. + * <p>Note that this class extends <code>Observable</code> to achieve change notification for + * <code>Observer</code>s. Whenever a field changes the name of the field will be passed to + * the <code>notifyObservers()</code> method, and through that to the <code>update()</code> method of each + * <code>Observer</code>. + * + */ +public interface GenericEntity extends Map<String, Object>, LocalizedMap<Object>, Serializable, Comparable<GenericEntity>, Cloneable, Reusable { + + public void refreshFromValue(GenericEntity newValue) throws GenericEntityException; + + public boolean isModified(); + public void synchronizedWithDatasource(); + public void removedFromDatasource(); + + public boolean isMutable(); + public void setImmutable(); + + /** + * @return Returns the isFromEntitySync. + */ + public boolean getIsFromEntitySync(); + + /** + * @param isFromEntitySync The isFromEntitySync to set. + */ + public void setIsFromEntitySync(boolean isFromEntitySync); + + public String getEntityName(); + + public ModelEntityInterface getModelEntity(); + + /** Get the GenericDelegator instance that created this value object and that is responsible for it. + *@return GenericDelegator object + */ + public GenericDelegator getDelegator(); + + public String getDelegatorName(); + + /** Set the GenericDelegator instance that created this value object and that is responsible for it. */ + public void setDelegator(GenericDelegator internalDelegator); + + public Object get(String name); + + /** Returns true if the entity contains all of the primary key fields, but NO others. */ + public boolean isPrimaryKey(); + public boolean isPrimaryKey(boolean requireValue); + + /** Returns true if the entity contains all of the primary key fields. */ + public boolean containsPrimaryKey(); + public boolean containsPrimaryKey(boolean requireValue); + + public String getPkShortValueString(); + + /** Sets the named field to the passed value, even if the value is null + * @param name The field name to set + * @param value The value to set + */ + public void set(String name, Object value); + + /** Sets the named field to the passed value. If value is null, it is only + * set if the setIfNull parameter is true. This is useful because an update + * will only set values that are included in the HashMap and will store null + * values in the HashMap to the datastore. If a value is not in the HashMap, + * it will be left unmodified in the datastore. + * @param name The field name to set + * @param value The value to set + * @param setIfNull Specifies whether or not to set the value if it is null + */ + public Object set(String name, Object value, boolean setIfNull); + + public void dangerousSetNoCheckButFast(ModelFieldInterface modelField, Object value); + + public Object dangerousGetNoCheckButFast(ModelFieldInterface modelField); + + /** Sets the named field to the passed value, converting the value from a String to the corrent type using <code>Type.valueOf()</code> + * @param name The field name to set + * @param value The String value to convert and set + */ + public void setString(String name, String value); + + /** Sets a field with an array of bytes, wrapping them automatically for easy use. + * @param name The field name to set + * @param bytes The byte array to be wrapped and set + */ + public void setBytes(String name, byte[] bytes); + + public void setNextSeqId(); + + public Boolean getBoolean(String name); + + public String getString(String name); + + public java.sql.Timestamp getTimestamp(String name); + + public java.sql.Time getTime(String name); + + public java.sql.Date getDate(String name); + + public Integer getInteger(String name); + + public Long getLong(String name); + + public Float getFloat(String name); + + public Double getDouble(String name); + + public BigDecimal getBigDecimal(String name); + + public byte[] getBytes(String name); + + /** Checks a resource bundle for a value for this field using the entity name, the field name + * and a composite of the Primary Key field values as a key. If no value is found in the + * resource then the field value is returned. Uses the default-resource-name from the entity + * definition as the resource name. To specify a resource name manually, use the other getResource method. + * + * So, the key in the resource bundle (properties file) should be as follows: + * <entity-name>.<field-name>.<pk-field-value-1>.<pk-field-value-2>...<pk-field-value-n> + * For example: + * ProductType.description.FINISHED_GOOD + * + * @param name The name of the field on the entity + * @param locale The locale to use when finding the ResourceBundle, if null uses the default + * locale for the current instance of Java + * @return If the corresponding resource is found and contains a key as described above, then that + * property value is returned; otherwise returns the field value + */ + public Object get(String name, Locale locale); + + /** Same as the getResource method that does not take resource name, but instead allows manually + * specifying the resource name. In general you should use the other method for more consistent + * naming and use of the corresponding properties files. + * @param name The name of the field on the entity + * @param resource The name of the resource to get the value from; if null defaults to the + * default-resource-name on the entity definition, if specified there + * @param locale The locale to use when finding the ResourceBundle, if null uses the default + * locale for the current instance of Java + * @return If the specified resource is found and contains a key as described above, then that + * property value is returned; otherwise returns the field value + */ + public Object get(String name, String resource, Locale locale); + + public GenericPK getPrimaryKey(); + + /** go through the pks and for each one see if there is an entry in fields to set */ + public void setPKFields(Map<? extends Object, ? extends Object> fields); + + /** go through the pks and for each one see if there is an entry in fields to set */ + public void setPKFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty); + + /** go through the non-pks and for each one see if there is an entry in fields to set */ + public void setNonPKFields(Map<? extends Object, ? extends Object> fields); + + /** go through the non-pks and for each one see if there is an entry in fields to set */ + public void setNonPKFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty); + + + /** Intelligently sets fields on this entity from the Map of fields passed in + * @param fields The fields Map to get the values from + * @param setIfEmpty Used to specify whether empty/null values in the field Map should over-write non-empty values in this entity + * @param namePrefix If not null or empty will be pre-pended to each field name (upper-casing the first letter of the field name first), and that will be used as the fields Map lookup name instead of the field-name + * @param pks If null, get all values, if TRUE just get PKs, if FALSE just get non-PKs + */ + public void setAllFields(Map<? extends Object, ? extends Object> fields, boolean setIfEmpty, String namePrefix, Boolean pks); + + /** Returns keys of entity fields + * @return java.util.Collection + */ + public Collection<String> getAllKeys(); + + /** Returns key/value pairs of entity fields + * @return java.util.Map + */ + public Map<String, Object> getAllFields(); + + /** Used by clients to specify exactly the fields they are interested in + * @param keysofFields the name of the fields the client is interested in + * @return java.util.Map + */ + public Map<String, Object> getFields(Collection<String> keysofFields); + + /** Used by clients to update particular fields in the entity + * @param keyValuePairs java.util.Map + */ + public void setFields(Map<? extends String, ? extends Object> keyValuePairs); + + public boolean matchesFields(Map<String, ? extends Object> keyValuePairs); + + /** Used to indicate if locking is enabled for this entity + * @return True if locking is enabled + */ + public boolean lockEnabled(); + + /** Makes an XML Element object with an attribute for each field of the entity + *@param document The XML Document that the new Element will be part of + *@return org.w3c.dom.Element object representing this generic entity + */ + public Element makeXmlElement(Document document); + + /** Makes an XML Element object with an attribute for each field of the entity + *@param document The XML Document that the new Element will be part of + *@param prefix A prefix to put in front of the entity name in the tag name + *@return org.w3c.dom.Element object representing this generic entity + */ + public Element makeXmlElement(Document document, String prefix); + + /** Writes XML text with an attribute or CDATA element for each field of the entity + *@param writer A PrintWriter to write to + *@param prefix A prefix to put in front of the entity name in the tag name + */ + public void writeXmlText(PrintWriter writer, String prefix); + + /** + * Creates a String for the entity, overrides the default toString + * This method is NOT secure, it WILL display encrypted fields + * + *@return String corresponding to this entity + */ + public String toStringInsecure(); + + /** Compares this GenericEntity to the passed object + *@param that Object to compare this to + *@return int representing the result of the comparison (-1,0, or 1) + */ + public int compareTo(GenericEntity that); + + public static interface NULL { + } +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntity.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,45 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.context.entity; + +import org.ofbiz.base.util.*; + +/** + * GenericEntityException + * + */ +@SuppressWarnings("serial") +public class GenericEntityException extends GeneralException { + + public GenericEntityException() { + super(); + } + + public GenericEntityException(Throwable nested) { + super(nested); + } + + public GenericEntityException(String str) { + super(str); + } + + public GenericEntityException(String str, Throwable nested) { + super(str, nested); + } +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericEntityException.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,28 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ +package org.ofbiz.context.entity; + + +/** + * Generic Entity Primary Key Object + * + */ +public interface GenericPK extends GenericEntity { + +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericPK.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Added: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java?rev=795024&view=auto ============================================================================== --- ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java (added) +++ ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java Fri Jul 17 09:56:47 2009 @@ -0,0 +1,254 @@ +/******************************************************************************* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + *******************************************************************************/ + +package org.ofbiz.context.entity; + +import java.util.List; +import java.util.Map; + +import javolution.lang.Reusable; + + +/** + * Generic Entity Value Interface - Handles persistence for any defined entity. + * + */ +public interface GenericValue extends GenericEntity, Reusable { + + public GenericValue create() throws GenericEntityException; + + public void store() throws GenericEntityException; + + public void remove() throws GenericEntityException; + + public void refresh() throws GenericEntityException; + + public void refreshFromCache() throws GenericEntityException; + + public boolean originalDbValuesAvailable(); + + public Object getOriginalDbValue(String name); + + /** This should only be called by the Entity Engine once a GenericValue has + * been read from the database so that we have a copy of the original field + * values from the Db. + */ + public void copyOriginalDbValues(); + + /** Get the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelated(String relationName) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelated(String relationName, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelated(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedCache(String relationName) throws GenericEntityException; + + /** + * Get the named Related Entity for the GenericValue from the persistent store across another Relation. + * Helps to get related Values in a multi-to-multi relationship. + * @param relationNameOne String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file, for first relation + * @param relationNameTwo String containing the relation name for second relation + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + * @return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedMulti(String relationNameOne, String relationNameTwo, List<String> orderBy) throws GenericEntityException; + + /** + * Get the named Related Entity for the GenericValue from the persistent store across another Relation. + * Helps to get related Values in a multi-to-multi relationship. + * @param relationNameOne String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file, for first relation + * @param relationNameTwo String containing the relation name for second relation + * @return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedMulti(String relationNameOne, String relationNameTwo) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedCache(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedCache(String relationName, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in a cache associated with this entity which is + * destroyed with this ValueObject when no longer used. + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedEmbeddedCache(String relationName) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in a cache associated with this entity which is + * destroyed with this ValueObject when no longer used. + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @param orderBy The fields of the named entity to order the query by; may be null; + * optionally add a " ASC" for ascending or " DESC" for descending + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedEmbeddedCache(String relationName, Map<String, ? extends Object> byAndFields, List<String> orderBy) throws GenericEntityException; + + public void removeRelatedEmbeddedCache(String relationName); + + public void storeRelatedEmbeddedCache(String relationName, List<GenericValue> col); + + public void storeRelatedEmbeddedCache(String relationName, GenericValue value); + + public void clearEmbeddedCache(); + + /** Get the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public GenericValue getRelatedOne(String relationName) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public GenericValue getRelatedOneCache(String relationName) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store, looking first in a cache associated with this entity which is + * destroyed with this ValueObject when no longer used. + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@return List of GenericValue instances as specified in the relation definition + */ + public GenericValue getRelatedOneEmbeddedCache(String relationName) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store and filter it + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param fields the fields that must equal in order to keep + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedByAnd(String relationName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store and filter it, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param fields the fields that must equal in order to keep + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedByAndCache(String relationName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store and filter it, looking first in a cache associated with this entity which is + * destroyed with this ValueObject when no longer used. + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param fields the fields that must equal in order to keep + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedByAndEmbeddedCache(String relationName, Map<String, ? extends Object> fields) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent store and order it + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param orderBy the order that they should be returned + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedOrderBy(String relationName, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store and order it, looking first in the global generic cache (for the moment this isn't true, is same as EmbeddedCache variant) + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param orderBy the order that they should be returned + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedOrderByCache(String relationName, List<String> orderBy) throws GenericEntityException; + + /** Get the named Related Entity for the GenericValue from the persistent + * store and order it, looking first in a cache associated with this entity which is + * destroyed with this ValueObject when no longer used. + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + *@param orderBy the order that they should be returned + *@return List of GenericValue instances as specified in the relation definition + */ + public List<GenericValue> getRelatedOrderByEmbeddedCache(String relationName, List<String> orderBy) throws GenericEntityException; + + /** Remove the named Related Entity for the GenericValue from the persistent store + *@param relationName String containing the relation name which is the combination of relation.title and relation.rel-entity-name as specified in the entity XML definition file + */ + public void removeRelated(String relationName) throws GenericEntityException; + + /** Get a dummy primary key for the named Related Entity for the GenericValue + * @param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + * @return GenericPK containing a possibly incomplete PrimaryKey object representing the related entity or entities + */ + public GenericPK getRelatedDummyPK(String relationName) throws GenericEntityException; + + /** Get a dummy primary key for the named Related Entity for the GenericValue + * @param relationName String containing the relation name which is the + * combination of relation.title and relation.rel-entity-name as + * specified in the entity XML definition file + * @param byAndFields the fields that must equal in order to keep; may be null + * @return GenericPK containing a possibly incomplete PrimaryKey object representing the related entity or entities + */ + public GenericPK getRelatedDummyPK(String relationName, Map<String, ? extends Object> byAndFields) throws GenericEntityException; + + /** + * Checks to see if all foreign key records exist in the database. Will create a dummy value for + * those missing when specified. + * + * @param insertDummy Create a dummy record using the provided fields + * @return true if all FKs exist (or when all missing are created) + * @throws GenericEntityException + */ + public boolean checkFks(boolean insertDummy) throws GenericEntityException; +} Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java ------------------------------------------------------------------------------ svn:keywords = "Date Rev Author URL Id" Propchange: ofbiz/branches/executioncontext20090716/framework/context/src/org/ofbiz/context/entity/GenericValue.java ------------------------------------------------------------------------------ svn:mime-type = text/plain |
Free forum by Nabble | Edit this page |