1 package org.apache.ojb.broker.accesslayer; 2 3 17 18 import java.sql.Connection ; 19 import java.sql.PreparedStatement ; 20 import java.sql.SQLException ; 21 22 import org.apache.ojb.broker.PersistenceBrokerException; 23 import org.apache.ojb.broker.metadata.ClassDescriptor; 24 import org.apache.ojb.broker.metadata.JdbcConnectionDescriptor; 25 import org.apache.ojb.broker.query.Query; 26 import org.apache.ojb.broker.util.logging.Logger; 27 import org.apache.ojb.broker.util.logging.LoggerFactory; 28 29 32 public class SQLCachingStatementsForClass extends StatementsForClassImpl 33 { 34 private Logger logger = LoggerFactory.getLogger(SQLCachingStatementsForClass.class); 35 38 private String selectByPKSQL; 39 42 private String insertSQL; 43 46 private String updateSQL; 47 50 private String deleteSQL; 51 52 public SQLCachingStatementsForClass(final JdbcConnectionDescriptor jcd, final ClassDescriptor mif) 53 { 54 super(jcd, mif); 55 } 56 57 78 79 public PreparedStatement getDeleteStmt(Connection con) throws SQLException 80 { 81 if (deleteSQL == null) 82 { 83 synchronized (this) 84 { 85 deleteSQL = sqlGenerator.getPreparedDeleteStatement(classDescriptor); 86 if (deleteSQL == null) 87 throw new PersistenceBrokerException("Could not generate delete Key SQL for class (" + classDescriptor.getClassOfObject().getName() + ")"); 88 } 89 } 90 try 91 { 92 return prepareStatement(con, deleteSQL, Query.NOT_SCROLLABLE, true); 93 } 94 catch (SQLException ex) 95 { 96 logger.error("Error getting delete statement for class (" + classDescriptor.getClassOfObject().getName() + ")", ex); 97 throw ex; 98 } 99 } 100 101 public PreparedStatement getInsertStmt(Connection con) throws SQLException 102 { 103 if (insertSQL == null) 104 { 105 synchronized (this) 106 { 107 insertSQL = sqlGenerator.getPreparedInsertStatement(classDescriptor); 108 if (insertSQL == null) 109 throw new PersistenceBrokerException("Could not generate insert SQL for class (" + classDescriptor.getClassOfObject().getName() + ")"); 110 } 111 } 112 try 113 { 114 return prepareStatement(con, insertSQL, Query.NOT_SCROLLABLE, true); 115 } 116 catch (SQLException ex) 117 { 118 logger.error("Error getting insert statement for class (" + classDescriptor.getClassOfObject().getName() + ")", ex); 119 throw ex; 120 } 121 } 122 123 public PreparedStatement getSelectByPKStmt(Connection con) throws SQLException 124 { 125 if (selectByPKSQL == null) 126 { 127 synchronized (this) 128 { 129 selectByPKSQL = sqlGenerator.getPreparedSelectByPkStatement(classDescriptor); 130 if (selectByPKSQL == null) 131 throw new PersistenceBrokerException("Could not generate Select by Primary Key SQL for class (" + classDescriptor.getClassOfObject().getName() + ")"); 132 } 133 } 134 try 135 { 136 return prepareStatement(con, selectByPKSQL, Query.NOT_SCROLLABLE, true); 137 } 138 catch (SQLException ex) 139 { 140 logger.error("Error getting select by primary key statement for class (" + classDescriptor.getClassOfObject().getName() + ")", ex); 141 throw ex; 142 } 143 } 144 145 public PreparedStatement getUpdateStmt(Connection con) throws SQLException 146 { 147 if (updateSQL == null) 148 { 149 synchronized (this) 150 { 151 updateSQL = sqlGenerator.getPreparedUpdateStatement(classDescriptor); 152 if (updateSQL == null) 153 throw new PersistenceBrokerException("Could not generate Update SQL for class (" + classDescriptor.getClassOfObject().getName() + ")"); 154 } 155 } 156 try 157 { 158 return prepareStatement(con, updateSQL, Query.NOT_SCROLLABLE, true); 159 } 160 catch (SQLException ex) 161 { 162 logger.error("Error getting update statement for class (" + classDescriptor.getClassOfObject().getName() + ")", ex); 163 throw ex; 164 } 165 } 166 } 167 | Popular Tags |