KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > erpCommon > utility > SequenceIdData


1 /*
2  *************************************************************************
3  * The contents of this file are subject to the Openbravo Public License
4  * Version 1.0 (the "License"), being the Mozilla Public License
5  * Version 1.1 with a permitted attribution clause; you may not use this
6  * file except in compliance with the License. You may obtain a copy of
7  * the License at http://www.openbravo.com/legal/license.html
8  * Software distributed under the License is distributed on an "AS IS"
9  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
10  * License for the specific language governing rights and limitations
11  * under the License.
12  * The Original Code is Openbravo ERP.
13  * The Initial Developer of the Original Code is Openbravo SL
14  * All portions are Copyright (C) 2001-2006 Openbravo SL
15  * All Rights Reserved.
16  * Contributor(s): ______________________________________.
17  ************************************************************************
18  */

19 //Sqlc generated VO.O11-2
20
// modified manually to return a String;
21

22 package org.openbravo.erpCommon.utility;
23
24 import java.sql.*;
25 import java.util.*;
26
27 import javax.servlet.ServletException JavaDoc;
28
29 import org.openbravo.data.FieldProvider;
30 import org.openbravo.database.ConnectionProvider;
31 import org.openbravo.exception.*;
32 import org.openbravo.data.UtilSql;
33
34 public class SequenceIdData implements FieldProvider {
35   public String JavaDoc dummy;
36
37   public String JavaDoc getField(String JavaDoc fieldName) {
38     if (fieldName.equalsIgnoreCase("dummy"))
39       return dummy;
40     else {
41       System.out.println("Field does not exist: " + fieldName);
42       return null;
43     }
44   }
45
46   /**Select void
47   */

48   public static SequenceIdData[] select(ConnectionProvider connectionProvider)
49     throws ServletException JavaDoc {
50     String JavaDoc strSql = "";
51     strSql = strSql + "";
52     strSql = strSql + " SELECT Dummy FROM DUAL";
53     strSql = strSql + " ";
54
55     PreparedStatement st = null;
56     ResultSet result;
57     Vector<Object JavaDoc> vector = new Vector<Object JavaDoc>(0);
58
59     int iParameter = 0;
60     try {
61       st = connectionProvider.getPreparedStatement(strSql);
62
63       result = st.executeQuery();
64       long countRecord = 0;
65       while(result.next()) {
66         countRecord++;
67         SequenceIdData objectSequenceIdData = new SequenceIdData();
68         objectSequenceIdData.dummy = UtilSql.getValue(result, "DUMMY");
69         vector.addElement(objectSequenceIdData);
70       }
71       result.close();
72     } catch (NoConnectionAvailableException ex) {
73       throw new ServletException JavaDoc("@CODE=NoConnectionAvailable");
74     } catch (SQLException ex2) {
75       System.out.println("SQL error in query: " + strSql + "Exception:"+ ex2);
76       throw new ServletException JavaDoc("@CODE=" + Integer.toString(ex2.getErrorCode()) + "@" + ex2.getMessage());
77     } catch (Exception JavaDoc ex3) {
78       throw new ServletException JavaDoc("@CODE=@" + ex3.getMessage());
79     } finally {
80       try {
81         connectionProvider.releasePreparedStatement(st);
82       } catch (Exception JavaDoc ignored) {}
83     }
84     SequenceIdData objectSequenceIdData[] = new SequenceIdData[vector.size()];
85     vector.copyInto(objectSequenceIdData);
86     return(objectSequenceIdData);
87   }
88   /*
89      public static String getSequence(ConnectionProvider connectionProvider, String table, String client)
90      throws ServletException {
91    String strSql = "";
92    strSql = strSql + "";
93    strSql = strSql + " SELECT CURRENTNEXT, CURRENTNEXTSYS FROM AD_SEQUENCE WHERE NAME=? AND IsActive = 'Y' AND IsTableID = 'Y' AND IsAutoSequence = 'Y'";
94    strSql = strSql + " ";
95
96    PreparedStatement st = connectionProvider.getPreparedStatement(strSql);
97    ResultSet result;
98    Vector vector = new Vector(0);
99    String resultado = "", v_NextNoSys = "", v_NextNo = "";
100
101    int iParameter = 0;
102    try {
103    iParameter++; UtilSql.setValue(st, iParameter, 12, "Test", table);
104   //iParameter++; UtilSql.setValue(st, iParameter, 12, "Test", client);
105
106   result = st.executeQuery();
107   long countRecord = 0;
108   while(result.next()) {
109   countRecord++;
110   v_NextNoSys = UtilSql.getValue(result, "CURRENTNEXTSYS");
111   v_NextNo = UtilSql.getValue(result, "CURRENTNEXT");
112   }
113   result.close();
114   } catch(SQLException e){
115   System.out.println("Error of SQL in query: " + strSql + "Exception:"+ e);
116   throw new ServletException(Integer.toString(e.getErrorCode()));
117   } finally {
118   connectionProvider.releasePreparedStatement(st);
119   }
120
121   if (v_NextNoSys!=null && !v_NextNoSys.equals("") && Integer.valueOf(v_NextNoSys).intValue() != -1 && Integer.valueOf(client).intValue() < 1000000) {
122   if (updateSequence(connectionProvider, table, "CURRENTNEXTSYS")<=0) throw new ServletException("0 lines updated at AD_Sequence");
123   resultado = v_NextNoSys;
124   } else {
125   if (updateSequence(connectionProvider, table, "CURRENTNEXT")<=0) throw new ServletException("0 lines updated at AD_Sequence");
126   resultado = v_NextNo;
127   }
128   return(resultado);
129      }
130
131      public static int updateSequence(ConnectionProvider connectionProvider, String table, String column)
132      throws ServletException {
133    String strSql = "";
134    strSql = strSql + "";
135    strSql = strSql + " UPDATE AD_SEQUENCE SET UPDATED=now(), " + column + "=" + column + " + IncrementNo ";
136    strSql = strSql + " WHERE NAME = ?";
137    strSql = strSql + " ";
138
139    PreparedStatement st = connectionProvider.getPreparedStatement(strSql);
140    int updateCount = 0;
141
142    int iParameter = 0;
143    try {
144    iParameter++; UtilSql.setValue(st, iParameter, 12, null, table);
145
146    updateCount = st.executeUpdate();
147    } catch(SQLException e){
148    System.out.println("Error of SQL in query: " + strSql + "Exception:"+ e);
149    throw new ServletException(Integer.toString(e.getErrorCode()));
150    } finally {
151    connectionProvider.releasePreparedStatement(st);
152    }
153    return(updateCount);
154    }*/

155
156   /**Get the sequence for the specified table
157   */

158   public static String JavaDoc getSequence(ConnectionProvider conn, String JavaDoc table, String JavaDoc client)
159     throws ServletException JavaDoc {
160     /*String strSql = "";
161       strSql = strSql + "";
162       strSql = strSql + " CALL AD_Sequence_Next(?,?,?)";
163       strSql = strSql + " ";
164
165       CallableStatement st = conn.getCallableStatement(strSql);
166       String object;
167
168       int iParameter = 0;*/

169     String JavaDoc object;
170     CSResponse response = SequenceData.getSequence(conn, table, client);
171     object = response.razon;
172     /*try {
173       iParameter++; UtilSql.setValue(st, iParameter, 12, "Test", table);
174       iParameter++; UtilSql.setValue(st, iParameter, 12, "Test", client);
175       int iParametersequence = iParameter + 1;
176       iParameter++; st.registerOutParameter(iParameter, 12);
177
178       st.execute();
179       object = UtilSql.getStringCallableStatement(st, iParametersequence);
180       } catch(SQLException e){
181       System.out.println("Error of SQL in query: getSequence Exception:"+ e);
182       throw new ServletException(Integer.toString(e.getErrorCode()));
183       } finally {
184       conn.releasePreparedStatement(st);
185       }*/

186     return(object);
187   }
188 }
189
Popular Tags