Methods Summary |
---|
public void | addConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)PUBLIC:
A type conversion value is a two-way mapping from the database to the object.
The database value will be substituted for the object value when read,
and the object value will be substituted for database value when written.
Note that each field/attribute value must have one and only one attribute/field value to maintain a two-way mapping.
if (fieldValue == null) {
fieldValue = Helper.getNullWrapper();
}
if (attributeValue == null) {
attributeValue = Helper.getNullWrapper();
}
getFieldToAttributeValues().put(fieldValue, attributeValue);
getAttributeToFieldValues().put(attributeValue, fieldValue);
|
public void | addToAttributeOnlyConversionValue(java.lang.Object fieldValue, java.lang.Object attributeValue)PUBLIC:
An attribute only conversion value is a one-way mapping from the database to the object.
This can be used if multiple database values are desired to be mapped to the same object value.
Note that when written only the default value will be used for the attribute, not this value.
if (fieldValue == null) {
fieldValue = Helper.getNullWrapper();
}
if (attributeValue == null) {
attributeValue = Helper.getNullWrapper();
}
getFieldToAttributeValues().put(fieldValue, attributeValue);
|
public void | convertClassNamesToClasses(java.lang.ClassLoader classLoader)INTERNAL:
Convert all the class-name-based settings in this converter to actual
class-based settings. This method is used when converting a project
that has been built with class names to a project with classes.
// Does nothing right now but was implemented since EnumTypeConverter
// is dependent on this method but we need to avoid JDK 1.5
// dependencies. AbstractDirectMapping will call this method.
|
public java.lang.Object | convertDataValueToObjectValue(java.lang.Object fieldValue, oracle.toplink.essentials.sessions.Session session)INTERNAL:
Returns the corresponding attribute value for the specified field value.
Object attributeValue = null;
if (fieldValue == null) {
attributeValue = getFieldToAttributeValues().get(Helper.getNullWrapper());
} else {
try {
fieldValue = ((AbstractSession)session).getDatasourcePlatform().getConversionManager().convertObject(fieldValue, getFieldClassification());
} catch (ConversionException e) {
throw ConversionException.couldNotBeConverted(mapping, mapping.getDescriptor(), e);
}
attributeValue = getFieldToAttributeValues().get(fieldValue);
if (attributeValue == null) {
if (getDefaultAttributeValue() != null) {
attributeValue = getDefaultAttributeValue();
} else {
// CR#3779
throw DescriptorException.noFieldValueConversionToAttributeValueProvided(fieldValue, getMapping().getField(), getMapping());
}
}
}
return attributeValue;
|
public java.lang.Object | convertObjectValueToDataValue(java.lang.Object attributeValue, oracle.toplink.essentials.sessions.Session session)INTERNAL:
Convert to the data value.
Object fieldValue;
if (attributeValue == null) {
fieldValue = getAttributeToFieldValues().get(Helper.getNullWrapper());
} else {
fieldValue = getAttributeToFieldValues().get(attributeValue);
if (fieldValue == null) {
throw DescriptorException.noAttributeValueConversionToFieldValueProvided(attributeValue, getMapping());
}
}
return fieldValue;
|
public java.util.Map | getAttributeToFieldValues()INTERNAL:
Get the attribute to field mapping.
return attributeToFieldValues;
|
public java.lang.Object | getDefaultAttributeValue()PUBLIC:
The default value can be used if the database can possibly store additional values then those that
have been mapped. Any value retreived from the database that is not mapped will be substitued for the default value.
return defaultAttributeValue;
|
public java.lang.Class | getFieldClassification()INTERNAL:
Get the type of the field value to allow conversion from the database.
return fieldClassification;
|
public java.lang.Class | getFieldClassification(oracle.toplink.essentials.internal.helper.DatabaseField fieldToClassify)INTERNAL:
Return the classifiction for the field contained in the mapping.
This is used to convert the row value to a consistent java value.
By default this is null which means unknown.
return getFieldClassification();
|
public java.lang.String | getFieldClassificationName()
if ((fieldClassificationName == null) && (fieldClassification != null)) {
fieldClassificationName = fieldClassification.getName();
}
return fieldClassificationName;
|
public java.util.Map | getFieldToAttributeValues()INTERNAL:
Get the field to attribute mapping.
return fieldToAttributeValues;
|
protected oracle.toplink.essentials.mappings.DatabaseMapping | getMapping()INTERNAL:
Return the mapping.
return mapping;
|
public void | initialize(oracle.toplink.essentials.mappings.DatabaseMapping mapping, oracle.toplink.essentials.sessions.Session session)INTERNAL:
Set the mapping.
this.mapping = mapping;
initializeFieldClassification(session);
|
public void | initializeFieldClassification(oracle.toplink.essentials.sessions.Session session)INTERNAL:
Set the field classification through searching the fields hashtable.
if (getFieldToAttributeValues().isEmpty()) {
return;
}
Class type = null;
Iterator fieldValuesEnum = getFieldToAttributeValues().keySet().iterator();
while (fieldValuesEnum.hasNext() && (type == null)) {
Object value = fieldValuesEnum.next();
if (value != Helper.getNullWrapper()) {
type = value.getClass();
}
}
setFieldClassification(type);
// CR#... Mapping must also have the field classification.
if (getMapping().isDirectToFieldMapping()) {
AbstractDirectMapping directMapping = (AbstractDirectMapping)getMapping();
// Allow user to specify field type to override computed value. (i.e. blob, nchar)
if (directMapping.getFieldClassification() == null) {
directMapping.setFieldClassification(type);
}
}
|
public boolean | isMutable()INTERNAL:
If the converter converts the value to a non-atomic value, i.e.
a value that can have its' parts changed without being replaced,
then it must return false, serialization can be non-atomic.
return false;
|
public boolean | isObjectTypeMapping()INTERNAL:
return true;
|
public void | mapBooleans()PUBLIC:
This is a very specific protocol which maps fieldValues "T" and "F"
to true and false respectively.
addConversionValue("F", new Boolean(false));
addConversionValue("T", new Boolean(true));
|
public void | mapGenders()PUBLIC:
This is a very specific protocol which maps fieldValues "F" and "M"
to "Female" and "Male" respectively.
addConversionValue("F", "Female");
addConversionValue("M", "Male");
|
public void | mapResponses()PUBLIC:
This is a very specific protocol which maps fieldValues "Y" and "N"
to "Yes" and "No" respectively.
addConversionValue("Y", "Yes");
addConversionValue("N", "No");
|
public void | setAttributeToFieldValues(java.util.Map attributeToFieldValues)INTERNAL:
Set the attribute to field mapping.
this.attributeToFieldValues = attributeToFieldValues;
|
public void | setDefaultAttributeValue(java.lang.Object defaultAttributeValue)PUBLIC:
The default value can be used if the database can possibly store additional values then those that
have been mapped. Any value retreived from the database that is not mapped will be substitued for the default value.
this.defaultAttributeValue = defaultAttributeValue;
|
public void | setFieldClassification(java.lang.Class fieldClassification)INTERNAL:
Set the type of the field value to allow conversion from the database.
this.fieldClassification = fieldClassification;
|
public void | setFieldClassificationName(java.lang.String fieldClassificationName)
this.fieldClassificationName = fieldClassificationName;
|
public void | setFieldToAttributeValueAssociations(java.util.Vector fieldToAttributeValueAssociations)INTERNAL:
Set a collection of the field to attribute value associations.
setFieldToAttributeValues(new Hashtable(fieldToAttributeValueAssociations.size() + 1));
setAttributeToFieldValues(new Hashtable(fieldToAttributeValueAssociations.size() + 1));
for (Enumeration associationsEnum = fieldToAttributeValueAssociations.elements();
associationsEnum.hasMoreElements();) {
Association association = (Association)associationsEnum.nextElement();
addConversionValue(association.getKey(), association.getValue());
}
|
public void | setFieldToAttributeValues(java.util.Map fieldToAttributeValues)INTERNAL:
Set the field to attribute mapping.
this.fieldToAttributeValues = fieldToAttributeValues;
|
protected void | setMapping(oracle.toplink.essentials.mappings.DatabaseMapping mapping)INTERNAL:
Set the mapping.
this.mapping = mapping;
|