1   package ch.ige.edossier.transfer.server.dao;
2   
3   import java.sql.*;
4   import ch.ige.edossier.transfer.vo.BfakturVO;
5   import ch.ige.edossier.util.DBHelper;
6   
7   /**
8    * B32.03 - eDossier-Interceptions - Diplomarbeit an der Software-Schule Schweiz<br>
9    * Data Access Objekt für die Detaildaten einer Beanstandung
10   * <p>
11   * Copyright (c) 2004, Eidgenössisches Institut für Geistiges Eigentum
12   * @author    Anita Rueegsegger, Marc Bouquet
13   * @version   $Id: BfakturDAO.java,v 1.7 2004/10/27 22:04:59 ruegsegger Exp $
14   */
15  public class BfakturDAO
16  {
17  
18  
19    /**
20     * Selektiert alle relevanten Daten der Tabelle bfaktur, bfaktpos, bfaktxt
21     * die benötigt werden um eine Beanstandung im Detail darzustellen
22     * @param schutitKey int Schutztitelkey Bestandteil des PK
23     * @param ereigIdat int Ereignisdatum Bestandteil des PK
24     * @param artNr String Artikelnummer Bestandteil des PK
25     * @throws SQLException Unerwarteter SQL-Fehler
26     * @return BfakturVO beinhaltete Detaildaten einer Beanstandung
27     */
28    public BfakturVO select( int schutitKey, int ereigIdat, String artNr ) throws SQLException
29    {
30      String query = null;
31      BfakturVO bfakturVO = null;
32      Connection con = null;
33      PreparedStatement ps = null;
34      ResultSet rs = null;
35  
36      try
37      {
38        query = "SELECT a.bfakt_id, b.text_long, c.inhaber, c.var_text, c.bfakt_dat " +
39                "FROM bfaktpos a, bfaktxt b, bfaktur c " +
40                "WHERE a.schutit_key=? AND a.ereig_idat=? AND a.art_nr=? AND a.text_nr = b.text_nr AND a.bfakt_id = c.bfakt_id";
41  
42        con = DBHelper.getInstance().getConnection();
43        ps = con.prepareStatement( query );
44        ps.setInt( 1, schutitKey );
45        ps.setInt( 2, ereigIdat );
46        ps.setString( 3, artNr );
47  
48        rs = ps.executeQuery();
49  
50        if( rs.next() )
51        {
52          bfakturVO = new BfakturVO();
53          bfakturVO.bfaktId = rs.getInt( "bfakt_id" );
54          bfakturVO.textLong = rs.getString( "text_long" );
55          bfakturVO.inhaber = rs.getString( "inhaber" );
56          bfakturVO.varText = rs.getString( "var_text" );
57          bfakturVO.bfaktDat = rs.getDate( "bfakt_dat" );
58        }
59      }
60      finally
61      {
62        DBHelper.getInstance().close( con, ps );
63      }
64      return bfakturVO;
65    }
66  
67    /**
68     * Selektiert den Titel einer Banstandung
69     * @param bfaktId int Schlüsselwert
70     * @throws SQLException Unerwarteter SQL-Fehler
71     * @return String Titel einer Beanstandung
72     */
73    public String selectTitel( int bfaktId ) throws SQLException
74    {
75      String query = null;
76      String titel = null;
77      Connection con = null;
78      PreparedStatement ps = null;
79      ResultSet rs = null;
80  
81      try
82      {
83        query = "SELECT b.text " +
84            "FROM bfaktur a, bformtxt_druck b " +
85            "WHERE a.bfakt_id=? AND a.formart_cd = b.formart_cd AND b.textart = 1 AND b.sprach_cd = a.sprach_cd";
86  
87        con = DBHelper.getInstance().getConnection();
88        ps = con.prepareStatement( query );
89        ps.setInt( 1, bfaktId );
90  
91        rs = ps.executeQuery();
92  
93        if( rs.next() )
94        {
95          titel = rs.getString( "text" );
96        }
97      }
98      finally
99      {
100       DBHelper.getInstance().close( con, ps );
101     }
102     return titel;
103   }
104 
105   /**
106    * Holt den byte-Array des Pdf-Dokuments von der Jipps-Datenbank
107    * @param bfaktId int PK der Tabelle printjob
108    * @throws SQLException Unerwarteter SQL-Fehler
109    * @return byte[] Pdf-Daten
110    */
111   public byte[] selectPdf( int bfaktId ) throws SQLException
112   {
113     String query = null;
114     Connection con = null;
115     PreparedStatement ps = null;
116     ResultSet rs = null;
117     byte[] printJobFile = null;
118     Blob myBlob = null;
119 
120     try
121     {
122       query = "SELECT printjob_file " +
123           "FROM printjob " +
124           "WHERE report_id = ? AND typ = 'Letter' AND schacht_id = 1";
125 
126       con = DBHelper.getInstance().getJippsConnection();
127       ps = con.prepareStatement( query );
128       ps.setInt( 1, bfaktId );
129 
130       rs = ps.executeQuery();
131 
132       if( rs.next() )
133       {
134         // pdf-Blob lesen
135         myBlob = ( java.sql.Blob )rs.getBlob( "printjob_file" );
136         printJobFile = myBlob.getBytes( new Long( "1" ).longValue(),
137                                         new Long( myBlob.length() ).intValue() );
138       }
139     }
140     finally
141     {
142       DBHelper.getInstance().close( con, ps );
143     }
144     return printJobFile;
145   }
146 }
147