/** * Clones this GenericEntity, this is a shallow clone & uses the default shallow HashMap clone * * @return Object that is a clone of this GenericEntity */ public Object clone() { GenericEntity newEntity = new GenericEntity(this); newEntity.setDelegator(internalDelegator); return newEntity; }
@Override public int compare(final GenericEntity d1, final GenericEntity d2) { return d1.getPrimaryKey().compareTo(d2.getPrimaryKey()); } });
/** Determines the equality of two GenericEntity objects, overrides the default equals *@param obj The object (GenericEntity) to compare this two *@return boolean stating if the two objects are equal */ public boolean equals(Object obj) { if (obj == null) return false; // from here, use the compareTo method since it is more efficient: if (this.compareTo(obj) == 0) { return true; } else { return false; } /* if (this.getClass().equals(obj.getClass())) { GenericEntity that = (GenericEntity) obj; if (this.getEntityName() != null && !this.getEntityName().equals(that.getEntityName())) { //if (Debug.infoOn()) Debug.logInfo("[GenericEntity.equals] Not equal: This entityName \"" + this.getEntityName() + "\" is not equal to that entityName \"" + that.getEntityName() + "\""); return false; } if (this.fields.equals(that.fields)) { return true; } else { //if (Debug.infoOn()) Debug.logInfo("[GenericEntity.equals] Not equal: Fields of this entity: \n" + this.toString() + "\n are not equal to fields of that entity:\n" + that.toString()); } } return false; */ }
public static void setValue(SQLProcessor sqlP, ModelField modelField, GenericEntity entity, ModelFieldTypeReader modelFieldTypeReader) throws GenericEntityException { Object fieldValue = entity.dangerousGetNoCheckButFast(modelField); setValue(sqlP, modelField, entity.getEntityName(), fieldValue, modelFieldTypeReader); }
private int compareAsc(GenericEntity obj, GenericEntity obj2) { if (this.modelField == null) { this.modelField = obj.getModelEntity().getField(field); if (this.modelField == null) { throw new IllegalArgumentException("The field " + field + " could not be found in the entity " + obj.getEntityName()); } } Object value = obj.dangerousGetNoCheckButFast(this.modelField); Object value2 = obj2.dangerousGetNoCheckButFast(this.modelField); // null is defined as the largest possible value if (value == null) return value2 == null ? 0 : 1; if (value2 == null) return value == null ? 0 : -1; int result = ((Comparable) value).compareTo(value2); // if (Debug.infoOn()) Debug.logInfo("[OrderByComparator.compareAsc] Result is " + result + " for [" + value + "] and [" + value2 + "]"); return result; }
GenericEntity entityCopy = new GenericEntity(entity); Object stampField = entity.get(ModelEntity.STAMP_FIELD); if ((stampField != null) && (!stampField.equals(entityCopy.get(ModelEntity.STAMP_FIELD)))) { String lockedTime = entityCopy.getTimestamp(ModelEntity.STAMP_FIELD).toString(); entity.set(ModelEntity.STAMP_FIELD, UtilDateTime.nowTimestamp()); throw new GenericEntityException("while updating: " + entity.toString(), e); } finally { sqlP.close();
GenericPK tempPK = entity.getPrimaryKey(); ModelEntity modelEntity = entity.getModelEntity(); Collection keys = entity.getAllKeys(); if (entity.get(curField.getName()) == null) { if (tempPK.get(curField.getName()) != null) { } else if (!entity.get(curField.getName()).equals(tempPK.get(curField.getName()))) {
public Integer getInteger(String name) { return (Integer) get(name); }
public int update(GenericEntity entity) throws GenericEntityException { ModelEntity modelEntity = entity.getModelEntity(); if (modelEntity == null) { throw new GenericModelException("Could not find ModelEntity record for entityName: " + entity.getEntityName()); } // we don't want to update ALL fields, just the nonpk fields that are in the passed GenericEntity List partialFields = new ArrayList(); Collection keys = entity.getAllKeys(); for (int fi = 0; fi < modelEntity.getNopksSize(); fi++) { ModelField curField = modelEntity.getNopk(fi); if (keys.contains(curField.getName())) partialFields.add(curField); } return customUpdate(entity, modelEntity, partialFields); }
/** Called dummyPKs because they can be invalid PKs, doing a deleteByAnd instead of a normal delete */ public int deleteAll(List dummyPKs) throws GenericEntityException { if (dummyPKs == null || dummyPKs.size() == 0) { return 0; } SQLProcessor sqlP = new ExplcitCommitSQLProcessor(helperName); try { Iterator iter = dummyPKs.iterator(); int numDeleted = 0; while (iter.hasNext()) { GenericEntity entity = (GenericEntity) iter.next(); // if it contains a complete primary key, delete the one, otherwise deleteByAnd if (entity.containsPrimaryKey()) { numDeleted += delete(entity, sqlP.getConnection()); } else { numDeleted += deleteByAnd(entity.getModelEntity(), entity.getAllFields(), sqlP.getConnection()); } } return numDeleted; } catch (GenericDataSourceException e) { sqlP.rollback(); throw new GenericDataSourceException("Generic Entity Exception occurred in deleteAll", e); } finally { sqlP.close(); } }
ModelEntity modelEntity = this.getModelEntity(); ModelFieldTypeReader mtr = ModelFieldTypeReader.getModelFieldTypeReader(getDelegator().getEntityHelperName(modelEntity)); value = encodeBase64(serialize(get(name))); if (value != null) { cdataMap.put(name, value); final Object obj = get(name); value = getString(name); if (value != null) { if (value.indexOf('\n') >= 0 || value.indexOf('\r') >= 0) { writer.print("><![CDATA["); writer.print(escapeCData(entry.getValue()));
T datedValue = iter.next(); fromDateField = datedValue.getModelEntity().getField(fromDateName); if (fromDateField == null) throw new IllegalArgumentException("\"" + fromDateName + "\" is not a field of " + datedValue.getEntityName()); thruDateField = datedValue.getModelEntity().getField(thruDateName); if (fromDateField == null) throw new IllegalArgumentException("\"" + thruDateName + "\" is not a field of " + datedValue.getEntityName()); java.sql.Timestamp fromDate = (java.sql.Timestamp) datedValue.dangerousGetNoCheckButFast(fromDateField); java.sql.Timestamp thruDate = (java.sql.Timestamp) datedValue.dangerousGetNoCheckButFast(thruDateField); java.sql.Timestamp fromDate = (java.sql.Timestamp) datedValue.dangerousGetNoCheckButFast(fromDateField); java.sql.Timestamp thruDate = (java.sql.Timestamp) datedValue.dangerousGetNoCheckButFast(thruDateField); java.sql.Timestamp fromDate = datedValue.getTimestamp(fromDateName); java.sql.Timestamp thruDate = datedValue.getTimestamp(thruDateName);
public int removeAll(List dummyPKs) throws GenericEntityException { int count = 0; for (Iterator iterator = dummyPKs.iterator(); iterator.hasNext();) { GenericEntity ge = (GenericEntity) iterator.next(); if (ge instanceof GenericPK) { count = count + removeFromCache((GenericPK) ge); } else { Map pkFields = new HashMap(); List pkFieldNames = ge.getModelEntity().getPkFieldNames(); for (int i = 0; i < pkFieldNames.size(); i++) { String fieldName = (String) pkFieldNames.get(i); pkFields.put(fieldName, ge.get(fieldName)); } GenericPK pk = new GenericPK(ge.getModelEntity(), pkFields); count = count + removeFromCache(pk); } } return count; }
entity.getEntityName() + '.' + curField.getName() + '.'); entity.dangerousSetNoCheckButFast(curField, rs.getString(ind)); break; entity.dangerousSetNoCheckButFast(curField, rs.getTimestamp(ind)); break; entity.dangerousSetNoCheckButFast(curField, rs.getTime(ind)); break; entity.dangerousSetNoCheckButFast(curField, rs.getDate(ind)); break; entity.dangerousSetNoCheckButFast(curField, null); } else { entity.dangerousSetNoCheckButFast(curField, intValue); entity.dangerousSetNoCheckButFast(curField, null); } else { entity.dangerousSetNoCheckButFast(curField, longValue); entity.dangerousSetNoCheckButFast(curField, null); } else { entity.dangerousSetNoCheckButFast(curField, floatValue); entity.dangerousSetNoCheckButFast(curField, null); } else { entity.dangerousSetNoCheckButFast(curField, doubleValue);
GenericDelegator delegator = entity.getDelegator(); value = entity.get(keyMap.getFieldName()); if (Debug.verboseOn()) Debug.logVerbose("[singleUpdateView]: --- Found map value: " + value.toString()); } else if (modelViewEntity.isField(keyMap.getRelFieldName())) { value = entity.get(keyMap.getRelFieldName()); if (Debug.verboseOn()) Debug.logVerbose("[singleUpdateView]: --- Found map value: " + value.toString()); } else { meGenericValue.set(meModelField.getName(), entity.get(modelField.getName())); meFieldsToSave.add(meModelField); if (Debug.verboseOn()) Debug.logVerbose("[singleUpdateView]: --- Added field to save: " + meModelField.getName() + " with value " + meGenericValue.get(meModelField.getName()));
private void writeXmlText(final String entityName, final Map<String, String> attributes, final ModelEntity modelEntity) throws ParseException { if (!entityName.equals(currentEntity)) { endDocument(); } if (printWriter == null) { try { currentEntity = entityName; printWriter = projectImportTemporaryFiles.getWriter(entityName); } catch (IOException e) { throw new ParseException(e.getMessage()); } } // Create a GenericEntity final GenericEntity genericEntity = new GenericEntity(delegator, modelEntity, attributes); genericEntity.writeXmlText(printWriter, null); }
public static Document makeXmlDocument(Collection<GenericValue> values) { Document document = UtilXml.makeEmptyXmlDocument("entity-engine-xml"); if (document == null) return null; addToXmlDocument(values, document); return document; }
/** * Get all primary keys from the model entity and bind their values * to the an SQL statement (SQL-Processor) * * @param sqlP * @param list * @param entity * @throws GenericEntityException */ public static void setPkValues(SQLProcessor sqlP, ModelEntity modelEntity, GenericEntity entity, ModelFieldTypeReader modelFieldTypeReader) throws GenericEntityException { for (int j = 0; j < modelEntity.getPksSize(); j++) { ModelField curField = modelEntity.getPk(j); // for where clause variables only setValue if not null... if (entity.dangerousGetNoCheckButFast(curField) != null) { setValue(sqlP, curField, entity, modelFieldTypeReader); } } }
GenericEntity entityCopy = new GenericEntity(entity); Object stampField = entity.get(ModelEntity.STAMP_FIELD); if ((stampField != null) && (!stampField.equals(entityCopy.get(ModelEntity.STAMP_FIELD)))) { String lockedTime = entityCopy.getTimestamp(ModelEntity.STAMP_FIELD).toString(); entity.set(ModelEntity.STAMP_FIELD, UtilDateTime.nowTimestamp()); throw new GenericEntityException("while updating: " + entity.toString(), e); } finally { sqlP.close();
GenericPK tempPK = entity.getPrimaryKey(); ModelEntity modelEntity = entity.getModelEntity(); Collection keys = entity.getAllKeys(); if (entity.get(curField.getName()) == null) { if (tempPK.get(curField.getName()) != null) { } else if (!entity.get(curField.getName()).equals(tempPK.get(curField.getName()))) {