Package com.centraview.report.ejb.entity

Source Code of com.centraview.report.ejb.entity.ReportEJB

/*
* $RCSfile: ReportEJB.java,v $    $Revision: 1.1.1.1 $  $Date: 2005/04/28 20:23:00 $ - $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.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;

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: ReportEJB</p>
*
* <p>Description:   Entity Bean BMP class that represents the REPORT
*  table.
* </p>
*/

public class ReportEJB extends CVEntityBean
{
  String description;
  Integer modifiedBy;
  Timestamp modifiedOn;
  int moduleId;
  int reportId;
  String name;
  int reportTypeId;

  String reportURL;
  private boolean isModified;
  int createdBy;
  Timestamp createdOn;
  Date dateFrom;
  Date dateTo;

  public void ejbPostCreate(Timestamp createdOn, Date dateFrom, Date dateTo, String description, Integer modifiedBy, Timestamp modifiedOn, int moduleId, String name, int reportTypeId, String reportURL, String ds) throws CreateException
  {}

  public ReportPK ejbCreate(Timestamp createdOn, Date dateFrom, Date dateTo, String description, Integer modifiedBy, Timestamp modifiedOn, int moduleId, String name, int reportTypeId, String reportURL, String ds) throws CreateException
  {

    setDescription(description);
    setReportURL(reportURL);
    setCreatedOn(createdOn);
    setDateFrom(dateFrom);
    setDateTo(dateTo);
    setModifiedBy(modifiedBy);
    setModifiedOn(modifiedOn);
    setModuleId(moduleId);
    setName(name);
    setReportTypeId(reportTypeId);
    CVDal dataAccessLayer = new CVDal(ds);
    try {
      dataAccessLayer.setSql("reports.createreport");
      dataAccessLayer.setInt(1, moduleId);
      dataAccessLayer.setString(2, name);
      dataAccessLayer.setString(3, description);
      dataAccessLayer.setInt(4, modifiedBy.intValue()); // modified and created should be the same on a create
      dataAccessLayer.setRealTimestamp(5, createdOn);
      if (modifiedBy == null) {
        dataAccessLayer.setNull(6, Types.INTEGER);
      } else {
        dataAccessLayer.setInt(6, modifiedBy.intValue());
      }
      dataAccessLayer.setRealTimestamp(7, modifiedOn);
      dataAccessLayer.setString(8, reportURL);
      dataAccessLayer.setInt(9, reportTypeId);
      dataAccessLayer.setRealDate(10, dateFrom);
      dataAccessLayer.setRealDate(11, dateTo);
      if (dataAccessLayer.executeUpdate() != 1) {
        throw new CreateException("Error adding row");
      }

      // get auto_increment id
      this.reportId = dataAccessLayer.getAutoGeneratedKey();
      this.moduleId = moduleId;
      this.name = name;
      this.description = description;
      this.createdBy = modifiedBy.intValue(); // modifiedBy and createdBy should be the same on a create.
      this.createdOn = createdOn;
      this.modifiedBy = modifiedBy;
      this.modifiedOn = modifiedOn;
      this.reportURL = reportURL;
      this.reportTypeId = reportTypeId;
      this.dateFrom = dateFrom;
      this.dateTo = dateTo;

      return new ReportPK(this.reportId, ds);
    } finally {
      dataAccessLayer.destroy();
      dataAccessLayer = null;
    }
  }

  public void ejbRemove() throws RemoveException
  {
    ReportPK primaryKey = (ReportPK)entityContext.getPrimaryKey();
    CVDal dataAccessLayer = new CVDal(primaryKey.dataSource);
    try {
      dataAccessLayer.setSql("reports.deletereport");
      dataAccessLayer.setInt(1, reportId);
      if (dataAccessLayer.executeUpdate() < 1) {
        throw new RemoveException("Error deleting report");
      }
    } finally {
      dataAccessLayer.destroy();
      dataAccessLayer = null;
    }
  }

  public void setCreatedBy(int createdBy)
  {
    isModified = true;
    this.createdBy = createdBy;
  }

  public void setCreatedOn(Timestamp createdOn)
  {
    isModified = true;
    this.createdOn = createdOn;
  }

  public void setDateFrom(Date dateFrom)
  {
    isModified = true;
    this.dateFrom = dateFrom;
  }

  public void setDateTo(Date dateTo)
  {
    isModified = true;
    this.dateTo = dateTo;
  }

  public void setDescription(String description)
  {
    this.description = description;
    isModified = true;
  }

  public void setModifiedBy(Integer modifiedBy)
  {
    isModified = true;
    this.modifiedBy = modifiedBy;
  }

  public void setModifiedOn(Timestamp modifiedOn)
  {
    isModified = true;
    this.modifiedOn = modifiedOn;
  }

  public void setModuleId(int moduleId)
  {
    isModified = true;
    this.moduleId = moduleId;
  }

  public void setReportId(int reportId)
  {
    isModified = true;
    this.reportId = reportId;
  }

  public void setName(String name)
  {
    isModified = true;
    this.name = name;
  }

  public void setReportTypeId(int reportTypeId)
  {
    isModified = true;
    this.reportTypeId = reportTypeId;
  }

  public void setReportURL(String reportURL)
  {
    this.reportURL = reportURL;
    isModified = true;
  }

  public int getCreatedBy()
  {
    return createdBy;
  }

  public Timestamp getCreatedOn()
  {
    return createdOn;
  }

  public Date getDateFrom()
  {
    return dateFrom;
  }

  public Date getDateTo()
  {
    return dateTo;
  }

  public String getDescription()
  {
    return description;
  }

  public Integer getModifiedBy()
  {
    return modifiedBy;
  }

  public Timestamp getModifiedOn()
  {
    return modifiedOn;
  }

  public int getModuleId()
  {
    return moduleId;
  }

  public int getReportId()
  {
    return reportId;
  }

  public String getName()
  {
    return name;
  }

  public int getReportTypeId()
  {
    return reportTypeId;
  }

  public String getReportURL()
  {
    return reportURL;
  }

  public ReportPK ejbFindByPrimaryKey(ReportPK pk) throws FinderException
  {
    CVDal dataAccessLayer = new CVDal(pk.dataSource);
    ResultSet resultSet = null;
    try {
      dataAccessLayer.setSql("reports.findreportbypk");
      dataAccessLayer.setInt(1, pk.reportId);
      resultSet = dataAccessLayer.executeQueryNonParsed();
      if (!resultSet.next()) {
        throw new ObjectNotFoundException("Cannot Find report: "+pk.toString());
      }
      return pk;
    } catch (SQLException e) {
      throw new EJBException("Error executing SQL SELECT reportid FROM report WHERE reportid = ?: " + 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 ejbLoad()
  {
    ReportPK key = (ReportPK)entityContext.getPrimaryKey();
    reportId = key.reportId;
    CVDal dataAccessLayer = new CVDal(key.dataSource);
    ResultSet resultSet = null;
    try {
      dataAccessLayer.setSql("reports.loadreport");
      dataAccessLayer.setInt(1, reportId);
      resultSet = dataAccessLayer.executeQueryNonParsed();
      if (!resultSet.next()) {
        throw new NoSuchEntityException("Row does not exist");
      }
      this.moduleId = resultSet.getInt(1);
      this.name = resultSet.getString(2);
      this.description = resultSet.getString(3);
      this.createdBy = resultSet.getInt(4);
      this.createdOn = resultSet.getTimestamp(5);
      this.modifiedBy = new Integer(resultSet.getInt(6));
      this.modifiedOn = resultSet.getTimestamp(7);
      this.reportURL = resultSet.getString(8);
      this.reportTypeId = resultSet.getInt(9);
      this.dateFrom = resultSet.getDate(10);
      this.dateTo = resultSet.getDate(11);
      isModified = false;
    } catch (SQLException e) {
      throw new EJBException("Error executing SQL SELECT moduleid, name, description, createdby, createdon, modifiedby, modifiedon, reportURL, reporttypeid, datefrom, dateto FROM report WHERE reportid = ?: " + 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.setSql("reports.storereport");
        dataAccessLayer.setInt(1, moduleId);
        dataAccessLayer.setString(2, name);
        dataAccessLayer.setString(3, description);
        dataAccessLayer.setInt(4, createdBy);
        dataAccessLayer.setRealTimestamp(5, createdOn);
        if (modifiedBy == null) {
          dataAccessLayer.setNull(6, Types.INTEGER);
        } else {
          dataAccessLayer.setInt(6, modifiedBy.intValue());
        }
        dataAccessLayer.setRealTimestamp(7, modifiedOn);
        dataAccessLayer.setString(8, reportURL);
        dataAccessLayer.setInt(9, reportTypeId);
        dataAccessLayer.setRealDate(10, dateFrom);
        dataAccessLayer.setRealDate(11, dateTo);
        dataAccessLayer.setInt(12, reportId);
        if (dataAccessLayer.executeUpdate() < 1) {
          throw new NoSuchEntityException("Row does not exist");
        }
      } finally {
        dataAccessLayer.destroy();
        dataAccessLayer = null;
      }
      isModified = false;
    }
  }
  public void ejbActivate()
  {}
  public void ejbPassivate()
  {}
}
TOP

Related Classes of com.centraview.report.ejb.entity.ReportEJB

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.