/*==========================================================================*\ | _BatchJob.java |*-------------------------------------------------------------------------*| | Created by eogenerator | DO NOT EDIT. Make changes to BatchJob.java instead. |*-------------------------------------------------------------------------*| | Copyright (C) 2006-2012 Virginia Tech | | This file is part of Web-CAT. | | Web-CAT is free software; you can redistribute it and/or modify | it under the terms of the GNU Affero General Public License as published | by the Free Software Foundation; either version 3 of the License, or | (at your option) any later version. | | Web-CAT is distributed in the hope that it will be useful, | but WITHOUT ANY WARRANTY; without even the implied warranty of | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | GNU General Public License for more details. | | You should have received a copy of the GNU Affero General Public License | along with Web-CAT; if not, see <http://www.gnu.org/licenses/>. \*==========================================================================*/ package org.webcat.batchprocessor; import com.webobjects.eoaccess.*; import com.webobjects.eocontrol.*; import com.webobjects.foundation.*; import er.extensions.eof.ERXEOControlUtilities; import er.extensions.eof.ERXKey; import org.apache.log4j.Logger; import org.webcat.core.EOBasedKeyGenerator; import org.webcat.woextensions.WCFetchSpecification; // ------------------------------------------------------------------------- /** * An automatically generated EOGenericRecord subclass. DO NOT EDIT. * To change, use EOModeler, or make additions in * BatchJob.java. * * @author Generated by eogenerator * @version version suppressed to control auto-generation */ public abstract class _BatchJob extends org.webcat.jobqueue.JobBase implements org.webcat.core.MutableContainer.MutableContainerOwner { //~ Constructors .......................................................... // ---------------------------------------------------------- /** * Creates a new _BatchJob object. */ public _BatchJob() { super(); } // ---------------------------------------------------------- /** * A static factory method for creating a new * BatchJob object given required * attributes and relationships. * @param editingContext The context in which the new object will be * inserted * @param enqueueTimeValue * @param isCancelledValue * @param isInIterationValue * @param isReadyValue * @param updateMutableFieldsValue * @return The newly created object */ public static BatchJob create( EOEditingContext editingContext, NSTimestamp enqueueTimeValue, boolean isCancelledValue, boolean isInIterationValue, boolean isReadyValue, boolean updateMutableFieldsValue ) { BatchJob eoObject = (BatchJob) EOUtilities.createAndInsertInstance( editingContext, _BatchJob.ENTITY_NAME); eoObject.setEnqueueTime(enqueueTimeValue); eoObject.setIsCancelled(isCancelledValue); eoObject.setIsInIteration(isInIterationValue); eoObject.setIsReady(isReadyValue); eoObject.setUpdateMutableFields(updateMutableFieldsValue); return eoObject; } // ---------------------------------------------------------- /** * Get a local instance of the given object in another editing context. * @param editingContext The target editing context * @param eo The object to import * @return An instance of the given object in the target editing context */ public static BatchJob localInstance( EOEditingContext editingContext, BatchJob eo) { return (eo == null) ? null : (BatchJob)EOUtilities.localInstanceOfObject( editingContext, eo); } // ---------------------------------------------------------- /** * Look up an object by id number. Assumes the editing * context is appropriately locked. * @param ec The editing context to use * @param id The id to look up * @return The object, or null if no such id exists */ public static BatchJob forId( EOEditingContext ec, int id) { BatchJob obj = null; if (id > 0) { NSArray<BatchJob> objects = objectsMatchingValues(ec, "id", new Integer(id)); if (objects != null && objects.count() > 0) { obj = objects.objectAtIndex(0); } } return obj; } // ---------------------------------------------------------- /** * Look up an object by id number. Assumes the editing * context is appropriately locked. * @param ec The editing context to use * @param id The id to look up * @return The object, or null if no such id exists */ public static BatchJob forId( EOEditingContext ec, String id) { return forId(ec, er.extensions.foundation.ERXValueUtilities.intValue(id)); } //~ Constants (for key names) ............................................. // Attributes --- public static final String BATCHED_OBJECT_IDS_KEY = "batchedObjectIds"; public static final ERXKey<NSData> batchedObjectIds = new ERXKey<NSData>(BATCHED_OBJECT_IDS_KEY); public static final String CONFIG_SETTINGS_KEY = "configSettings"; public static final ERXKey<NSData> configSettings = new ERXKey<NSData>(CONFIG_SETTINGS_KEY); public static final String CURRENT_STATE_KEY = "currentState"; public static final ERXKey<String> currentState = new ERXKey<String>(CURRENT_STATE_KEY); public static final String DESCRIPTION_KEY = "description"; public static final ERXKey<String> description = new ERXKey<String>(DESCRIPTION_KEY); public static final String INDEX_OF_NEXT_OBJECT_KEY = "indexOfNextObject"; public static final ERXKey<Integer> indexOfNextObject = new ERXKey<Integer>(INDEX_OF_NEXT_OBJECT_KEY); public static final String IS_IN_ITERATION_KEY = "isInIteration"; public static final ERXKey<Integer> isInIteration = new ERXKey<Integer>(IS_IN_ITERATION_KEY); public static final String STATE_AFTER_ITERATION_KEY = "stateAfterIteration"; public static final ERXKey<String> stateAfterIteration = new ERXKey<String>(STATE_AFTER_ITERATION_KEY); public static final String UPDATE_MUTABLE_FIELDS_KEY = "updateMutableFields"; public static final ERXKey<Integer> updateMutableFields = new ERXKey<Integer>(UPDATE_MUTABLE_FIELDS_KEY); // To-one relationships --- public static final String BATCH_PLUGIN_KEY = "batchPlugin"; public static final ERXKey<org.webcat.batchprocessor.BatchPlugin> batchPlugin = new ERXKey<org.webcat.batchprocessor.BatchPlugin>(BATCH_PLUGIN_KEY); public static final String BATCH_RESULT_KEY = "batchResult"; public static final ERXKey<org.webcat.batchprocessor.BatchResult> batchResult = new ERXKey<org.webcat.batchprocessor.BatchResult>(BATCH_RESULT_KEY); public static final String OBJECT_QUERY_KEY = "objectQuery"; public static final ERXKey<org.webcat.core.ObjectQuery> objectQuery = new ERXKey<org.webcat.core.ObjectQuery>(OBJECT_QUERY_KEY); // To-many relationships --- // Fetch specifications --- public static final String ENTITY_NAME = "BatchJob"; public transient final EOBasedKeyGenerator generateKey = new EOBasedKeyGenerator(this); //~ Methods ............................................................... // ---------------------------------------------------------- /** * Get a local instance of this object in another editing context. * @param editingContext The target editing context * @return An instance of this object in the target editing context */ public BatchJob localInstance(EOEditingContext editingContext) { return (BatchJob)EOUtilities.localInstanceOfObject( editingContext, this); } //-- Local mutable cache -- private org.webcat.core.MutableArray batchedObjectIdsCache; private NSData batchedObjectIdsRawCache; // ---------------------------------------------------------- /** * Retrieve this object's <code>batchedObjectIds</code> value. * @return the value of the attribute */ public org.webcat.core.MutableArray batchedObjectIds() { NSData dbValue = (NSData)storedValueForKey("batchedObjectIds"); if (batchedObjectIdsRawCache != dbValue) { if (dbValue != null && dbValue.equals( batchedObjectIdsRawCache)) { // They are still equal, so just update the raw cache batchedObjectIdsRawCache = dbValue; } else { // Underlying attribute may have changed because // of a concurrent update through another editing // context, so throw away current values. batchedObjectIdsRawCache = dbValue; org.webcat.core.MutableArray newValue = org.webcat.core.MutableArray .objectWithArchiveData( dbValue ); if ( batchedObjectIdsCache != null ) { batchedObjectIdsCache.copyFrom( newValue ); } else { batchedObjectIdsCache = newValue; } batchedObjectIdsCache.setOwner( this ); setUpdateMutableFields( true ); } } else if ( dbValue == null && batchedObjectIdsCache == null ) { batchedObjectIdsCache = org.webcat.core.MutableArray .objectWithArchiveData( dbValue ); batchedObjectIdsCache.setOwner( this ); setUpdateMutableFields( true ); } return batchedObjectIdsCache; } // ---------------------------------------------------------- /** * Change the value of this object's <code>batchedObjectIds</code> * property. * * @param value The new value for this property */ public void setBatchedObjectIds( org.webcat.core.MutableArray value ) { if (log.isDebugEnabled()) { log.debug( "setBatchedObjectIds(" + value + ")" ); } if ( batchedObjectIdsCache == null ) { batchedObjectIdsCache = value; value.setHasChanged( false ); batchedObjectIdsRawCache = value.archiveData(); takeStoredValueForKey( batchedObjectIdsRawCache, "batchedObjectIds" ); } else if ( batchedObjectIdsCache != value ) // ( batchedObjectIdsCache != null ) { batchedObjectIdsCache.copyFrom( value ); setUpdateMutableFields( true ); } else // ( batchedObjectIdsCache == non-null value ) { // no nothing } } // ---------------------------------------------------------- /** * Clear the value of this object's <code>batchedObjectIds</code> * property. */ public void clearBatchedObjectIds() { if (log.isDebugEnabled()) { log.debug( "clearBatchedObjectIds()" ); } takeStoredValueForKey( null, "batchedObjectIds" ); batchedObjectIdsRawCache = null; batchedObjectIdsCache = null; } //-- Local mutable cache -- private org.webcat.core.MutableDictionary configSettingsCache; private NSData configSettingsRawCache; // ---------------------------------------------------------- /** * Retrieve this object's <code>configSettings</code> value. * @return the value of the attribute */ public org.webcat.core.MutableDictionary configSettings() { NSData dbValue = (NSData)storedValueForKey("configSettings"); if (configSettingsRawCache != dbValue) { if (dbValue != null && dbValue.equals( configSettingsRawCache)) { // They are still equal, so just update the raw cache configSettingsRawCache = dbValue; } else { // Underlying attribute may have changed because // of a concurrent update through another editing // context, so throw away current values. configSettingsRawCache = dbValue; org.webcat.core.MutableDictionary newValue = org.webcat.core.MutableDictionary .objectWithArchiveData( dbValue ); if ( configSettingsCache != null ) { configSettingsCache.copyFrom( newValue ); } else { configSettingsCache = newValue; } configSettingsCache.setOwner( this ); setUpdateMutableFields( true ); } } else if ( dbValue == null && configSettingsCache == null ) { configSettingsCache = org.webcat.core.MutableDictionary .objectWithArchiveData( dbValue ); configSettingsCache.setOwner( this ); setUpdateMutableFields( true ); } return configSettingsCache; } // ---------------------------------------------------------- /** * Change the value of this object's <code>configSettings</code> * property. * * @param value The new value for this property */ public void setConfigSettings( org.webcat.core.MutableDictionary value ) { if (log.isDebugEnabled()) { log.debug( "setConfigSettings(" + value + ")" ); } if ( configSettingsCache == null ) { configSettingsCache = value; value.setHasChanged( false ); configSettingsRawCache = value.archiveData(); takeStoredValueForKey( configSettingsRawCache, "configSettings" ); } else if ( configSettingsCache != value ) // ( configSettingsCache != null ) { configSettingsCache.copyFrom( value ); setUpdateMutableFields( true ); } else // ( configSettingsCache == non-null value ) { // no nothing } } // ---------------------------------------------------------- /** * Clear the value of this object's <code>configSettings</code> * property. */ public void clearConfigSettings() { if (log.isDebugEnabled()) { log.debug( "clearConfigSettings()" ); } takeStoredValueForKey( null, "configSettings" ); configSettingsRawCache = null; configSettingsCache = null; } // ---------------------------------------------------------- /** * Retrieve this object's <code>currentState</code> value. * @return the value of the attribute */ public String currentState() { return (String)storedValueForKey( "currentState" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>currentState</code> * property. * * @param value The new value for this property */ public void setCurrentState( String value ) { if (log.isDebugEnabled()) { log.debug( "setCurrentState(" + value + "): was " + currentState() ); } takeStoredValueForKey( value, "currentState" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>description</code> value. * @return the value of the attribute */ public String description() { return (String)storedValueForKey( "description" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>description</code> * property. * * @param value The new value for this property */ public void setDescription( String value ) { if (log.isDebugEnabled()) { log.debug( "setDescription(" + value + "): was " + description() ); } takeStoredValueForKey( value, "description" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>indexOfNextObject</code> value. * @return the value of the attribute */ public int indexOfNextObject() { Integer returnValue = (Integer)storedValueForKey( "indexOfNextObject" ); return ( returnValue == null ) ? 0 : returnValue.intValue(); } // ---------------------------------------------------------- /** * Change the value of this object's <code>indexOfNextObject</code> * property. * * @param value The new value for this property */ public void setIndexOfNextObject( int value ) { if (log.isDebugEnabled()) { log.debug( "setIndexOfNextObject(" + value + "): was " + indexOfNextObject() ); } Integer actual = er.extensions.eof.ERXConstant.integerForInt( value ); setIndexOfNextObjectRaw( actual ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>indexOfNextObject</code> value. * @return the value of the attribute */ public Integer indexOfNextObjectRaw() { return (Integer)storedValueForKey( "indexOfNextObject" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>indexOfNextObject</code> * property. * * @param value The new value for this property */ public void setIndexOfNextObjectRaw( Integer value ) { if (log.isDebugEnabled()) { log.debug( "setIndexOfNextObjectRaw(" + value + "): was " + indexOfNextObjectRaw() ); } takeStoredValueForKey( value, "indexOfNextObject" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>isInIteration</code> value. * @return the value of the attribute */ public boolean isInIteration() { Integer returnValue = (Integer)storedValueForKey( "isInIteration" ); return ( returnValue == null ) ? false : ( returnValue.intValue() > 0 ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>isInIteration</code> * property. * * @param value The new value for this property */ public void setIsInIteration( boolean value ) { if (log.isDebugEnabled()) { log.debug( "setIsInIteration(" + value + "): was " + isInIteration() ); } Integer actual = er.extensions.eof.ERXConstant.integerForInt( value ? 1 : 0 ); setIsInIterationRaw( actual ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>isInIteration</code> value. * @return the value of the attribute */ public Integer isInIterationRaw() { return (Integer)storedValueForKey( "isInIteration" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>isInIteration</code> * property. * * @param value The new value for this property */ public void setIsInIterationRaw( Integer value ) { if (log.isDebugEnabled()) { log.debug( "setIsInIterationRaw(" + value + "): was " + isInIterationRaw() ); } takeStoredValueForKey( value, "isInIteration" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>stateAfterIteration</code> value. * @return the value of the attribute */ public String stateAfterIteration() { return (String)storedValueForKey( "stateAfterIteration" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>stateAfterIteration</code> * property. * * @param value The new value for this property */ public void setStateAfterIteration( String value ) { if (log.isDebugEnabled()) { log.debug( "setStateAfterIteration(" + value + "): was " + stateAfterIteration() ); } takeStoredValueForKey( value, "stateAfterIteration" ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>updateMutableFields</code> value. * @return the value of the attribute */ public boolean updateMutableFields() { Integer returnValue = (Integer)storedValueForKey( "updateMutableFields" ); return ( returnValue == null ) ? false : ( returnValue.intValue() > 0 ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>updateMutableFields</code> * property. * * @param value The new value for this property */ public void setUpdateMutableFields( boolean value ) { if (log.isDebugEnabled()) { log.debug( "setUpdateMutableFields(" + value + "): was " + updateMutableFields() ); } Integer actual = er.extensions.eof.ERXConstant.integerForInt( value ? 1 : 0 ); setUpdateMutableFieldsRaw( actual ); } // ---------------------------------------------------------- /** * Retrieve this object's <code>updateMutableFields</code> value. * @return the value of the attribute */ public Integer updateMutableFieldsRaw() { return (Integer)storedValueForKey( "updateMutableFields" ); } // ---------------------------------------------------------- /** * Change the value of this object's <code>updateMutableFields</code> * property. * * @param value The new value for this property */ public void setUpdateMutableFieldsRaw( Integer value ) { if (log.isDebugEnabled()) { log.debug( "setUpdateMutableFieldsRaw(" + value + "): was " + updateMutableFieldsRaw() ); } takeStoredValueForKey( value, "updateMutableFields" ); } // ---------------------------------------------------------- /** * Called just before this object is saved to the database. */ public void saveMutables() { log.debug("saveMutables()"); if ( batchedObjectIdsCache != null && batchedObjectIdsCache.hasChanged() ) { batchedObjectIdsRawCache = batchedObjectIdsCache.archiveData(); takeStoredValueForKey( batchedObjectIdsRawCache, "batchedObjectIds" ); batchedObjectIdsCache.setHasChanged( false ); } if ( configSettingsCache != null && configSettingsCache.hasChanged() ) { configSettingsRawCache = configSettingsCache.archiveData(); takeStoredValueForKey( configSettingsRawCache, "configSettings" ); configSettingsCache.setHasChanged( false ); } setUpdateMutableFields( false ); } // ---------------------------------------------------------- /** * Called just before this object is saved to the database. */ public void willUpdate() { log.debug("willUpdate()"); saveMutables(); super.willUpdate(); } // ---------------------------------------------------------- /** * Called just before this object is inserted into the database. */ public void willInsert() { log.debug("willInsert()"); saveMutables(); super.willInsert(); } // ---------------------------------------------------------- /** * Called when the object is invalidated. */ public void flushCaches() { log.debug("flushCaches()"); batchedObjectIdsCache = null; batchedObjectIdsRawCache = null; configSettingsCache = null; configSettingsRawCache = null; super.flushCaches(); } // ---------------------------------------------------------- /** * Called when an owned mutable container object is changed. */ public void mutableContainerHasChanged() { setUpdateMutableFields( true ); } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>batchPlugin</code> * relationship. * @return the entity in the relationship */ public org.webcat.batchprocessor.BatchPlugin batchPlugin() { return (org.webcat.batchprocessor.BatchPlugin)storedValueForKey( "batchPlugin" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>batchPlugin</code> * relationship (DO NOT USE--instead, use * <code>setBatchPluginRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setBatchPlugin( org.webcat.batchprocessor.BatchPlugin value ) { if (log.isDebugEnabled()) { log.debug( "setBatchPlugin(" + value + "): was " + batchPlugin() ); } takeStoredValueForKey( value, "batchPlugin" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>batchPlugin</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setBatchPluginRelationship( org.webcat.batchprocessor.BatchPlugin value ) { if (log.isDebugEnabled()) { log.debug( "setBatchPluginRelationship(" + value + "): was " + batchPlugin() ); } if ( value == null ) { org.webcat.batchprocessor.BatchPlugin object = batchPlugin(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "batchPlugin" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "batchPlugin" ); } } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>batchResult</code> * relationship. * @return the entity in the relationship */ public org.webcat.batchprocessor.BatchResult batchResult() { return (org.webcat.batchprocessor.BatchResult)storedValueForKey( "batchResult" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>batchResult</code> * relationship (DO NOT USE--instead, use * <code>setBatchResultRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setBatchResult( org.webcat.batchprocessor.BatchResult value ) { if (log.isDebugEnabled()) { log.debug( "setBatchResult(" + value + "): was " + batchResult() ); } takeStoredValueForKey( value, "batchResult" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>batchResult</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setBatchResultRelationship( org.webcat.batchprocessor.BatchResult value ) { if (log.isDebugEnabled()) { log.debug( "setBatchResultRelationship(" + value + "): was " + batchResult() ); } if ( value == null ) { org.webcat.batchprocessor.BatchResult object = batchResult(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "batchResult" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "batchResult" ); } } // ---------------------------------------------------------- /** * Retrieve the entity pointed to by the <code>objectQuery</code> * relationship. * @return the entity in the relationship */ public org.webcat.core.ObjectQuery objectQuery() { return (org.webcat.core.ObjectQuery)storedValueForKey( "objectQuery" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>objectQuery</code> * relationship (DO NOT USE--instead, use * <code>setObjectQueryRelationship()</code>. * This method is provided for WebObjects use. * * @param value The new entity to relate to */ public void setObjectQuery( org.webcat.core.ObjectQuery value ) { if (log.isDebugEnabled()) { log.debug( "setObjectQuery(" + value + "): was " + objectQuery() ); } takeStoredValueForKey( value, "objectQuery" ); } // ---------------------------------------------------------- /** * Set the entity pointed to by the <code>objectQuery</code> * relationship. This method is a type-safe version of * <code>addObjectToBothSidesOfRelationshipWithKey()</code>. * * @param value The new entity to relate to */ public void setObjectQueryRelationship( org.webcat.core.ObjectQuery value ) { if (log.isDebugEnabled()) { log.debug( "setObjectQueryRelationship(" + value + "): was " + objectQuery() ); } if ( value == null ) { org.webcat.core.ObjectQuery object = objectQuery(); if ( object != null ) removeObjectFromBothSidesOfRelationshipWithKey( object, "objectQuery" ); } else { addObjectToBothSidesOfRelationshipWithKey( value, "objectQuery" ); } } // ---------------------------------------------------------- /** * Retrieve objects using a fetch specification. * * @param context The editing context to use * @param fspec The fetch specification to use * * @return an NSArray of the entities retrieved */ @SuppressWarnings("unchecked") public static NSArray<BatchJob> objectsWithFetchSpecification( EOEditingContext context, EOFetchSpecification fspec) { return context.objectsWithFetchSpecification(fspec); } // ---------------------------------------------------------- /** * Retrieve all objects of this type. * * @param context The editing context to use * * @return an NSArray of the entities retrieved */ public static NSArray<BatchJob> allObjects( EOEditingContext context) { return objectsMatchingQualifier(context, null, null); } // ---------------------------------------------------------- /** * Retrieve objects using a qualifier. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return an NSArray of the entities retrieved */ public static NSArray<BatchJob> objectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier) { return objectsMatchingQualifier(context, qualifier, null); } // ---------------------------------------------------------- /** * Retrieve objects using a qualifier and sort orderings. * * @param context The editing context to use * @param qualifier The qualifier to use * @param sortOrderings The sort orderings to use * * @return an NSArray of the entities retrieved */ public static NSArray<BatchJob> objectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) { @SuppressWarnings("unchecked") EOFetchSpecification fspec = new WCFetchSpecification( ENTITY_NAME, qualifier, sortOrderings); fspec.setUsesDistinct(true); return objectsWithFetchSpecification(context, fspec); } // ---------------------------------------------------------- /** * Retrieve the first object that matches a qualifier, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param qualifier The qualifier to use * @param sortOrderings the sort orderings * * @return the first entity that was retrieved, or null if there was none */ public static BatchJob firstObjectMatchingQualifier( EOEditingContext context, EOQualifier qualifier, NSArray<EOSortOrdering> sortOrderings) { NSArray<BatchJob> objects = objectsMatchingQualifier(context, qualifier, sortOrderings); return (objects.size() > 0) ? objects.get(0) : null; } // ---------------------------------------------------------- /** * Retrieve a single object using a list of keys and values to match. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return the single entity that was retrieved * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static BatchJob uniqueObjectMatchingQualifier( EOEditingContext context, EOQualifier qualifier) throws EOUtilities.MoreThanOneException { NSArray<BatchJob> objects = objectsMatchingQualifier(context, qualifier); if (objects.size() > 1) { String msg = "fetching BatchJob"; try { if (qualifier != null) { msg += " where " + qualifier; } msg += ", result = " + objects; } catch (Exception e) { log.error("Exception building MoreThanOneException message, " + "contents so far: " + msg, e); } throw new EOUtilities.MoreThanOneException(msg); } return (objects.size() > 0) ? objects.get(0) : null; } // ---------------------------------------------------------- /** * Retrieve objects using a list of keys and values to match. * * @param context The editing context to use * @param keysAndValues a list of keys and values to match, alternating * "key", "value", "key", "value"... * * @return an NSArray of the entities retrieved */ public static NSArray<BatchJob> objectsMatchingValues( EOEditingContext context, Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("There should a value " + "corresponding to every key that was passed. Args = " + java.util.Arrays.toString(keysAndValues)); } NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { Object key = keysAndValues[i]; Object value = keysAndValues[i + 1]; if (key == null) { throw new IllegalArgumentException( "Found null where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } else if (!(key instanceof String)) { throw new IllegalArgumentException( "Found a " + key.getClass().getName() + " [" + key + "]" + " where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } valueDictionary.setObjectForKey(value, key); } return objectsMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve objects using a dictionary of keys and values to match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return an NSArray of the entities retrieved */ @SuppressWarnings("unchecked") public static NSArray<BatchJob> objectsMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) { return EOUtilities.objectsMatchingValues(context, ENTITY_NAME, keysAndValues); } // ---------------------------------------------------------- /** * Retrieve the first object that matches a set of keys and values, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param sortOrderings the sort orderings * @param keysAndValues a list of keys and values to match, alternating * "key", "value", "key", "value"... * * @return the first entity that was retrieved, or null if there was none */ public static BatchJob firstObjectMatchingValues( EOEditingContext context, NSArray<EOSortOrdering> sortOrderings, Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("There should a value " + "corresponding to every key that was passed. Args = " + java.util.Arrays.toString(keysAndValues)); } NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { Object key = keysAndValues[i]; Object value = keysAndValues[i + 1]; if (key == null) { throw new IllegalArgumentException( "Found null where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } else if (!(key instanceof String)) { throw new IllegalArgumentException( "Found a " + key.getClass().getName() + " [" + key + "]" + " where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } valueDictionary.setObjectForKey(value, key); } return firstObjectMatchingValues( context, sortOrderings, valueDictionary); } // ---------------------------------------------------------- /** * Retrieves the first object that matches a set of keys and values, when * sorted with the specified sort orderings. * * @param context The editing context to use * @param sortOrderings the sort orderings * @param keysAndValues a dictionary of keys and values to match * * @return the first entity that was retrieved, or null if there was none */ public static BatchJob firstObjectMatchingValues( EOEditingContext context, NSArray<EOSortOrdering> sortOrderings, NSDictionary<String, Object> keysAndValues) { @SuppressWarnings("unchecked") EOFetchSpecification fspec = new WCFetchSpecification( ENTITY_NAME, EOQualifier.qualifierToMatchAllValues(keysAndValues), sortOrderings); fspec.setFetchLimit(1); NSArray<BatchJob> objects = objectsWithFetchSpecification( context, fspec ); if ( objects.count() == 0 ) { return null; } else { return objects.objectAtIndex(0); } } // ---------------------------------------------------------- /** * Retrieve a single object using a list of keys and values to match. * * @param context The editing context to use * @param keysAndValues a list of keys and values to match, alternating * "key", "value", "key", "value"... * * @return the single entity that was retrieved, or null if there was none * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static BatchJob uniqueObjectMatchingValues( EOEditingContext context, Object... keysAndValues) throws EOUtilities.MoreThanOneException { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("There should a value " + "corresponding to every key that was passed. Args = " + java.util.Arrays.toString(keysAndValues)); } NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { Object key = keysAndValues[i]; Object value = keysAndValues[i + 1]; if (key == null) { throw new IllegalArgumentException( "Found null where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } else if (!(key instanceof String)) { throw new IllegalArgumentException( "Found a " + key.getClass().getName() + " [" + key + "]" + " where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } valueDictionary.setObjectForKey(value, key); } return uniqueObjectMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve an object using a dictionary of keys and values to match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return the single entity that was retrieved, or null if there was none * * @throws EOUtilities.MoreThanOneException * if there is more than one matching object */ public static BatchJob uniqueObjectMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) throws EOUtilities.MoreThanOneException { try { return (BatchJob)EOUtilities.objectMatchingValues( context, ENTITY_NAME, keysAndValues); } catch (EOObjectNotAvailableException e) { return null; } } // ---------------------------------------------------------- /** * Retrieve the count of all objects of this type. * * @param context The editing context to use * * @return the count of all objects */ public static int countOfAllObjects(EOEditingContext context) { return countOfObjectsMatchingQualifier(context, null); } // ---------------------------------------------------------- /** * Retrieve the count of objects that match a qualifier. * * @param context The editing context to use * @param qualifier The qualifier to use * * @return the count of objects matching the qualifier */ public static int countOfObjectsMatchingQualifier( EOEditingContext context, EOQualifier qualifier) { return ERXEOControlUtilities.objectCountWithQualifier( context, ENTITY_NAME, qualifier); } // ---------------------------------------------------------- /** * Retrieve the count of objects using a list of keys and values to match. * * @param context The editing context to use * @param keysAndValues a list of keys and values to match, alternating * "key", "value", "key", "value"... * * @return the count of objects that match the specified values */ public static int countOfObjectsMatchingValues( EOEditingContext context, Object... keysAndValues) { if (keysAndValues.length % 2 != 0) { throw new IllegalArgumentException("There should a value " + "corresponding to every key that was passed. Args = " + java.util.Arrays.toString(keysAndValues)); } NSMutableDictionary<String, Object> valueDictionary = new NSMutableDictionary<String, Object>(); for (int i = 0; i < keysAndValues.length; i += 2) { Object key = keysAndValues[i]; Object value = keysAndValues[i + 1]; if (key == null) { throw new IllegalArgumentException( "Found null where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } else if (!(key instanceof String)) { throw new IllegalArgumentException( "Found a " + key.getClass().getName() + " [" + key + "]" + " where a String key was expected, arguments = " + java.util.Arrays.toString(keysAndValues)); } valueDictionary.setObjectForKey(value, key); } return countOfObjectsMatchingValues(context, valueDictionary); } // ---------------------------------------------------------- /** * Retrieve the count of objects using a dictionary of keys and values to * match. * * @param context The editing context to use * @param keysAndValues a dictionary of keys and values to match * * @return the count of objects that matched the specified values */ public static int countOfObjectsMatchingValues( EOEditingContext context, NSDictionary<String, Object> keysAndValues) { return countOfObjectsMatchingQualifier(context, EOQualifier.qualifierToMatchAllValues(keysAndValues)); } // ---------------------------------------------------------- /** * Produce a string representation of this object. This implementation * calls UserPresentableDescription(), which uses WebObjects' internal * mechanism to print out the visible fields of this object. Normally, * subclasses would override userPresentableDescription() to change * the way the object is printed. * * @return A string representation of the object's value */ public String toString() { return userPresentableDescription(); } //~ Instance/static variables ............................................. static Logger log = Logger.getLogger(BatchJob.class); }