it.mokabyte.pattern.dao
Class MyDaoJdbcImpl

java.lang.Object
  |
  +--it.mokabyte.pattern.dao.MyDaoJdbcImpl
All Implemented Interfaces:
MyDao

public class MyDaoJdbcImpl
extends java.lang.Object
implements MyDao

Title: MyDaoJdbcImpl

Description: class that implements the data access logic to DBMS by JDBC

Copyright: Copyright (c) 2002

Company:

Author:
Rossini S. - Dozio L.

Field Summary
private  it.mokabyte.pattern.dao.DataSource dataSource
          The datasource
 
Constructor Summary
MyDaoJdbcImpl()
          Retrieve the datasource from JNDI using the given name.
 
Method Summary
 boolean accountExists(AccountPK key)
           
private  void closeResources(java.sql.Connection con, java.sql.PreparedStatement stmt, java.sql.ResultSet rslt)
          Close all Database-Resources passed in.
 int deleteAccount(AccountPK pk)
          Delete a row from the MOKA_ACCOUNT table.
 int insertAccount(AccountPK pk, java.lang.String name, java.lang.String address, double balance)
          Insert a row into the MOKA_ACCOUNT table.
 AccountOM readAccount(AccountPK pk)
          Get a user from MOKA_ACCOUNT table.
 int updateAccount(AccountPK key, java.lang.String name, java.lang.String address, double balance)
          Update a row from the MOKA_ACCOUNT table.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

dataSource

private it.mokabyte.pattern.dao.DataSource dataSource
The datasource
Constructor Detail

MyDaoJdbcImpl

public MyDaoJdbcImpl()
              throws DAOException
Retrieve the datasource from JNDI using the given name.
Parameters:
dataSourceName - the JNDI name of the DataSource to look up
Throws:
NamingException - thrown for errors with JNDI
Method Detail

insertAccount

public int insertAccount(AccountPK pk,
                         java.lang.String name,
                         java.lang.String address,
                         double balance)
                  throws DAOException
Insert a row into the MOKA_ACCOUNT table. SQL : INSERT INTO MOKA_ACCOUNT(ID, NAME, ADDRESS, BALANCE) VALUES (id,name,address,balance)
Specified by:
insertAccount in interface MyDao
Parameters:
pk - primary key for the account
name - the account user name
address - the account user address
balance - the initial balance for this account
Returns:
the number of rows inserted
Throws:
DAOException - thrown if a database error

deleteAccount

public int deleteAccount(AccountPK pk)
                  throws DAOException
Delete a row from the MOKA_ACCOUNT table. Use the sql: SQL : DELETE FROM MOKA_ACCOUNT WHERE ID = 'ID'
Specified by:
deleteAccount in interface MyDao
Parameters:
the - primary key
Returns:
the number of rows deleted
Throws:
DAOException - thrown if a database error

readAccount

public AccountOM readAccount(AccountPK pk)
                      throws DAOException
Get a user from MOKA_ACCOUNT table. Use the sql: SQL : SELECT NAME,ADDRESS,BALANCE FROM MOKA_ACCOUNT WHERE ID = 'ID'
Specified by:
readAccount in interface MyDao
Parameters:
the - primary key
Returns:
the ObjectModel of the Account
Throws:
DAOException - thrown if a database error

updateAccount

public int updateAccount(AccountPK key,
                         java.lang.String name,
                         java.lang.String address,
                         double balance)
                  throws DAOException
Update a row from the MOKA_ACCOUNT table. SQL : UPDATE MOKA_ACCOUNT SET BALANCE,NAME,ADDRESS = ... WHERE ID =
Specified by:
updateAccount in interface MyDao
Parameters:
key - the primary key
name - user name
address - user address
balance - user balance
Returns:
the number of rows updated
Throws:
DAOException - thrown if a database error

accountExists

public boolean accountExists(AccountPK key)
                      throws DAOException
Specified by:
accountExists in interface MyDao
Parameters:
key - the Primary Key for this account
Returns:
Whether the indicated account exists
Throws:
DAOException - thrown if a database error

closeResources

private void closeResources(java.sql.Connection con,
                            java.sql.PreparedStatement stmt,
                            java.sql.ResultSet rslt)
Close all Database-Resources passed in. null is an acceptable value for all arguments.
Parameters:
con - The Connection to close
stmt - The PreparedStatement to close
rslt - The ResultSet to close