KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > model > MPrivateAccess


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.model;
15
16 import java.sql.*;
17 import java.util.*;
18
19 import org.compiere.util.*;
20
21 /**
22  * Private Access
23  *
24  * @author Jorg Janke
25  * @version $Id: MPrivateAccess.java,v 1.3 2003/10/26 05:54:36 jjanke Exp $
26  */

27 public class MPrivateAccess extends X_AD_Private_Access
28 {
29     /**
30      * Load Pricate Access
31      * @param ctx context
32      * @param AD_User_ID user
33      * @param AD_Table_ID table
34      * @param Record_ID record
35      * @return access or null if not found
36      */

37     public static MPrivateAccess get (Properties ctx, int AD_User_ID, int AD_Table_ID, int Record_ID)
38     {
39         MPrivateAccess retValue = null;
40         PreparedStatement pstmt = null;
41         String JavaDoc sql = "SELECT * FROM AD_Private_Access WHERE AD_User_ID=? AND AD_Table_ID=? AND Record_ID=?";
42         try
43         {
44             pstmt = DB.prepareCall(sql);
45             pstmt.setInt(1, AD_User_ID);
46             pstmt.setInt(2, AD_Table_ID);
47             pstmt.setInt(3, Record_ID);
48             ResultSet rs = pstmt.executeQuery();
49             if (rs.next())
50                 retValue = new MPrivateAccess (ctx, rs);
51             rs.close();
52             pstmt.close();
53             pstmt = null;
54         }
55         catch (Exception JavaDoc e)
56         {
57             s_log.error("MPrivateAccess", e);
58         }
59         try
60         {
61             if (pstmt != null)
62                 pstmt.close();
63             pstmt = null;
64         }
65         catch (Exception JavaDoc e)
66         {
67             pstmt = null;
68         }
69         return retValue;
70     } // get
71

72     /**
73      * Get Where Clause of Locked Records for Table
74      * @param AD_Table_ID table
75      * @param AD_User_ID user requesting info
76      * @return "<>1" or " NOT IN (1,2)" or null
77      */

78     public static String JavaDoc getLockedRecordWhere (int AD_Table_ID, int AD_User_ID)
79     {
80         ArrayList list = new ArrayList();
81         PreparedStatement pstmt = null;
82         String JavaDoc sql = "SELECT Record_ID FROM AD_Private_Access WHERE AD_Table_ID=? AND AD_User_ID<>? AND IsActive='Y'";
83         try
84         {
85             pstmt = DB.prepareCall(sql);
86             pstmt.setInt(1, AD_Table_ID);
87             pstmt.setInt(2, AD_User_ID);
88             ResultSet rs = pstmt.executeQuery();
89             while (rs.next())
90                 list.add(new Integer JavaDoc(rs.getInt(1)));
91             rs.close();
92             pstmt.close();
93             pstmt = null;
94         }
95         catch (Exception JavaDoc e)
96         {
97             s_log.error("MPrivateAccess", e);
98         }
99         try
100         {
101             if (pstmt != null)
102                 pstmt.close();
103             pstmt = null;
104         }
105         catch (Exception JavaDoc e)
106         {
107             pstmt = null;
108         }
109         //
110
if (list.size() == 0)
111             return null;
112         if (list.size() == 1)
113             return "<>" + list.get(0);
114         //
115
StringBuffer JavaDoc sb = new StringBuffer JavaDoc(" NOT IN(");
116         for (int i = 0; i < list.size(); i++)
117         {
118             if (i > 0)
119                 sb.append(",");
120             sb.append(list.get(i));
121         }
122         sb.append(")");
123         return sb.toString();
124     } // get
125

126     
127     /** Logger */
128     private static Logger s_log = Logger.getCLogger(MPrivateAccess.class);
129     
130     /**
131      * Load Constructor
132      * @param ctx context
133      * @param rs result set
134      */

135     public MPrivateAccess(Properties ctx, ResultSet rs)
136     {
137         super(ctx, rs);
138     } // MPrivateAccess
139

140     /**
141      * New Constructor
142      * @param ctx context
143      * @param AD_User_ID user
144      * @param AD_Table_ID table
145      * @param Record_ID record
146      */

147     public MPrivateAccess (Properties ctx, int AD_User_ID, int AD_Table_ID, int Record_ID)
148     {
149         super (ctx, 0);
150         setAD_User_ID (AD_User_ID);
151         setAD_Table_ID (AD_Table_ID);
152         setRecord_ID (Record_ID);
153     } // MPrivateAccess
154

155 } // MPrivateAccess
156
Popular Tags