1 package org.inigma.waragent.crud; 2 3 import java.io.IOException; 4 import java.sql.Connection; 5 import java.sql.SQLException; 6 import java.util.Properties; 7 8 import org.inigma.iniglet.Configuration; 9 10 public abstract class AbstractCrud { 11 private static Properties properties = null; 12 protected static Connection connection = null; 13 protected static Configuration configuration = null; 14 15 public synchronized static void initialize(Configuration config) { 16 if (configuration == null) { 17 configuration = config; 18 } 19 if (connection == null) { 20 connection = config.getConnection(); 21 config.initializeSchema( 22 AbstractCrud.class.getResourceAsStream("/org/inigma/waragent/000_up_war-agent.sql") 23 ); 24 } 25 } 26 27 protected synchronized static Properties getConfig(String type) { 28 if (properties == null) { 29 properties = new Properties(); 30 try { 31 properties.load(AbstractCrud.class.getResourceAsStream("/org/inigma/waragent/cache.properties")); 32 } catch (IOException e) { 33 throw new RuntimeException("Unable to load cache configurations"); 34 } 35 } 36 Properties config = new Properties(); 37 config.setProperty("ttl", properties.getProperty(type + ".ttl")); 38 config.setProperty("idle", properties.getProperty(type + ".idle")); 39 config.setProperty("access", properties.getProperty(type + ".access")); 40 config.setProperty("loader", properties.getProperty(type + ".loader")); 41 return config; 42 } 43 44 public static void commit() { 45 if (connection != null) { 46 try { 47 connection.commit(); 48 } catch (SQLException ignore) { 49 } 50 } 51 } 52 }