KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > base > secureApp > DefaultValuesData


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.base.secureApp;
13
14 import java.sql.*;
15
16 import javax.servlet.ServletException JavaDoc;
17
18 import org.openbravo.data.FieldProvider;
19 import org.openbravo.database.ConnectionProvider;
20 import org.openbravo.exception.*;
21 import org.openbravo.data.UtilSql;
22
23 /**Clase SqlStandardData
24  */

25 public class DefaultValuesData implements FieldProvider {
26   public String JavaDoc columnname;
27
28   public String JavaDoc getField(String JavaDoc fieldName) {
29     if (fieldName.equalsIgnoreCase("columnname"))
30       return columnname;
31     else {
32       System.out.println("Field does not exist: " + fieldName);
33       return null;
34     }
35   }
36
37 /**Select for relation
38  */

39   public static String JavaDoc select(ConnectionProvider connectionProvider, String JavaDoc param1, String JavaDoc param2, String JavaDoc param3, String JavaDoc param4) throws ServletException JavaDoc {
40     String JavaDoc strSql = "SELECT " + param1 + " AS COLUMNNAME";
41     strSql = strSql + " FROM " + param2 + " ";
42     strSql = strSql + " WHERE isActive = 'Y' ";
43     strSql = strSql + " AND isDefault = 'Y' ";
44     strSql = strSql + " AND AD_Client_ID IN (" + param3 + ") ";
45     strSql = strSql + " AND AD_Org_ID IN (" + param4 + ") ";
46     strSql = strSql + " ORDER BY AD_Client_ID";
47
48     Statement st = null;
49     ResultSet result;
50     String JavaDoc resultado="";
51
52     try {
53       st = connectionProvider.getStatement();
54       result = st.executeQuery(strSql);
55
56       if (result.next()) {
57         resultado = UtilSql.getValue(result, "COLUMNNAME");
58       }
59       result.close();
60     } catch(SQLException e){
61       System.out.println("SQL error in query: " + strSql + "Exception:"+ e);
62       throw new ServletException JavaDoc("@CODE=" + Integer.toString(e.getErrorCode()) + "@" + e.getMessage());
63     } catch(NoConnectionAvailableException ec){
64       System.out.println("Connection error in query: " + strSql + "Exception:"+ ec);
65       throw new ServletException JavaDoc("@CODE=NoConnectionAvailable");
66     } catch(PoolNotFoundException ep){
67       System.out.println("Pool error in query: " + strSql + "Exception:"+ ep);
68       throw new ServletException JavaDoc("@CODE=NoConnectionAvailable");
69     } catch(Exception JavaDoc ex){
70       System.out.println("Exception in query: " + strSql + "Exception:"+ ex);
71       throw new ServletException JavaDoc("@CODE=@" + ex.getMessage());
72     } finally {
73       try {
74         connectionProvider.releaseStatement(st);
75       } catch(Exception JavaDoc ignore){
76         ignore.printStackTrace();
77       }
78     }
79     return(resultado);
80   }
81 }
82
Popular Tags