1 56 57 package org.objectstyle.cayenne.dba.oracle; 58 59 import java.lang.reflect.Method ; 60 import java.sql.PreparedStatement ; 61 import java.sql.Statement ; 62 63 import org.apache.log4j.Level; 64 import org.apache.log4j.Logger; 65 import org.objectstyle.cayenne.access.QueryLogger; 66 import org.objectstyle.cayenne.access.trans.SelectTranslator; 67 68 73 public class OracleSelectTranslator extends SelectTranslator { 74 75 private static Logger logObj = Logger.getLogger(OracleSelectTranslator.class); 76 77 private static boolean testedDriver; 78 private static boolean useOptimizations; 79 private static Method statementSetRowPrefetch; 80 81 private static final Object [] rowPrefetchArgs = new Object [] { 82 new Integer (100) 83 }; 84 85 89 private static final synchronized void testDriver(Statement st) { 90 if (testedDriver) { 91 return; 92 } 93 94 if (st == null) { 96 return; 97 } 98 99 testedDriver = true; 100 101 try { 102 104 Class [] args2 = new Class [] { 105 Integer.TYPE 106 }; 107 statementSetRowPrefetch = st.getClass().getMethod("setRowPrefetch", args2); 108 109 useOptimizations = true; 110 } 111 catch (Exception ex) { 112 useOptimizations = false; 113 statementSetRowPrefetch = null; 114 115 StringBuffer buf = new StringBuffer (); 116 buf 117 .append("Unknown Oracle statement type: [") 118 .append(st.getClass().getName()) 119 .append("]. No Oracle optimizations applied."); 120 121 logObj.info(buf.toString()); 122 } 123 } 124 125 129 public PreparedStatement createStatement(Level logLevel) throws Exception { 130 String sqlStr = createSqlString(); 131 QueryLogger.logQuery(logLevel, sqlStr, values); 132 PreparedStatement stmt = connection.prepareStatement(sqlStr); 133 134 initStatement(stmt); 135 136 if (!testedDriver) { 137 testDriver(stmt); 138 } 139 140 if (useOptimizations) { 141 143 147 154 155 statementSetRowPrefetch.invoke(stmt, rowPrefetchArgs); 163 } 164 165 return stmt; 166 } 167 } | Popular Tags |