001//
002// Name
003//     $RCSfile: KeyFieldValueList.java,v $
004// 
005// COPYRIGHT
006//    Copyright 2009-2015 Cloud Software Group, Inc. ALL RIGHTS RESERVED.
007//    Cloud Software Group, Inc. Confidential Information
008//
009// History
010//    $Revision: 1.1.2.8 $ $Date: 2015/01/27 03:24:50 $
011//
012package com.kabira.platform;
013
014import java.util.ArrayList;
015
016/**
017 * Class used to manage field values.
018 */
019public class KeyFieldValueList
020{
021    /**
022     * Creates a KeyFieldValueList instance.
023     */
024    public KeyFieldValueList()
025    {
026        m_entries = new ArrayList<KeyFieldEntry>();
027    }
028
029    /**
030     * Adds a field value pair.
031     *
032     * @param fieldName The field name.
033     * @param value     The value to use.
034     * @throws KeyNullValueError The given value is null.
035     * <p>
036     * When executed, this defines the value used for the given
037     * field. These field/value pairs are used when forming the key
038     * for a query, or for setting additional fields when a
039     * <code>getOrCreateSingleResult()</code> call results in an
040     * instance being created by the runtime.
041     * <p>
042     * Adding the same field more than once will result in
043     * a KeyMalformedQueryError exception if this instance
044     * is passed to KeyQuery.defineQuery() for a non-ordered key.
045     */
046    public void add(String fieldName, Object value)
047            throws KeyNullValueError
048    {
049        if (value == null)
050        {
051            throw new KeyNullValueError(
052                    "Null value for field " + fieldName +
053                            ", keys cannot have null values");
054        }
055        KeyFieldEntry f = new KeyFieldEntry();
056
057        f.m_name = fieldName;
058        f.m_value = value;
059        f.m_op = KeyComparisonOperator.EQ;
060
061        m_entries.add(f);
062    }
063
064    /**
065     * Removes all fields from the list.
066     */
067    public void clear()
068    {
069        m_entries.clear();
070    }
071
072    ArrayList<KeyFieldEntry> getEntries()
073    {
074        return new ArrayList<KeyFieldEntry>(m_entries);
075    }
076
077    ArrayList<KeyFieldEntry> m_entries;
078}