FileDocCategorySizeDatePackage
AbstractRecord.javaAPI DocGlassfish v2 API15528Thu Jul 19 11:51:58 BST 2007oracle.toplink.essentials.internal.sessions

AbstractRecord

public abstract class AbstractRecord extends Object implements Serializable, Record, Cloneable, Map

Purpose: Define the abstract definition of a record for internal use. Public API should reference the Record interface. Subclasses are DatabaseRecord and XMLRecord.

Responsibilities:

  • Implement the Record and Map interfaces.
see
DatabaseField

Fields Summary
protected Vector
fields
Use vector to store the fields/values for optimal performance.
protected Vector
values
Use vector to store the fields/values for optimal performance.
protected DatabaseField
lookupField
Optimize field creation for field name lookup.
public static final NoEntry
noEntry
INTERNAL: indicator showing that no entry exists for a given key.
Constructors Summary
public AbstractRecord()
INTERNAL: TopLink converts JDBC results to collections of rows.

        this.fields = new Vector();
        this.values = new Vector();
    
public AbstractRecord(int initialCapacity)
INTERNAL: TopLink converts JDBC results to collections of rows.

        this.fields = new Vector(initialCapacity);
        this.values = new Vector(initialCapacity);
    
public AbstractRecord(Vector fields, Vector values)
INTERNAL: TopLink converts JDBC results to collections of rows.

        this.fields = fields;
        this.values = values;
    
Methods Summary
public voidadd(oracle.toplink.essentials.internal.helper.DatabaseField key, java.lang.Object value)
INTERNAL: Add the field-value pair to the row. Will not check, will simply add to the end of the row

        getFields().addElement(key);
        getValues().addElement(value);
    
public voidclear()
PUBLIC: Clear the contents of the row.

        this.fields = new Vector();
        this.values = new Vector();
    
public java.lang.Objectclone()
INTERNAL: Clone the row and its values.

        try {
            AbstractRecord clone = (AbstractRecord)super.clone();
            clone.setFields((Vector)getFields().clone());
            clone.setValues((Vector)getValues().clone());
            return clone;
        } catch (CloneNotSupportedException exception) {
        }

        return null;
    
public booleancontains(java.lang.Object value)
PUBLIC: Check if the value is contained in the row.

        return containsValue(value);
    
public booleancontainsKey(oracle.toplink.essentials.internal.helper.DatabaseField key)
INTERNAL: Check if the field is contained in the row.

        // Optimize check.
        int index = key.getIndex();
        if ((index >= 0) && (index < getFields().size())) {
            DatabaseField field = (DatabaseField)getFields().elementAt(index);
            if ((field == key) || field.equals(key)) {
                return true;
            }
        }
        return getFields().contains(key);
    
public booleancontainsKey(java.lang.Object key)
PUBLIC: Check if the field is contained in the row. Conform to hashtable interface.

        if (key instanceof String) {
            return containsKey((String)key);
        }
        if (key instanceof DatabaseField) {
            return containsKey((DatabaseField)key);
        }

        return false;
    
public booleancontainsKey(java.lang.String fieldName)
PUBLIC: Check if the field is contained in the row.

        // Optimized the field creation.
        if (this.lookupField == null) {
            this.lookupField = new DatabaseField(fieldName);
        } else {
            this.lookupField.resetQualifiedName(fieldName);
        }
        return containsKey(this.lookupField);
    
public booleancontainsValue(java.lang.Object value)
PUBLIC: Check if the value is contained in the row.

        return getValues().contains(value);
    
public java.util.Enumerationelements()
PUBLIC: Returns an Enumeration of the values.

        return getValues().elements();
    
public java.util.SetentrySet()
PUBLIC: Returns a set of the keys.

        int size = this.size();
        Map tempMap = new HashMap(size);
        for (int i = 0; i < size; i++) {
            tempMap.put(this.getFields().elementAt(i), this.getValues().elementAt(i));
        }
        return tempMap.entrySet();
    
public java.lang.Objectget(java.lang.Object key)
PUBLIC: Retrieve the value for the field name. A field is constructed on the name to check the hash table. If missing null is returned.

        if (key instanceof String) {
            return get((String)key);
        } else if (key instanceof DatabaseField) {
            return get((DatabaseField)key);
        }
        return null;
    
public java.lang.Objectget(java.lang.String fieldName)
PUBLIC: Retrieve the value for the field name. A field is constructed on the name to check the hash table. If missing null is returned.

        Object value = getIndicatingNoEntry(fieldName);
        if (value == oracle.toplink.essentials.internal.sessions.AbstractRecord.noEntry) {
            return null;
        }
        return value;
    
public java.lang.Objectget(oracle.toplink.essentials.internal.helper.DatabaseField key)
INTERNAL: Retrieve the value for the field. If missing null is returned.

        Object value = getIndicatingNoEntry(key);
        if (value == oracle.toplink.essentials.internal.sessions.AbstractRecord.noEntry) {
            return null;
        }
        return value;
    
public oracle.toplink.essentials.internal.helper.DatabaseFieldgetField(oracle.toplink.essentials.internal.helper.DatabaseField key)
INTERNAL: Returns the row's field with the same name.

        // Optimize check.
        int index = key.getIndex();
        if ((index >= 0) && (index < getFields().size())) {
            DatabaseField field = (DatabaseField)getFields().elementAt(index);
            if ((field == key) || field.equals(key)) {
                return field;
            }
        }
        for (index = 0; index < getFields().size(); index++) {
            DatabaseField field = (DatabaseField)getFields().elementAt(index);
            if ((field == key) || field.equals(key)) {
                return field;
            }
        }
        return null;
    
public java.util.VectorgetFields()
INTERNAL:

        return fields;
    
public java.lang.ObjectgetIndicatingNoEntry(java.lang.String fieldName)
PUBLIC: Retrieve the value for the field name. A field is constructed on the name to check the hash table. If missing DatabaseRow.noEntry is returned.

        // Optimized the field creation.
        if (this.lookupField == null) {
            this.lookupField = new DatabaseField(fieldName);
        } else {
            this.lookupField.resetQualifiedName(fieldName);
        }
        return getIndicatingNoEntry(this.lookupField);
    
public java.lang.ObjectgetIndicatingNoEntry(oracle.toplink.essentials.internal.helper.DatabaseField key)
INTERNAL: Retrieve the value for the field. If missing DatabaseRow.noEntry is returned.

        // PERF: Direct variable access.
        // Optimize check.
        int index = key.getIndex();
        if ((index >= 0) && (index < this.fields.size())) {
            DatabaseField field = (DatabaseField)this.fields.elementAt(index);
            if ((field == key) || field.equals(key)) {
                return this.values.elementAt(index);
            }
        }
        index = this.fields.indexOf(key);
        if (index >= 0) {
            // PERF: If the fields index was not set, then set it.
            if (key.getIndex() == -1) {
                key.setIndex(index);
            }
            return this.values.elementAt(index);
        } else {
            return oracle.toplink.essentials.internal.sessions.AbstractRecord.noEntry;
        }
    
public java.lang.ObjectgetValues(oracle.toplink.essentials.internal.helper.DatabaseField key)

        return get(key);
    
public java.lang.ObjectgetValues(java.lang.String key)

        return get(key);
    
public java.util.VectorgetValues()
INTERNAL:

        return values;
    
public booleanisEmpty()
PUBLIC: Return if the row is empty.

        return size() == 0;
    
public java.util.SetkeySet()
PUBLIC: Returns a set of the keys.

        return new HashSet(getFields());
    
public java.util.Enumerationkeys()
PUBLIC: Returns an Enumeration of the DatabaseField objects.

        return getFields().elements();
    
public voidmergeFrom(oracle.toplink.essentials.internal.sessions.AbstractRecord row)
INTERNAL: Merge the provided row into this row. Existing field values in this row will be replaced with values from the provided row. Fields not in this row will be added from provided row. Values not in provided row will remain in this row.

        for (int index = 0; index < row.size(); ++index){
            this.put(row.getFields().get(index), row.getValues().get(index));
        }
    
public java.lang.Objectput(java.lang.Object key, java.lang.Object value)
PUBLIC: Add the field-value pair to the row.

        if (key instanceof String) {
            return put((String)key, value);
        } else if (key instanceof DatabaseField) {
            return put((DatabaseField)key, value);
        } else {
            throw ValidationException.onlyFieldsAreValidKeysForDatabaseRows();
        }
    
public java.lang.Objectput(java.lang.String key, java.lang.Object value)
PUBLIC: Add the field-value pair to the row.

        return put(new DatabaseField(key), value);
    
public java.lang.Objectput(oracle.toplink.essentials.internal.helper.DatabaseField key, java.lang.Object value)
INTERNAL: Add the field-value pair to the row.

        int index = getFields().indexOf(key);
        if (index >= 0) {
            Object oldValue = getValues().elementAt(index);
            replaceAt(value, index);
            return oldValue;
        } else {
            add(key, value);
        }

        return null;
    
public voidputAll(java.util.Map map)
PUBLIC: Add all of the elements.

        Iterator entriesIterator = map.entrySet().iterator();
        while (entriesIterator.hasNext()) {
            Map.Entry entry = (Map.Entry)entriesIterator.next();
            put(entry.getKey(), entry.getValue());
        }
    
public java.lang.Objectremove(java.lang.Object key)
INTERNAL: Remove the field key from the row.

        if (key instanceof String) {
            return remove((String)key);
        } else if (key instanceof DatabaseField) {
            return remove((DatabaseField)key);
        }
        return null;
    
public java.lang.Objectremove(java.lang.String fieldName)
INTERNAL: Remove the field key from the row.

        return remove(new DatabaseField(fieldName));
    
public java.lang.Objectremove(oracle.toplink.essentials.internal.helper.DatabaseField key)
INTERNAL: Remove the field key from the row.

        int index = getFields().indexOf(key);
        if (index >= 0) {
            getFields().removeElementAt(index);
            Object value = getValues().elementAt(index);
            getValues().removeElementAt(index);
            return value;
        }
        return null;
    
public voidreplaceAt(java.lang.Object value, int index)
INTERNAL: replaces the value at index with value

        getValues().setElementAt(value, index);
    
protected voidsetFields(java.util.Vector fields)

        this.fields = fields;
    
protected voidsetValues(java.util.Vector values)

        this.values = values;
    
public intsize()
PUBLIC: Return the number of field/value pairs in the row.

        return getFields().size();
    
public java.lang.StringtoString()
INTERNAL:

        StringWriter writer = new StringWriter();
        writer.write(Helper.getShortClassName(getClass()));
        writer.write("(");

        for (int index = 0; index < getFields().size(); index++) {
            writer.write(Helper.cr());
            writer.write("\t");
            writer.write(String.valueOf((getFields().elementAt(index))));
            writer.write(" => ");
            writer.write(String.valueOf((getValues().elementAt(index))));
        }
        writer.write(")");

        return writer.toString();
    
public java.util.Collectionvalues()
PUBLIC: Returns an collection of the values.

        return getValues();