Annotation of java/classes/org/w3c/tools/jdbc/PropertyCache.java, revision 1.4
1.1 bmahe 1: // PropertyCache.java
1.4 ! ylafon 2: // $Id: PropertyCache.java,v 1.3 2012/06/16 15:48:47 ylafon Exp $
1.1 bmahe 3: // (c) COPYRIGHT MIT, INRIA and Keio, 2000.
4: // Please first read the full copyright statement in file COPYRIGHT.html
5: package org.w3c.tools.jdbc;
6:
7: import java.beans.PropertyDescriptor;
1.4 ! ylafon 8: import java.util.HashMap;
! 9: import java.util.Map;
1.1 bmahe 10:
11: /**
1.3 ylafon 12: * @author Beno�t Mah� (bmahe@w3.org)
1.4 ! ylafon 13: * @version $Revision: 1.3 $
1.1 bmahe 14: */
15: public class PropertyCache {
1.2 ylafon 16:
1.1 bmahe 17: public static boolean debug = false;
18: /**
19: * The modified properties
20: */
1.4 ! ylafon 21: protected static Map<String, Object> properties = new HashMap<>();
1.2 ylafon 22:
1.1 bmahe 23: protected static String getId(JdbcBeanInterface bean, String property) {
1.3 ylafon 24: StringBuilder buffer;
25: buffer = new StringBuilder();
26: buffer.append(String.valueOf(bean.hashCode()));
27: buffer.append('.').append(property);
28: return buffer.toString();
1.1 bmahe 29: }
30:
1.3 ylafon 31: public static void addProperty(JdbcBeanInterface bean,
32: String property,
33: Object value) {
34: String id = getId(bean, property);
35: if (id != null) {
36: if (debug) {
37: System.out.println("add property in cache: " + id + " = " + value);
38: }
39: properties.put(id, value);
40: }
1.1 bmahe 41: }
42:
43: public static Object getProperty(JdbcBeanInterface bean,
1.3 ylafon 44: PropertyDescriptor pd) {
45: String id = getId(bean, pd.getName());
46: if (id != null) {
47: return properties.get(id);
48: }
49: return null;
1.1 bmahe 50: }
51:
52: public static void removeProperties(JdbcBeanInterface bean) {
1.3 ylafon 53: StringBuilder buffer = new StringBuilder();
54: buffer.append(String.valueOf(bean.hashCode()));
55: buffer.append('.');
56: String beankey = buffer.toString();
1.4 ! ylafon 57: for (String key : properties.keySet()) {
1.3 ylafon 58: if (key.startsWith(beankey)) {
59: if (debug) {
60: System.out.println("remove property from cache: " + beankey);
61: }
62: properties.remove(key);
63: }
64: }
1.1 bmahe 65: }
66: }
Webmaster