/**
* This class implements CatalogDAO for oracle, sybase and cloudscape DBs.
* This class encapsulates all the SQL calls made by Catalog EJB.
* This layer maps the relational data stored in the database to
* the objects needed by Catalog EJB.
*/
public class CatalogDAOImpl implements CatalogDAO {
// Helper methods
protected static DataSource getDataSource()
throws CatalogDAOSysException {
try {
InitialContext ic = new InitialContext();
return (DataSource) ic.lookup(JNDINames.CATALOG_DATASOURCE);
}
catch (NamingException ne) {
throw new CatalogDAOSysException("NamingException while looking "
+ "up DB context : "
+ ne.getMessage());
}
}
// Business methods
public Category getCategory(String categoryID, Locale l)
throws CatalogDAOSysException {
Connection c = null;
PreparedStatement ps = null;
ResultSet rs = null;
Category ret = null;
try {
c = getDataSource().getConnection();
ps = c.prepareStatement("select a.catid, name, descn "
+ "from (category a join "
+ "category_details b on "
+ "a.catid=b.catid) "
+ "where locale = ? "
+ "and a.catid = ?",
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ps.setString(1, l.toString());
ps.setString(2, categoryID);
rs = ps.executeQuery();
if (rs.first()) {
ret = new Category(rs.getString(1).trim(),
rs.getString(2),
rs.getString(3));
}
rs.close();
ps.close();