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.SQLException ; 18 import org.apache.log4j.Category; 19 20 21 class DeleteRequest extends RequestUsingFields 22 { 23 private static final Category LOG = Category.getInstance(DeleteRequest.class); 24 25 private final String textStmt; 26 27 public DeleteRequest(ClassBaseTable table) 28 { 29 super(table); 30 31 textStmt = "DELETE FROM " + table.getName() + " WHERE " + idMapping.getColumn().getName() + " = ?"; 32 } 33 34 public void execute(StateManager sm) 35 { 36 if (cpxFields != null) 37 { 38 for (int i = 0; i < cpxFields.length; ++i) 39 cpxFieldMappings[cpxFields[i]].deleteObject(sm); 40 } 41 42 PersistenceManager pm = sm.getPersistenceManager(); 43 44 try 45 { 46 Connection conn = pm.getConnection(true); 47 48 try 49 { 50 PreparedStatement ps = conn.prepareStatement(textStmt); 51 52 try 53 { 54 idMapping.setObject(pm, ps, 1, sm.getObjectId()); 55 56 long startTime = System.currentTimeMillis(); 57 58 ps.executeUpdate(); 59 60 if (LOG.isDebugEnabled()) 61 LOG.debug("Time = " + (System.currentTimeMillis() - startTime) + " ms: " + textStmt); 62 } 63 finally 64 { 65 ps.close(); 66 } 67 } 68 finally 69 { 70 pm.releaseConnection(conn); 71 } 72 } 73 catch (SQLException e) 74 { 75 throw pm.getStoreManager().getDatabaseAdapter().newDataStoreException("Delete request failed: " + textStmt, e); 76 } 77 } 78 } 79 | Popular Tags |