org.starhope.appius.mb
Class Currency

java.lang.Object
  extended by org.starhope.appius.sql.SQLPeerDatum
      extended by org.starhope.appius.sql.SQLPeerEnum
          extended by org.starhope.appius.mb.Currency
All Implemented Interfaces:
Serializable

public class Currency
extends SQLPeerEnum

Author:
brpocock
See Also:
Serialized Form

Field Summary
private  String code
          The ISO-4217 currency code (three letters); "USD" is U.S.
private static long serialVersionUID
           
private  String symbol
          The display character sequence.
 
Fields inherited from class org.starhope.appius.sql.SQLPeerEnum
enumeration, instance
 
Constructor Summary
private Currency()
          WRITEME
protected Currency(int id)
           
private Currency(ResultSet resultSet)
           
 
Method Summary
protected  void cache(ResultSet set)
          This method caches into the internal "enumeration" hashmap the results of an SQL query specific to this SQLPeerEnum class of object.
 void flush()
           
static Currency get_USD()
          This is a quick "semantic sugar" to pick up U.S.
static Currency get(org.json.JSONObject object)
           
static Currency get(String id)
           
static Currency getByCode(String string)
           
protected  String getCacheUniqueID()
          This is an overriding method.
 String getCode()
          Get the three-character (ISO-4217) currency code.
protected  PreparedStatement getStatement(Connection connection)
          WRITEME: document this method (brpocock, Aug 14, 2009)
 String getSymbol()
           
 void set(org.json.JSONObject o)
           
protected  void set(ResultSet rs)
           
 void setCode(String newCode)
          Change the currency code for this instance.
 void setSymbol(String newSymbol)
          Set the user-visible displayed symbol of this currency.
 
Methods inherited from class org.starhope.appius.sql.SQLPeerEnum
doRealCacheResetStatic, equals, equals, get, get, getEnumeration, getID, getID, getString, getString, hashCode, invalidateCache, invalidateCaches, prepCache, resetCache, set, set, toJSON, toString
 
Methods inherited from class org.starhope.appius.sql.SQLPeerDatum
changed, findInCache, get, saveInCache
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

code

private String code
The ISO-4217 currency code (three letters); "USD" is U.S. Dollar, and "EUR" is the Euro.


symbol

private String symbol
The display character sequence. For US Dollars, it's " US $ "; for Euros, it's just the Euro sign

Constructor Detail

Currency

private Currency()
WRITEME


Currency

protected Currency(int id)
Parameters:
id - The integral ID number for the type of currency to be instantiated

Currency

private Currency(ResultSet resultSet)
Parameters:
resultSet - the SQL row from which to instantiate this currency object
Method Detail

get

public static Currency get(org.json.JSONObject object)
                    throws RuntimeException,
                           NotFoundException,
                           org.json.JSONException
Parameters:
object - the JSON data describing the currency wanted
Returns:
the Currency object
Throws:
org.json.JSONException - if the JSON data is badly-formed
NotFoundException - if the object isn't found in the database
RuntimeException - if something else bad happens

get

public static Currency get(String id)
                    throws RuntimeException,
                           NotFoundException
Parameters:
id - database ID
Returns:
currency with that database ID
Throws:
NotFoundException - if it's not found in the database
RuntimeException - if something else wonky were to happen

get_USD

public static Currency get_USD()
This is a quick "semantic sugar" to pick up U.S. Dollars as a currency format, since that's realistically the only one we're dealing with at the moment.

Returns:
a Currency object representing U.S. Dollars.

getByCode

public static Currency getByCode(String string)
                          throws NotFoundException
Parameters:
string - ISO-4217 currency code
Returns:
a Currency object
Throws:
NotFoundException - if it can't be found

cache

protected void cache(ResultSet set)
              throws SQLException
Description copied from class: SQLPeerEnum
This method caches into the internal "enumeration" hashmap the results of an SQL query specific to this SQLPeerEnum class of object. The ResultSet must have a long (probably INT UNSIGNED) in the first column of the results, and the string value for it in column 1.

Overrides:
cache in class SQLPeerEnum
Parameters:
set - The ResultSet from the SQL query
Throws:
SQLException - if anything goes wrong from the query
See Also:
SQLPeerEnum.cache(java.sql.ResultSet)

flush

public void flush()
Specified by:
flush in class SQLPeerDatum
See Also:
SQLPeerDatum.flush()

getCacheUniqueID

protected String getCacheUniqueID()
This is an overriding method.

Overrides:
getCacheUniqueID in class SQLPeerEnum
Returns:
The local (Stringified) version of an unique ID; usually the database ID column
See Also:
SQLPeerDatum.getCacheUniqueID()

getCode

public String getCode()
Get the three-character (ISO-4217) currency code.

Returns:
A string of three uppercase characters

getStatement

protected PreparedStatement getStatement(Connection connection)
Description copied from class: SQLPeerEnum
WRITEME: document this method (brpocock, Aug 14, 2009)

Specified by:
getStatement in class SQLPeerEnum
Parameters:
connection - WRITEME
Returns:
WRITEME
See Also:
SQLPeerEnum.getStatement(java.sql.Connection)

getSymbol

public String getSymbol()
Returns:
A string of 1-5 characters suitable for unambiguous representation of this currency.
See Also:
Returns the currency symbol for user presentation of prices.

set

public void set(org.json.JSONObject o)
Overrides:
set in class SQLPeerDatum
Parameters:
o - The JSON data to be used to set the value of this object
See Also:
CastsToJSON.set(org.json.JSONObject)

set

protected void set(ResultSet rs)
Specified by:
set in class SQLPeerDatum
Parameters:
rs - The result of an SQL query, with the cursor already pointed at the row describing this specific instance of the object.
See Also:
SQLPeerDatum.set(java.sql.ResultSet)

setCode

public void setCode(String newCode)
             throws DataException
Change the currency code for this instance.

Parameters:
newCode - The new currency code to be set (ISO-4217, uppercase, e.g. "USD")
Throws:
DataException - if the specification does not consist of three AppiusCharacter.UPPERCASE_LETTER characters.

setSymbol

public void setSymbol(String newSymbol)
               throws DataException
Set the user-visible displayed symbol of this currency. E.G. for the US Dollar, this is "US $"; Mexican New Peso, "Mx $"; for the Canadian dollar, "CA $"; for the Chinese RMB, it might be "RMB", versus Japanese Yen "Jp ¥"; Euro, just "€" (since there's no confusion with any other country using a similar currency symbol)

Parameters:
newSymbol - The new symbol string to be used for this currency
Throws:
DataException - if the new symbol string is not supplied, or is more than 5 characters long