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