PreparedStatementFactory { public static PreparedStatement getPreparedStatement(String query, Session session) { if (query == null || query.trim().equals("")) { throw new IllegalArgumentException("Query must be populated."); } if (session == null) { throw new IllegalArgumentException("Session cannot be null."); } query = query.trim(); Cache c = CacheFactory.getCache("preparedStatements"); Element e = null; e = c.get(query); if (e == null || e.getObjectValue() == null) { logger.debug("Creating new Prepared Statement for: " + query); try { e = new Element(query, session.prepare(query)); c.put(e); } catch (InvalidQueryException ex) { logger.error("Serious problem when attempting to prepare query: " + query + " This is likely a fatal application problem.", ex); throw ex; } } else { if (logger.isTraceEnabled()) { PreparedStatement ps = (PreparedStatement) e.getObjectValue(); logger.trace("Pulling PreparedStatement from Cache: " + ps.getQueryString()); } } return (PreparedStatement) e.getObjectValue(); }  static PreparedStatement getPreparedStatement(String query, Session session);  }
@Test public void testGetPreparedStatement() { System.out.println("getPreparedStatement"); String query = "select * from docussandra.sys_db"; PreparedStatement result = PreparedStatementFactory.getPreparedStatement(query, f.getSession()); assertNotNull(result); result = PreparedStatementFactory.getPreparedStatement(query, f.getSession()); assertNotNull(result); }