Rakesh API

biz.wedoit4u.databeans
Class CustomerBean

java.lang.Object
  extended by biz.wedoit4u.databeans.CustomerBean
All Implemented Interfaces:
java.io.Serializable

public class CustomerBean
extends java.lang.Object
implements java.io.Serializable

A java bean that represents a record in the customers table. This bean is used to cache the values read from the database, and to make modifications you need to the bean fields, and then send it back to the database for updating the associated record. All instances of this class are cached into a Map object that is stored in the System.getProperties() object under a property with name CACHE_NAME. All instances variables are public except the primary key column customer_id.

Copyright 2003, Rakesh Vidyadharan

Version:
$Id: CustomerBean.java,v 1.10 2004/05/26 11:42:31 rakesh Exp $
Author:
Rakesh Vidyadharan on 9th September 2003
See Also:
Serialized Form

Field Summary
 java.util.Date activationDate
          The value in the activation_date column.
 char active
          The value in the active column.
private static java.util.Map cache
          The Map that is used to cache instances of this bean.
static java.lang.String CACHE_NAME
          A constant that denotes the name of the system property at which all instances of this class are cached.
 java.util.Date creationDate
          The value in the creation_date column.
private  int customerId
          The value in the customer_id column.
 int customerTypeId
          The value in the customer_type_id column.
 java.lang.String domain
          The value in the domain column.
 java.lang.String email
          The value in the email column.
 java.util.Date expirationDate
          The value in the expiration_date column.
private static java.lang.Object lockObject
          An object that is used to synchronise modifications to the system cache of instances of these beans.
 java.lang.String password
          The value in the password column.
 java.lang.String username
          The value in the username column.
 
Constructor Summary
private CustomerBean()
          Default constructor.
 
Method Summary
static CustomerBean create(int customerId, java.lang.String username, java.lang.String password, java.lang.String email, java.lang.String domain, char active, java.util.Date activationDate, java.util.Date expirationDate, int customerTypeId)
          Create a new customers record with the values specified for all the columns in the table.
static void delete(CustomerBean cb)
          Delete the specified instance of this class from the system cache as well as from the database.
static java.util.Collection findAll()
          Return a Collection of bean instances that represent all the records in the customers table.
static java.util.Collection findByCustomerType(int customerTypeId)
          Return a Collection of bean instances that represent all the records in the customers table that are associated with the specified customer_type_id.
private static java.util.Collection getCollection(java.util.Collection list)
          Return a Collection of bean instances from the specified Collection of primary key values.
 int getCustomerId()
          Returns customerId.
static CustomerBean getInstance(int customerId)
          Fetch the instance of the bean from the system cache indentified by the primary key column customerId.
static CustomerBean getInstance(java.lang.String username, java.lang.String password)
          Return the bean instance identified by the username and password values specified.
 void save()
          Write back all the values in the bean fields to the database.
static void setInstance(CustomerBean ctb)
          Add the specified bean instance to the system cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lockObject

private static final java.lang.Object lockObject
An object that is used to synchronise modifications to the system cache of instances of these beans.


cache

private static final java.util.Map cache
The Map that is used to cache instances of this bean.


CACHE_NAME

public static final java.lang.String CACHE_NAME
A constant that denotes the name of the system property at which all instances of this class are cached.

See Also:
Constant Field Values

customerId

private int customerId
The value in the customer_id column.


username

public java.lang.String username
The value in the username column.


password

public java.lang.String password
The value in the password column.


email

public java.lang.String email
The value in the email column.


domain

public java.lang.String domain
The value in the domain column.


active

public char active
The value in the active column.


creationDate

public java.util.Date creationDate
The value in the creation_date column.


activationDate

public java.util.Date activationDate
The value in the activation_date column.


expirationDate

public java.util.Date expirationDate
The value in the expiration_date column.


customerTypeId

public int customerTypeId
The value in the customer_type_id column.

Constructor Detail

CustomerBean

private CustomerBean()
Default constructor. Cannot be directly instantiated.

Method Detail

create

public static final CustomerBean create(int customerId,
                                        java.lang.String username,
                                        java.lang.String password,
                                        java.lang.String email,
                                        java.lang.String domain,
                                        char active,
                                        java.util.Date activationDate,
                                        java.util.Date expirationDate,
                                        int customerTypeId)
                                 throws CMAException
Create a new customers record with the values specified for all the columns in the table. If you wish to use the database sequence to generate the customer_id value, specify a value of 0 for the customer_id. Creating a new instance will also add the new instance of the system cache, unless the customerId value specified is 0.

Parameters:
customerId - - The customer_id value.
username - - The username value.
password - - The password value.
email - - The email value. This may be null.
domain - - The domain value. This may be null.
active - - The active value.
activationDate - - The activation_date value.
expirationDate - - The expiration_date value.
customerTypeId - - The customer_type_id value.
Throws:
CMAException - - If an attempt is made to create an instance of the object that already exists, as identified by the customerTypeId value.

delete

public static final void delete(CustomerBean cb)
                         throws CMAException
Delete the specified instance of this class from the system cache as well as from the database.

Parameters:
cb - - The bean instance that is to be removed.
Throws:
CMAException - - If errors are encountered while removing the associated record in the database.

save

public void save()
          throws CMAException
Write back all the values in the bean fields to the database. All the columns in the customers table are updated with the values in the bean fields.

Throws:
CMAException - - If errors are encountered while writing the values to the database.

getInstance

public static final CustomerBean getInstance(int customerId)
                                      throws CMAException
Fetch the instance of the bean from the system cache indentified by the primary key column customerId.

Parameters:
customerId - - The primary key value based upon which to find the appropriate bean instance.
Throws:
CMAException - - If the appropriate bean instance is not found.

findAll

public static final java.util.Collection findAll()
                                          throws CMAException
Return a Collection of bean instances that represent all the records in the customers table.

Returns:
Collection - The collection of java bean instances.
Throws:
CMAException - - If errors are encountered while fetching all the bean instances.

findByCustomerType

public static final java.util.Collection findByCustomerType(int customerTypeId)
                                                     throws CMAException
Return a Collection of bean instances that represent all the records in the customers table that are associated with the specified customer_type_id.

Parameters:
customerTypeId - - The customer_type_id foreign key.
Returns:
Collection - The collection of java bean instances.
Throws:
CMAException - - If errors are encountered while fetching all the bean instances.

getCollection

private static final java.util.Collection getCollection(java.util.Collection list)
                                                 throws CMAException
Return a Collection of bean instances from the specified Collection of primary key values.

Parameters:
list - - The Collection of primary key values.
Throws:
CMAException - - If errors are encountered while fetching the bean instances.

getInstance

public static final CustomerBean getInstance(java.lang.String username,
                                             java.lang.String password)
                                      throws CMAException
Return the bean instance identified by the username and password values specified.

Parameters:
username - - The username value.
password - - The password value.
Throws:
CMAException - - If errors are encountered while fetching the bean instance.

setInstance

public static final void setInstance(CustomerBean ctb)
Add the specified bean instance to the system cache. This method follows the general contract provided by the Map interface in that, if an entry with the same key already exists, then that entry is replaced, or a new one created. This method uses the lockObject to synchronise modifications to the Map cache.

Parameters:
ctb - - The instance that is being added to the system cache.

getCustomerId

public final int getCustomerId()
Returns customerId.

Returns:
int - The value/reference of/to customerId.

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan