1 24 25 package com.mckoi.database; 26 27 import com.mckoi.util.Cache; 28 import com.mckoi.database.global.ObjectTranslator; 29 import com.mckoi.database.global.ByteLongObject; 30 import com.mckoi.debug.*; 31 32 42 43 public final class StatementCache { 44 45 48 private DatabaseSystem system; 49 50 53 private Cache cache; 54 55 58 public StatementCache(DatabaseSystem system, 59 int hash_size, int max_size, int clean_percentage) { 60 this.system = system; 61 cache = new Cache(hash_size, max_size, clean_percentage); 62 } 63 64 67 public final DebugLogger Debug() { 68 return system.Debug(); 69 } 70 71 74 public synchronized void put(String query_string, 75 StatementTree statement_tree) { 76 query_string = query_string.trim(); 77 if (cache.get(query_string) == null) { 79 try { 80 Object cloned_tree = statement_tree.clone(); 81 cache.put(query_string, cloned_tree); 82 } 83 catch (CloneNotSupportedException e) { 84 Debug().writeException(e); 85 throw new Error ("Unable to clone statement tree: " + e.getMessage()); 86 } 87 } 88 } 89 90 94 public synchronized StatementTree get(String query_string) { 95 query_string = query_string.trim(); 96 Object ob = cache.get(query_string); 97 if (ob != null) { 98 try { 99 StatementTree cloned_tree = (StatementTree) ob; 103 return (StatementTree) cloned_tree.clone(); 104 } 105 catch (CloneNotSupportedException e) { 106 Debug().writeException(e); 107 throw new Error ("Unable to clone statement tree: " + e.getMessage()); 108 } 109 } 110 return null; 112 } 113 114 } 115 | Popular Tags |