1 10 11 package com.triactive.jdo.store; 12 13 import com.triactive.jdo.PersistenceManager; 14 import com.triactive.jdo.StateManager; 15 import java.sql.Connection ; 16 import java.sql.PreparedStatement ; 17 import java.sql.ResultSet ; 18 import java.sql.SQLException ; 19 import org.apache.log4j.Category; 20 21 22 class LookupRequest extends Request 23 { 24 private static final Category LOG = Category.getInstance(LookupRequest.class); 25 26 private final String textStmt; 27 28 public LookupRequest(ClassBaseTable table) 29 { 30 super(table); 31 32 FetchStatement fetchStmt = new FetchStatement(table); 33 Column idCol = idMapping.getColumn(); 34 35 fetchStmt.select(idCol); 36 fetchStmt.andCondition(fetchStmt.referenceColumn(idCol) + " = ?"); 37 38 textStmt = fetchStmt.toString(); 39 } 40 41 public void execute(StateManager sm) 42 { 43 PersistenceManager pm = sm.getPersistenceManager(); 44 45 try 46 { 47 Connection conn = pm.getConnection(false); 48 49 try 50 { 51 PreparedStatement ps = conn.prepareStatement(textStmt); 52 53 try 54 { 55 idMapping.setObject(pm, ps, 1, sm.getObjectId()); 56 57 long startTime = System.currentTimeMillis(); 58 59 ResultSet rs = ps.executeQuery(); 60 61 try 62 { 63 if (LOG.isDebugEnabled()) 64 LOG.debug("Time = " + (System.currentTimeMillis() - startTime) + " ms: " + textStmt); 65 66 if (!rs.next()) 67 throw new ObjectNotFoundException("No such database row", sm.getObject()); 68 } 69 finally 70 { 71 rs.close(); 72 } 73 } 74 finally 75 { 76 ps.close(); 77 } 78 } 79 finally 80 { 81 pm.releaseConnection(conn); 82 } 83 } 84 catch (SQLException e) 85 { 86 throw pm.getStoreManager().getDatabaseAdapter().newDataStoreException("Lookup request failed: " + textStmt, e); 87 } 88 } 89 } 90 | Popular Tags |