/*
* $RCSfile: ReportTypeEJB.java,v $ $Revision: 1.1.1.1 $ $Date: 2005/04/28 20:23:02 $ - $Author: mking_cv $
*
* The contents of this file are subject to the Open Software License
* Version 2.1 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.centraview.com/opensource/license.html
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is: CentraView Open Source.
*
* The developer of the Original Code is CentraView. Portions of the
* Original Code created by CentraView are Copyright (c) 2004 CentraView,
* LLC; All Rights Reserved. The terms "CentraView" and the CentraView
* logos are trademarks and service marks of CentraView, LLC.
*/
package com.centraview.report.ejb.entity;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.FinderException;
import javax.ejb.NoSuchEntityException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.RemoveException;
import com.centraview.common.CVDal;
/**
* <p>Title: ReportTypeEJB</p>
*
* <p>Description: Entity Bean BMP class that represents the REPORTTYPE
* table.
* </p>
*
* @author Kalmychkov Alexi, Serdioukov Eduard
* @version 1.0
* @date 01/05/04
*/
// TODO add queries to QueryCollection
public class ReportTypeEJB extends CVEntityBean {
int reportTypeId;
String reportTypeName;
private boolean isModified;
public ReportTypePK ejbCreate(String reportTypeName, String ds) throws CreateException {
setReportTypeName(reportTypeName);
CVDal dataAccessLayer = new CVDal(ds);
try {
dataAccessLayer.setSqlQuery("INSERT INTO reporttype (reporttypename) VALUES (?)");
dataAccessLayer.setString(1, reportTypeName);
if (dataAccessLayer.executeUpdate() != 1) {
throw new CreateException("Error adding row");
}
// get auto_increment id
this.reportTypeId = dataAccessLayer.getAutoGeneratedKey();
this.reportTypeName = reportTypeName;
return new ReportTypePK(this.reportTypeId, ds);
}
finally {
dataAccessLayer.destroy();
dataAccessLayer = null;
}
}
public void ejbPostCreate(String reportTypeName, String ds) throws CreateException {
}
public void ejbRemove() throws RemoveException {
ReportTypePK primaryKey = (ReportTypePK)entityContext.getPrimaryKey();
CVDal dataAccessLayer = new CVDal(primaryKey.dataSource);
try {
dataAccessLayer.setSqlQuery("DELETE FROM reporttype WHERE reporttypeid = ?");
dataAccessLayer.setInt(1, reportTypeId);
if (dataAccessLayer.executeUpdate() < 1) {
throw new RemoveException("Error deleting row");
}
}
finally {
dataAccessLayer.destroy();
dataAccessLayer = null;
}
}
public void setReportTypeId(int reportTypeId) {
this.reportTypeId = reportTypeId;
}
public void setReportTypeName(String reportTypeName) {
isModified = true;
this.reportTypeName = reportTypeName;
}
public int getReportTypeId() {
return reportTypeId;
}
public String getReportTypeName() {
return reportTypeName;
}
public void ejbLoad() {
ReportTypePK key = (ReportTypePK) entityContext.getPrimaryKey();
reportTypeId = key.reportTypeId;
CVDal dataAccessLayer = new CVDal(key.dataSource);
ResultSet resultSet = null;
try {
dataAccessLayer.setSqlQuery("SELECT reporttypename FROM reporttype WHERE reporttypeid = ?");
dataAccessLayer.setInt(1, reportTypeId);
resultSet = dataAccessLayer.executeQueryNonParsed();
if (!resultSet.next()) {
throw new NoSuchEntityException("Row does not exist");
}
this.reportTypeName = resultSet.getString(1);
isModified = false;
}
catch(SQLException e) {
throw new EJBException("Error executing SQL SELECT reporttypename FROM reporttype WHERE reporttypeid = ?: " + e.toString());
}
finally {
if (resultSet != null) {
try { resultSet.close(); }
catch (SQLException e) {
// Not much we can do at this point.
}
}
dataAccessLayer.destroy();
dataAccessLayer = null;
}
}
public void ejbStore() {
if (isModified) {
ReportPK primaryKey = (ReportPK)entityContext.getPrimaryKey();
CVDal dataAccessLayer = new CVDal(primaryKey.dataSource);
try {
dataAccessLayer.setSqlQuery("UPDATE reporttype SET reporttypename = ? WHERE reporttypeid = ?");
dataAccessLayer.setString(1, reportTypeName);
dataAccessLayer.setInt(2, reportTypeId);
if (dataAccessLayer.executeUpdate() < 1) {
throw new NoSuchEntityException("Row does not exist");
}
}
finally {
dataAccessLayer.destroy();
dataAccessLayer = null;
}
}
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public ReportTypePK ejbFindByPrimaryKey(ReportTypePK pk) throws
FinderException {
CVDal dataAccessLayer = new CVDal(pk.dataSource);
ResultSet resultSet = null;
try {
dataAccessLayer.setSqlQuery("SELECT reporttypeid FROM reporttype WHERE reporttypeid = ?");
dataAccessLayer.setInt(1, pk.reportTypeId);
resultSet = dataAccessLayer.executeQueryNonParsed();
if (!resultSet.next()) {
throw new ObjectNotFoundException("Primary key does not exist");
}
return pk;
}
catch(SQLException e) {
throw new EJBException("Error executing SQL SELECT reporttypeid FROM reporttype WHERE reporttypeid = ?: " + e.toString());
}
finally {
if (resultSet != null) {
try { resultSet.close(); }
catch (SQLException e) {
// Not much we can do at this point.
}
}
dataAccessLayer.destroy();
dataAccessLayer = null;
}
}
}