use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class PersistentHelper method generateKeyCriteria.
/**
* This will generate a Criteria for reloading the input persistent object, based on the persistent class name and its key values.
* Note: This method will determine the key fields by looking up the getKeyFields method in the corresponding meta class for the input persistent object.
*
* @param object The persistent object.
* @throws ClassNotFoundException if the Meta class for the input persistent class is not found.
* @throws NoSuchMethodException if the Meta class does not have the 'public static FieldMetaData[] getKeyFields()' method.
* @throws IllegalAccessException if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class enforces Java language access control and the underlying method is inaccessible.
* @throws InvocationTargetException if the 'public static FieldMetaData[] getKeyFields()' method of the Meta class throws an exception.
* @throws IllegalArgumentException if the input persistent class does not have any key-fields or if any of the key-fields is null.
* @return a Criteria for reloading the persistent object.
*/
public static Criteria generateKeyCriteria(IPersistent object) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, IllegalArgumentException {
Criteria criteria = new Criteria();
criteria.setTable(object.getClass().getName());
FieldMetaData[] keyFields = getKeyFields(object.getClass().getName());
if (keyFields != null && keyFields.length > 0) {
for (FieldMetaData keyField : keyFields) {
String keyFieldName = keyField.getName();
Object keyFieldValue = BeanHelper.getField(object, keyFieldName);
if (keyFieldValue != null) {
criteria.addCriteria(keyFieldName, keyFieldValue);
} else {
String str = "KeyCriteria cannot be generated. The input persistent object has a null value for its key-field " + object + ':' + keyFieldName;
if (log.isDebugEnabled())
log.debug(str);
throw new IllegalArgumentException(str);
}
}
} else {
String str = "KeyCriteria cannot be generated. The input persistent object does not have any key fields defined in its meta class: " + object.getClass().getName();
if (log.isDebugEnabled())
log.debug(str);
throw new IllegalArgumentException(str);
}
return criteria;
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class FlexCriteriaBean method findKeys.
/**
* Returns an array of key field names for the input domain class.
*/
private String[] findKeys(String domainClassName) throws FrameworkException {
// Search for the first available class-level primary-key rule
IObjectRuleIntrospector introspector = RulesEngineFactory.getRulesEngine().getObjectRuleIntrospector(domainClassName, null);
String[] keys = introspector.getPrimaryKey();
// Search for corresponding DomainMeta class, if required
if (keys == null || keys.length == 0) {
try {
FieldMetaData[] keyFields = PersistentHelper.getKeyFields(domainClassName);
if (keyFields != null) {
keys = new String[keyFields.length];
for (int i = 0; i < keyFields.length; i++) keys[i] = keyFields[i].getName();
}
} catch (Exception e) {
// do nothing
}
}
return keys != null && keys.length > 0 ? keys : null;
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class Persistent method hashCode.
/**
* Returns the hashCode of this object based on it's primary key.
*
* @return the hashCode of this object based on it's primary key.
*/
public int hashCode() {
// return (getAssetTk() != null ? getAssetTk().hashCode() : 0);
int result = 0;
// IStoredProcedure implementations does not have hashCode or key fields, so just return the super.hashCode().
if (IStoredProcedure.class.isAssignableFrom(this.getClass())) {
return super.hashCode();
}
try {
FieldMetaData[] keyFields = PersistentHelper.getKeyFields(this.getClass().getName());
if (keyFields != null && keyFields.length > 0) {
for (FieldMetaData keyField : keyFields) {
String keyFieldName = keyField.getName();
Object thisValue = BeanHelper.getField(this, keyFieldName);
if (thisValue != null)
result += thisValue.hashCode();
}
if (log.isDebugEnabled())
log.debug("Output=" + result);
return result;
} else {
if (log.isDebugEnabled())
log.debug("Will invoke super.hashCode() since key fields cannot be determined for the class '" + this.getClass() + '\'');
}
} catch (Exception e) {
log.warn("Will invoke super.hashCode() since an error occurred while evaluating the key fields", e);
}
result = super.hashCode();
if (log.isDebugEnabled())
log.debug("Output from super.hashCode() is " + result);
return result;
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class Persistent method equals.
/**
* Compares this object with another Persistent object.
* Returns a true if both the objects have the same primary key.
*
* @param obj the other Persistent object.
* @return a true if both the objects have the same primary key.
*/
public boolean equals(Object obj) {
boolean result = false;
if (obj != null && this.getClass() == obj.getClass()) {
try {
FieldMetaData[] keyFields = PersistentHelper.getKeyFields(this.getClass().getName());
if (keyFields != null && keyFields.length > 0) {
for (FieldMetaData keyField : keyFields) {
String keyFieldName = keyField.getName();
Object thisValue = BeanHelper.getField(this, keyFieldName);
Object targetValue = BeanHelper.getField(obj, keyFieldName);
result = thisValue == null ? targetValue == null : thisValue.equals(targetValue);
if (log.isDebugEnabled())
log.debug(keyFieldName + ": thisValue=" + thisValue + ", targetValue=" + targetValue + ", comparison=" + result);
if (!result)
break;
}
if (log.isDebugEnabled())
log.debug("Output=" + result);
return result;
} else {
if (log.isDebugEnabled())
log.debug("Will invoke super.equals() since key fields cannot be determined for the class '" + this.getClass() + '\'');
}
} catch (Exception e) {
log.warn("Will invoke super.equals() since an error occurred while comparing the key fields", e);
}
} else {
if (log.isDebugEnabled())
log.debug("Will invoke super.equals() since the " + (obj == null ? "argument is null" : "argument's class '" + obj.getClass() + "' does not match the current class '" + this.getClass() + '\''));
}
result = super.equals(obj);
if (log.isDebugEnabled())
log.debug("Output from super.equals() is " + result);
return result;
}
use of org.jaffa.metadata.FieldMetaData in project jaffa-framework by jaffa-projects.
the class EditBoxForm method getFieldLinkedToCCWM.
public WidgetModel getFieldLinkedToCCWM() {
if (w_fieldLinkedToCC == null) {
FieldMetaData meta = new StringFieldMetaData("SomeName2", "SomeToken2", Boolean.FALSE, null, null, FieldMetaData.UPPER_CASE);
w_fieldLinkedToCC = new EditBoxModel(meta);
w_fieldLinkedToCC.setValue(getFieldLinkedToCC());
}
return w_fieldLinkedToCC;
}
Aggregations