Package com.centraview.report.ejb.entity

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

/*
* $RCSfile: ReportContentEJB.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.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.Collection;
import java.util.Vector;

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: ReportContentEJB</p>
*
* <p>Description:   Entity Bean BMP class that represents the REPORTCONTENT
*  table.
* </p>
*
* @author Kalmychkov Alexi, Serdioukov Eduard
* @version 1.0
* @date 01/05/04
*/

public class ReportContentEJB extends CVEntityBean {
  int fieldId;
  int tableId;
  int reportContentId;
  int reportId;
  short sequenceNumber;
  String sortOrder;
  Byte sortOrderSequence;
  private boolean isModified;

  public ReportContentPK ejbCreate(int fieldId, int tableId, int reportId, short sequenceNumber, String sortOrder,
                                   Byte sortOrderSequence, String ds) throws CreateException {
    CVDal dataAccessLayer = new CVDal(ds);
    try
    {
      // INSERT INTO reportcontent (reportid, fieldid, tableid, sequencenumber,
      // sortorder, sortordersequence) VALUES (?, ?, ?, ?, ?, ?)
      dataAccessLayer.setSql("reports.createreportcontent");
      dataAccessLayer.setInt(1, reportId);
      dataAccessLayer.setInt(2, fieldId);
      dataAccessLayer.setInt(3, tableId);
      dataAccessLayer.setShort(4, sequenceNumber);
      dataAccessLayer.setString(5, sortOrder);
      if (sortOrderSequence == null)
      {
        dataAccessLayer.setNull(6, Types.TINYINT);
      } else {
        dataAccessLayer.setByte(6, sortOrderSequence.byteValue());
      }
      if (dataAccessLayer.executeUpdate() != 1)
      {
        throw new CreateException("Error adding row");
      }
      // get auto_increment id
      this.reportContentId = dataAccessLayer.getAutoGeneratedKey();
      this.fieldId = fieldId;
      this.tableId = tableId;
      this.reportId = reportId;
      this.sequenceNumber = sequenceNumber;
      this.sortOrder = sortOrder;
      this.sortOrderSequence = sortOrderSequence;
      return new ReportContentPK(this.reportContentId, ds);
  } catch(Exception e) {
    System.out.println("[Exception][ReportContentEJB.ejbCreate] Exception Thrown: "+e);
    throw new EJBException(e);
  } finally {
    dataAccessLayer.destroy();
    dataAccessLayer = null;
  }
}


  public void ejbPostCreate(int fieldId, int tableId, int reportId, short sequenceNumber, String sortOrder,
                            Byte sortOrderSequence, String ds) throws CreateException {
  }

  public void ejbRemove() throws RemoveException {
    ReportContentPK primaryKey = (ReportContentPK)entityContext.getPrimaryKey();
    CVDal dataAccessLayer = new CVDal(primaryKey.getDataSource());
    try {
     
      dataAccessLayer.setSql("reports.deletereportcontent");
      dataAccessLayer.setInt(1, reportContentId);
      if (dataAccessLayer.executeUpdate() < 1) {
        throw new RemoveException("Error deleting row");
      }
    }
    finally {
      dataAccessLayer.destroy();
      dataAccessLayer = null;
    }

  }

  public void setFieldId(int fieldId) {
    isModified = true;
    this.fieldId = fieldId;
  }

  public void setReportContentId(int reportContentId) {
    isModified = true;
    this.reportContentId = reportContentId;
  }

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

  public void setSequenceNumber(short sequenceNumber) {
    isModified = true;
    this.sequenceNumber = sequenceNumber;
  }

  public void setSortOrder(String sortOrder) {
    isModified = true;
    this.sortOrder = sortOrder;
  }

  public void setSortOrderSequence(Byte sortOrderSequence) {
    isModified = true;
    this.sortOrderSequence = sortOrderSequence;
  }

  public int getFieldId() {
    return fieldId;
  }

  public int getReportContentId() {
    return reportContentId;
  }

  public int getReportId() {
    return reportId;
  }

  public short getSequenceNumber() {
    return sequenceNumber;
  }

  public String getSortOrder() {
    return sortOrder;
  }

  public Byte getSortOrderSequence() {
    return sortOrderSequence;
  }

  public ReportContentPK ejbFindByPrimaryKey(ReportContentPK pk) throws
      FinderException {
    CVDal dataAccessLayer = new CVDal(pk.getDataSource());
    ResultSet resultSet = null;
    try {
      dataAccessLayer.setSql("reports.findreportcontentbypk");
      dataAccessLayer.setInt(1, pk.reportContentId);
      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 reportcontentid FROM reportcontent WHERE reportcontentid = ?: " + 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() {
    ReportContentPK key = (ReportContentPK) entityContext.getPrimaryKey();
    reportContentId = key.reportContentId;
    CVDal dataAccessLayer = new CVDal(key.getDataSource());
    ResultSet resultSet = null;
    try {
      dataAccessLayer.setSql("reports.loadreportcontent");
      dataAccessLayer.setInt(1, reportContentId);
      resultSet = dataAccessLayer.executeQueryNonParsed();
      if (!resultSet.next()) {
        throw new NoSuchEntityException("ReportContent Row does not exist");
      }
      this.reportId = resultSet.getInt(1);
      this.fieldId = resultSet.getInt(2);
      this.tableId = resultSet.getInt(3);
      this.sequenceNumber = resultSet.getByte(4);
      this.sortOrder = resultSet.getString(5);
      this.sortOrderSequence = new Byte(resultSet.getByte(6));
      isModified = false;
    }
    catch(SQLException e) {
      throw new EJBException("Error executing SQL SELECT reportid, fieldid, sequencenumber, sortorder, sortordersequence FROM reportcontent WHERE reportcontentid = ?: " + 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) {
      ReportContentPK primaryKey = (ReportContentPK)entityContext.getPrimaryKey();
      CVDal dataAccessLayer = new CVDal(primaryKey.getDataSource());
    try {
      dataAccessLayer.setSql("reports.storereportcontent");
      dataAccessLayer.setInt(1, reportId);
      dataAccessLayer.setInt(2, fieldId);
      dataAccessLayer.setInt(3, fieldId);
      dataAccessLayer.setShort(4, sequenceNumber);
      dataAccessLayer.setString(5, sortOrder);
      if (sortOrderSequence == null) {
        dataAccessLayer.setNull(6, Types.TINYINT);
      }
      else {
        dataAccessLayer.setByte(6, sortOrderSequence.byteValue());
      }
      dataAccessLayer.setInt(7, reportContentId);
      if (dataAccessLayer.executeUpdate() < 1) {
        throw new NoSuchEntityException("Cannot store ReportContent");
      }
    }
    finally {
      dataAccessLayer.destroy();
      dataAccessLayer = null;
    }
    isModified = false;
    }
  }


  public Collection ejbFindByReport(int reportId, String ds) {
    CVDal dataAccessLayer = new CVDal(ds);
    ResultSet resultSet = null;
    Vector keys = new Vector();
    try {
      dataAccessLayer.setSql("reports.findreportcontentbyreport");
     
      dataAccessLayer.setInt(1, reportId);
      resultSet = dataAccessLayer.executeQueryNonParsed();

      while (resultSet.next()) {
        int reportContentId = resultSet.getInt(1);
        keys.addElement(new ReportContentPK(reportContentId,ds));
      }
    }
    catch(SQLException e) {
      throw new EJBException("SELECT reporticontentid FROM reportcontent WHERE reportid = "+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;
    }
    return keys;
  }

  public void ejbActivate() {
  }

  public void ejbPassivate() {
  }

  /**
   * @return Returns the tableId.
   */
  public int getTableId()
  {
    return this.tableId;
  }
  /**
   * @param tableId The tableId to set.
   */
  public void setTableId(int tableId)
  {
    isModified = true;
    this.tableId = tableId;
  }
}
TOP

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

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.