Rakesh API

biz.wedoit4u.databeans
Class ContentBean

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

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

The implementation of the entity bean that represents a record in the contents table. This bean can be used to cache the contents of a database record, as well as insulate entity beans from client code. All instance variables are public, except the primary key column (content_id), which has only a accessor. All instances of this class are cached in the runtime environment System.getProperties(), under a property indentified by the value of CACHE_NAME.

Copyright 2003, Rakesh Vidyadharan

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

Field Summary
 java.lang.String body
          The value in the body column.
 java.lang.String brief
          The value in the picture 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.
 int categoryId
          The value in the category_id column.
private  int contentId
          The value in the content_id column.
 java.util.Date creationDate
          The value in the creation_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.util.Date modificationDate
          The value in the modification_date column.
 java.lang.String picture
          The value in the picture column.
 java.lang.String title
          The value in the title column.
 
Constructor Summary
private ContentBean()
          Default constructor.
 
Method Summary
static ContentBean create(int contentId, int categoryId, java.lang.String title, java.lang.String brief, java.lang.String picture, java.lang.String body)
          Create a new record in the content table with all the columns specified.
static void delete(ContentBean 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 categories table.
static java.util.Collection findByCategory(int categoryId)
          Return a Collection of bean instances that represent all the records in the categories table that are associated with the specified category_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 getContentId()
          Returns contentId.
static ContentBean getInstance(int contentId)
          Fetch the bean instance uniquely identified by the primary key value specified from the system cache.
 void save()
          Write back all the values in the bean fields to the database.
static void setInstance(ContentBean 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

contentId

private int contentId
The value in the content_id column.


categoryId

public int categoryId
The value in the category_id column.


title

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


brief

public java.lang.String brief
The value in the picture column.


picture

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


body

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


creationDate

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


modificationDate

public java.util.Date modificationDate
The value in the modification_date column.

Constructor Detail

ContentBean

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

Method Detail

create

public static final ContentBean create(int contentId,
                                       int categoryId,
                                       java.lang.String title,
                                       java.lang.String brief,
                                       java.lang.String picture,
                                       java.lang.String body)
                                throws CMAException
Create a new record in the content table with all the columns specified. When creating a temporary instace (for client code) specify a value of 0 for the contentId parameter. Creating a new instance of the class also adds the new instance to the system cache, unless the contentId value is 0.

Parameters:
contentId - - The new primary key value to use.
categoryId - - The category_id to use for the new content.
title - - The title value to set.
brief - - The brief value to set.
picture - - The picture value to set.
body - - The body value to set.
Returns:
ContentBean - The new instance that was created.
Throws:
CMAException - - If an attempt is made to create an instance of the object that already exists, as identified by the customerTypeId value.

save

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

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

delete

public static final void delete(ContentBean 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.

getInstance

public static final ContentBean getInstance(int contentId)
                                     throws CMAException
Fetch the bean instance uniquely identified by the primary key value specified from the system cache.

Parameters:
contentId - - The content_id primary key value.
Returns:
ContentBean - The appropriate entity bean instance.
Throws:
CMAException - - If the specified bean instance does not exist in the cache

findAll

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

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

findByCategory

public static final java.util.Collection findByCategory(int categoryId)
                                                 throws CMAException
Return a Collection of bean instances that represent all the records in the categories table that are associated with the specified category_id.

Parameters:
categoryId - - The category_id value.
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.

setInstance

public static final void setInstance(ContentBean 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.

getContentId

public final int getContentId()
Returns contentId.

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

Rakesh API

Copyright © 2002-2005 - Rakesh Vidyadharan