01: /*
02: * Copyright 2004 (C) TJDO.
03: * All rights reserved.
04: *
05: * This software is distributed under the terms of the TJDO License version 1.0.
06: * See the terms of the TJDO License in the documentation provided with this software.
07: *
08: * $Id: DeleteRequest.java,v 1.6 2004/01/18 03:01:06 jackknifebarber Exp $
09: */
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: class DeleteRequest extends RequestUsingFields {
21: private static final Category LOG = Category
22: .getInstance(DeleteRequest.class);
23:
24: private final String textStmt;
25:
26: public DeleteRequest(ClassBaseTable table) {
27: super (table);
28:
29: textStmt = "DELETE FROM " + table.getName() + " WHERE "
30: + idMapping.getColumn().getName() + " = ?";
31: }
32:
33: public void execute(StateManager sm) {
34: if (cpxFields != null) {
35: for (int i = 0; i < cpxFields.length; ++i)
36: cpxFieldMappings[cpxFields[i]].deleteObject(sm);
37: }
38:
39: PersistenceManager pm = sm.getPersistenceManager();
40:
41: try {
42: Connection conn = pm.getConnection(true);
43:
44: try {
45: PreparedStatement ps = conn.prepareStatement(textStmt);
46:
47: try {
48: idMapping.setObject(pm, ps, 1, sm.getObjectId());
49:
50: long startTime = System.currentTimeMillis();
51:
52: ps.executeUpdate();
53:
54: if (LOG.isDebugEnabled())
55: LOG
56: .debug("Time = "
57: + (System.currentTimeMillis() - startTime)
58: + " ms: " + textStmt);
59: } finally {
60: ps.close();
61: }
62: } finally {
63: pm.releaseConnection(conn);
64: }
65: } catch (SQLException e) {
66: throw pm.getStoreManager().getDatabaseAdapter()
67: .newDataStoreException(
68: "Delete request failed: " + textStmt, e);
69: }
70: }
71: }
|