01: /*-------------------------------------------------------------------------
02: *
03: * Copyright (c) 2004-2005, PostgreSQL Global Development Group
04: * Copyright (c) 2004, Open Cloud Limited.
05: *
06: * IDENTIFICATION
07: * $PostgreSQL: pgjdbc/org/postgresql/core/v3/Portal.java,v 1.5 2005/01/11 08:25:44 jurka Exp $
08: *
09: *-------------------------------------------------------------------------
10: */
11: package org.postgresql.core.v3;
12:
13: import java.lang.ref.PhantomReference;
14: import org.postgresql.core.*;
15:
16: /**
17: * V3 ResultCursor implementation in terms of backend Portals.
18: * This holds the state of a single Portal. We use a PhantomReference
19: * managed by our caller to handle resource cleanup.
20: *
21: * @author Oliver Jowett (oliver@opencloud.com)
22: */
23: class Portal implements ResultCursor {
24: Portal(SimpleQuery query, String portalName) {
25: this .query = query;
26: this .portalName = portalName;
27: this .encodedName = Utils.encodeUTF8(portalName);
28: }
29:
30: public void close() {
31: if (cleanupRef != null) {
32: cleanupRef.clear();
33: cleanupRef.enqueue();
34: cleanupRef = null;
35: }
36: }
37:
38: String getPortalName() {
39: return portalName;
40: }
41:
42: byte[] getEncodedPortalName() {
43: return encodedName;
44: }
45:
46: SimpleQuery getQuery() {
47: return query;
48: }
49:
50: void setCleanupRef(PhantomReference cleanupRef) {
51: this .cleanupRef = cleanupRef;
52: }
53:
54: public String toString() {
55: return portalName;
56: }
57:
58: // Holding on to a reference to the generating query has
59: // the nice side-effect that while this Portal is referenced,
60: // so is the SimpleQuery, so the underlying statement won't
61: // be closed while the portal is open (the backend closes
62: // all open portals when the statement is closed)
63:
64: private final SimpleQuery query;
65: private final String portalName;
66: private final byte[] encodedName;
67: private PhantomReference cleanupRef;
68: }
|