KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.*;
17 import java.sql.*;
18 import java.util.*;
19
20 import org.compiere.util.*;
21
22 /**
23  * Change Log Model
24  *
25  * @author Jorg Janke
26  * @version $Id: MChangeLog.java,v 1.2 2003/10/31 05:30:52 jjanke Exp $
27  */

28 public class MChangeLog extends X_AD_ChangeLog
29 {
30     /**
31      * Do we track changes for this table
32      * @param AD_Table_ID table
33      * @return true if changes are tracked
34      */

35     public static boolean isLogged (int AD_Table_ID)
36     {
37         if (s_changeLog == null)
38             fillChangeLog();
39         //
40
Boolean JavaDoc value = (Boolean JavaDoc)s_changeLog.get(new Integer JavaDoc (AD_Table_ID));
41         if (value != null && value.booleanValue())
42             return true;
43         return false;
44     } // trackChanges
45

46     /**
47      * Fill Log with tables to be logged
48      */

49     private static void fillChangeLog()
50     {
51         s_changeLog = new CCache ("MChangeLog-Tables", 10);
52         String JavaDoc sql = "SELECT AD_Table_ID FROM AD_Table WHERE IsChangeLog='Y'"; // also inactive
53
PreparedStatement pstmt = null;
54         try
55         {
56             pstmt = DB.prepareCall(sql);
57             ResultSet rs = pstmt.executeQuery();
58             while (rs.next())
59                 s_changeLog.put(new Integer JavaDoc(rs.getInt(1)), Boolean.TRUE);
60             rs.close();
61             pstmt.close();
62             pstmt = null;
63         }
64         catch (Exception JavaDoc e)
65         {
66             s_log.error("fillChangeLog", e);
67         }
68         try
69         {
70             if (pstmt != null)
71                 pstmt.close();
72             pstmt = null;
73         }
74         catch (Exception JavaDoc e)
75         {
76             pstmt = null;
77         }
78         s_log.info("fillChangeLog - #" + s_changeLog.size());
79     } // fillChangeLog
80

81     /** Change Log */
82     private static CCache s_changeLog = null;
83     /** Logger */
84     private static Logger s_log = Logger.getCLogger(MChangeLog.class);
85     
86     /*************************************************************************/
87     
88     /**
89      * Standard Constructor
90      * @param ctx context
91      * @param AD_ChangeLog_ID id
92      */

93     public MChangeLog(Properties ctx, int AD_ChangeLog_ID)
94     {
95         super (ctx, AD_ChangeLog_ID);
96         if (AD_ChangeLog_ID == 0)
97         {
98         // setAD_ChangeLog_ID (0);
99
// setAD_Column_ID (0);
100
// setAD_Session_ID (0);
101
// setAD_Table_ID (0);
102
// setRecord_ID (null);
103
}
104     } // MChangeLog
105

106     /**
107      * Load Constructor
108      * @param ctx context
109      * @param rs result set
110      */

111     public MChangeLog(Properties ctx, ResultSet rs)
112     {
113         super(ctx, rs);
114     } // MChangeLog
115

116     /**
117      * New Constructor
118      * @param ctx context
119      * @param AD_Session_ID session
120      * @param AD_Table_ID table
121      * @param AD_Column_ID column
122      * @param Record_ID record
123      * @param OldValue old
124      * @param NewValue new
125      */

126     public MChangeLog (Properties ctx, int AD_Session_ID,
127         int AD_Table_ID, int AD_Column_ID, int Record_ID,
128         String JavaDoc OldValue, String JavaDoc NewValue)
129     {
130         super (ctx, 0);
131         setAD_Session_ID (AD_Session_ID);
132         setAD_Table_ID (AD_Table_ID);
133         setAD_Column_ID (AD_Column_ID);
134         setRecord_ID (Record_ID);
135         //
136
setOldValue(OldValue);
137         setNewValue(NewValue);
138     } // MChangeLog
139

140 } // MChangeLog
141
Popular Tags