Commit 934c5b84 authored by Bruce Momjian's avatar Bruce Momjian

Remove postgresql jdbc files, per Peter Mount.

parent 730d1c0d
package postgresql.fastpath;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import postgresql.util.*;
// Important: There are a lot of debug code commented out. Please do not
// delete these.
/**
* This class implements the Fastpath api.
*
* <p>This is a means of executing functions imbeded in the postgresql backend
* from within a java application.
*
* <p>It is based around the file src/interfaces/libpq/fe-exec.c
*
*
* <p><b>Implementation notes:</b>
*
* <p><b><em>Network protocol:</em></b>
*
* <p>The code within the backend reads integers in reverse.
*
* <p>There is work in progress to convert all of the protocol to
* network order but it may not be there for v6.3
*
* <p>When fastpath switches, simply replace SendIntegerReverse() with
* SendInteger()
*
* @see postgresql.FastpathFastpathArg
* @see postgresql.LargeObject
*/
public class Fastpath
{
// This maps the functions names to their id's (possible unique just
// to a connection).
protected Hashtable func = new Hashtable();
protected postgresql.Connection conn; // our connection
protected postgresql.PG_Stream stream; // the network stream
/**
* Initialises the fastpath system
*
* <p><b>Important Notice</b>
* <br>This is called from postgresql.Connection, and should not be called
* from client code.
*
* @param conn postgresql.Connection to attach to
* @param stream The network stream to the backend
*/
public Fastpath(postgresql.Connection conn,postgresql.PG_Stream stream)
{
this.conn=conn;
this.stream=stream;
//DriverManager.println("Fastpath initialised");
}
/**
* Send a function call to the PostgreSQL backend
*
* @param fnid Function id
* @param resulttype True if the result is an integer, false for other results
* @param args FastpathArguments to pass to fastpath
* @return null if no data, Integer if an integer result, or byte[] otherwise
* @exception SQLException if a database-access error occurs.
*/
public Object fastpath(int fnid,boolean resulttype,FastpathArg[] args) throws SQLException
{
// added Oct 7 1998 to give us thread safety
synchronized(stream) {
// send the function call
try {
// 70 is 'F' in ASCII. Note: don't use SendChar() here as it adds padding
// that confuses the backend. The 0 terminates the command line.
stream.SendInteger(70,1);
stream.SendInteger(0,1);
//stream.SendIntegerReverse(fnid,4);
//stream.SendIntegerReverse(args.length,4);
stream.SendInteger(fnid,4);
stream.SendInteger(args.length,4);
for(int i=0;i<args.length;i++)
args[i].send(stream);
// This is needed, otherwise data can be lost
stream.flush();
} catch(IOException ioe) {
throw new PSQLException("postgresql.fp.send",new Integer(fnid),ioe);
}
// Now handle the result
// We should get 'V' on sucess or 'E' on error. Anything else is treated
// as an error.
//int in = stream.ReceiveChar();
//DriverManager.println("ReceiveChar() = "+in+" '"+((char)in)+"'");
//if(in!='V') {
//if(in=='E')
//throw new SQLException(stream.ReceiveString(4096));
//throw new SQLException("Fastpath: expected 'V' from backend, got "+((char)in));
//}
// Now loop, reading the results
Object result = null; // our result
while(true) {
int in = stream.ReceiveChar();
//DriverManager.println("ReceiveChar() = "+in+" '"+((char)in)+"'");
switch(in)
{
case 'V':
break;
//------------------------------
// Function returned properly
//
case 'G':
int sz = stream.ReceiveIntegerR(4);
//DriverManager.println("G: size="+sz); //debug
// Return an Integer if
if(resulttype)
result = new Integer(stream.ReceiveIntegerR(sz));
else {
byte buf[] = new byte[sz];
stream.Receive(buf,0,sz);
result = buf;
}
break;
//------------------------------
// Error message returned
case 'E':
throw new PSQLException("postgresql.fp.error",stream.ReceiveString(4096));
//------------------------------
// Notice from backend
case 'N':
conn.addWarning(stream.ReceiveString(4096));
break;
//------------------------------
// End of results
//
// Here we simply return res, which would contain the result
// processed earlier. If no result, this already contains null
case '0':
//DriverManager.println("returning "+result);
return result;
default:
throw new PSQLException("postgresql.fp.protocol",new Character((char)in));
}
}
}
}
/**
* Send a function call to the PostgreSQL backend by name.
*
* Note: the mapping for the procedure name to function id needs to exist,
* usually to an earlier call to addfunction().
*
* This is the prefered method to call, as function id's can/may change
* between versions of the backend.
*
* For an example of how this works, refer to postgresql.LargeObject
*
* @param name Function name
* @param resulttype True if the result is an integer, false for other
* results
* @param args FastpathArguments to pass to fastpath
* @return null if no data, Integer if an integer result, or byte[] otherwise
* @exception SQLException if name is unknown or if a database-access error
* occurs.
* @see postgresql.LargeObject
*/
public Object fastpath(String name,boolean resulttype,FastpathArg[] args) throws SQLException
{
//DriverManager.println("Fastpath: calling "+name);
return fastpath(getID(name),resulttype,args);
}
/**
* This convenience method assumes that the return value is an Integer
* @param name Function name
* @param args Function arguments
* @return integer result
* @exception SQLException if a database-access error occurs or no result
*/
public int getInteger(String name,FastpathArg[] args) throws SQLException
{
Integer i = (Integer)fastpath(name,true,args);
if(i==null)
throw new PSQLException("postgresql.fp.expint",name);
return i.intValue();
}
/**
* This convenience method assumes that the return value is an Integer
* @param name Function name
* @param args Function arguments
* @return byte[] array containing result
* @exception SQLException if a database-access error occurs or no result
*/
public byte[] getData(String name,FastpathArg[] args) throws SQLException
{
return (byte[])fastpath(name,false,args);
}
/**
* This adds a function to our lookup table.
*
* <p>User code should use the addFunctions method, which is based upon a
* query, rather than hard coding the oid. The oid for a function is not
* guaranteed to remain static, even on different servers of the same
* version.
*
* @param name Function name
* @param fnid Function id
*/
public void addFunction(String name,int fnid)
{
func.put(name,new Integer(fnid));
}
/**
* This takes a ResultSet containing two columns. Column 1 contains the
* function name, Column 2 the oid.
*
* <p>It reads the entire ResultSet, loading the values into the function
* table.
*
* <p><b>REMEMBER</b> to close() the resultset after calling this!!
*
* <p><b><em>Implementation note about function name lookups:</em></b>
*
* <p>PostgreSQL stores the function id's and their corresponding names in
* the pg_proc table. To speed things up locally, instead of querying each
* function from that table when required, a Hashtable is used. Also, only
* the function's required are entered into this table, keeping connection
* times as fast as possible.
*
* <p>The postgresql.LargeObject class performs a query upon it's startup,
* and passes the returned ResultSet to the addFunctions() method here.
*
* <p>Once this has been done, the LargeObject api refers to the functions by
* name.
*
* <p>Dont think that manually converting them to the oid's will work. Ok,
* they will for now, but they can change during development (there was some
* discussion about this for V7.0), so this is implemented to prevent any
* unwarranted headaches in the future.
*
* @param rs ResultSet
* @exception SQLException if a database-access error occurs.
* @see postgresql.LargeObjectManager
*/
public void addFunctions(ResultSet rs) throws SQLException
{
while(rs.next()) {
func.put(rs.getString(1),new Integer(rs.getInt(2)));
}
}
/**
* This returns the function id associated by its name
*
* <p>If addFunction() or addFunctions() have not been called for this name,
* then an SQLException is thrown.
*
* @param name Function name to lookup
* @return Function ID for fastpath call
* @exception SQLException is function is unknown.
*/
public int getID(String name) throws SQLException
{
Integer id = (Integer)func.get(name);
// may be we could add a lookup to the database here, and store the result
// in our lookup table, throwing the exception if that fails.
// We must, however, ensure that if we do, any existing ResultSet is
// unaffected, otherwise we could break user code.
//
// so, until we know we can do this (needs testing, on the TODO list)
// for now, we throw the exception and do no lookups.
if(id==null)
throw new PSQLException("postgresql.fp.unknown",name);
return id.intValue();
}
}
package postgresql.fastpath;
import java.io.*;
import java.lang.*;
import java.net.*;
import java.util.*;
import java.sql.*;
import postgresql.util.*;
/**
* Each fastpath call requires an array of arguments, the number and type
* dependent on the function being called.
*
* <p>This class implements methods needed to provide this capability.
*
* <p>For an example on how to use this, refer to the postgresql.largeobject
* package
*
* @see postgresql.fastpath.Fastpath
* @see postgresql.largeobject.LargeObjectManager
* @see postgresql.largeobject.LargeObject
*/
public class FastpathArg
{
/**
* Type of argument, true=integer, false=byte[]
*/
public boolean type;
/**
* Integer value if type=true
*/
public int value;
/**
* Byte value if type=false;
*/
public byte[] bytes;
/**
* Constructs an argument that consists of an integer value
* @param value int value to set
*/
public FastpathArg(int value)
{
type=true;
this.value=value;
}
/**
* Constructs an argument that consists of an array of bytes
* @param bytes array to store
*/
public FastpathArg(byte bytes[])
{
type=false;
this.bytes=bytes;
}
/**
* Constructs an argument that consists of part of a byte array
* @param buf source array
* @param off offset within array
* @param len length of data to include
*/
public FastpathArg(byte buf[],int off,int len)
{
type=false;
bytes = new byte[len];
System.arraycopy(buf,off,bytes,0,len);
}
/**
* Constructs an argument that consists of a String.
* @param s String to store
*/
public FastpathArg(String s)
{
this(s.getBytes());
}
/**
* This sends this argument down the network stream.
*
* <p>The stream sent consists of the length.int4 then the contents.
*
* <p><b>Note:</b> This is called from Fastpath, and cannot be called from
* client code.
*
* @param s output stream
* @exception IOException if something failed on the network stream
*/
protected void send(postgresql.PG_Stream s) throws IOException
{
if(type) {
// argument is an integer
s.SendInteger(4,4); // size of an integer
s.SendInteger(value,4); // integer value of argument
} else {
// argument is a byte array
s.SendInteger(bytes.length,4); // size of array
s.Send(bytes);
}
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This represents the box datatype within postgresql.
*/
public class PGbox extends PGobject implements Serializable,Cloneable
{
/**
* These are the two points.
*/
public PGpoint point[] = new PGpoint[2];
/**
* @param x1 first x coordinate
* @param y1 first y coordinate
* @param x2 second x coordinate
* @param y2 second y coordinate
*/
public PGbox(double x1,double y1,double x2,double y2)
{
this();
this.point[0] = new PGpoint(x1,y1);
this.point[1] = new PGpoint(x2,y2);
}
/**
* @param p1 first point
* @param p2 second point
*/
public PGbox(PGpoint p1,PGpoint p2)
{
this();
this.point[0] = p1;
this.point[1] = p2;
}
/**
* @param s Box definition in PostgreSQL syntax
* @exception SQLException if definition is invalid
*/
public PGbox(String s) throws SQLException
{
this();
setValue(s);
}
/**
* Required constructor
*/
public PGbox()
{
setType("box");
}
/**
* This method sets the value of this object. It should be overidden,
* but still called by subclasses.
*
* @param value a string representation of the value of the object
* @exception SQLException thrown if value is invalid for this type
*/
public void setValue(String value) throws SQLException
{
PGtokenizer t = new PGtokenizer(value,',');
if(t.getSize() != 2)
throw new PSQLException("postgresql.geo.box",value);
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGbox) {
PGbox p = (PGbox)obj;
return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
(p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
return new PGbox((PGpoint)point[0].clone(),(PGpoint)point[1].clone());
}
/**
* @return the PGbox in the syntax expected by postgresql
*/
public String getValue()
{
return point[0].toString()+","+point[1].toString();
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This represents postgresql's circle datatype, consisting of a point and
* a radius
*/
public class PGcircle extends PGobject implements Serializable,Cloneable
{
/**
* This is the centre point
*/
public PGpoint center;
/**
* This is the radius
*/
double radius;
/**
* @param x coordinate of centre
* @param y coordinate of centre
* @param r radius of circle
*/
public PGcircle(double x,double y,double r)
{
this(new PGpoint(x,y),r);
}
/**
* @param c PGpoint describing the circle's centre
* @param r radius of circle
*/
public PGcircle(PGpoint c,double r)
{
this();
this.center = c;
this.radius = r;
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public PGcircle(String s) throws SQLException
{
this();
setValue(s);
}
/**
* This constructor is used by the driver.
*/
public PGcircle()
{
setType("circle");
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeAngle(s),',');
if(t.getSize() != 2)
throw new PSQLException("postgresql.geo.circle",s);
try {
center = new PGpoint(t.getToken(0));
radius = Double.valueOf(t.getToken(1)).doubleValue();
} catch(NumberFormatException e) {
throw new PSQLException("postgresql.geo.circle",e);
}
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGcircle) {
PGcircle p = (PGcircle)obj;
return p.center.equals(center) && p.radius==radius;
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
return new PGcircle((PGpoint)center.clone(),radius);
}
/**
* @return the PGcircle in the syntax expected by postgresql
*/
public String getValue()
{
return "<"+center+","+radius+">";
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This implements a line consisting of two points.
*
* Currently line is not yet implemented in the backend, but this class
* ensures that when it's done were ready for it.
*/
public class PGline extends PGobject implements Serializable,Cloneable
{
/**
* These are the two points.
*/
public PGpoint point[] = new PGpoint[2];
/**
* @param x1 coordinate for first point
* @param y1 coordinate for first point
* @param x2 coordinate for second point
* @param y2 coordinate for second point
*/
public PGline(double x1,double y1,double x2,double y2)
{
this(new PGpoint(x1,y1),new PGpoint(x2,y2));
}
/**
* @param p1 first point
* @param p2 second point
*/
public PGline(PGpoint p1,PGpoint p2)
{
this();
this.point[0] = p1;
this.point[1] = p2;
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public PGline(String s) throws SQLException
{
this();
setValue(s);
}
/**
* reuired by the driver
*/
public PGline()
{
setType("line");
}
/**
* @param s Definition of the line segment in PostgreSQL's syntax
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
if(t.getSize() != 2)
throw new PSQLException("postgresql.geo.line",s);
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGline) {
PGline p = (PGline)obj;
return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
(p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
return new PGline((PGpoint)point[0].clone(),(PGpoint)point[1].clone());
}
/**
* @return the PGline in the syntax expected by postgresql
*/
public String getValue()
{
return "["+point[0]+","+point[1]+"]";
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This implements a lseg (line segment) consisting of two points
*/
public class PGlseg extends PGobject implements Serializable,Cloneable
{
/**
* These are the two points.
*/
public PGpoint point[] = new PGpoint[2];
/**
* @param x1 coordinate for first point
* @param y1 coordinate for first point
* @param x2 coordinate for second point
* @param y2 coordinate for second point
*/
public PGlseg(double x1,double y1,double x2,double y2)
{
this(new PGpoint(x1,y1),new PGpoint(x2,y2));
}
/**
* @param p1 first point
* @param p2 second point
*/
public PGlseg(PGpoint p1,PGpoint p2)
{
this();
this.point[0] = p1;
this.point[1] = p2;
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public PGlseg(String s) throws SQLException
{
this();
setValue(s);
}
/**
* reuired by the driver
*/
public PGlseg()
{
setType("lseg");
}
/**
* @param s Definition of the line segment in PostgreSQL's syntax
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removeBox(s),',');
if(t.getSize() != 2)
throw new PSQLException("postgresql.geo.lseg");
point[0] = new PGpoint(t.getToken(0));
point[1] = new PGpoint(t.getToken(1));
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGlseg) {
PGlseg p = (PGlseg)obj;
return (p.point[0].equals(point[0]) && p.point[1].equals(point[1])) ||
(p.point[0].equals(point[1]) && p.point[1].equals(point[0]));
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
return new PGlseg((PGpoint)point[0].clone(),(PGpoint)point[1].clone());
}
/**
* @return the PGlseg in the syntax expected by postgresql
*/
public String getValue()
{
return "["+point[0]+","+point[1]+"]";
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This implements a path (a multiple segmented line, which may be closed)
*/
public class PGpath extends PGobject implements Serializable,Cloneable
{
/**
* True if the path is open, false if closed
*/
public boolean open;
/**
* The points defining this path
*/
public PGpoint points[];
/**
* @param points the PGpoints that define the path
* @param open True if the path is open, false if closed
*/
public PGpath(PGpoint[] points,boolean open)
{
this();
this.points = points;
this.open = open;
}
/**
* Required by the driver
*/
public PGpath()
{
setType("path");
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public PGpath(String s) throws SQLException
{
this();
setValue(s);
}
/**
* @param s Definition of the path in PostgreSQL's syntax
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
// First test to see if were open
if(s.startsWith("[") && s.endsWith("]")) {
open = true;
s = PGtokenizer.removeBox(s);
} else if(s.startsWith("(") && s.endsWith(")")) {
open = false;
s = PGtokenizer.removePara(s);
} else
throw new PSQLException("postgresql.geo.path");
PGtokenizer t = new PGtokenizer(s,',');
int npoints = t.getSize();
points = new PGpoint[npoints];
for(int p=0;p<npoints;p++)
points[p] = new PGpoint(t.getToken(p));
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGpath) {
PGpath p = (PGpath)obj;
if(p.points.length != points.length)
return false;
if(p.open != open)
return false;
for(int i=0;i<points.length;i++)
if(!points[i].equals(p.points[i]))
return false;
return true;
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
PGpoint ary[] = new PGpoint[points.length];
for(int i=0;i<points.length;i++)
ary[i]=(PGpoint)points[i].clone();
return new PGpath(ary,open);
}
/**
* This returns the polygon in the syntax expected by postgresql
*/
public String getValue()
{
StringBuffer b = new StringBuffer(open?"[":"(");
for(int p=0;p<points.length;p++) {
if(p>0) b.append(",");
b.append(points[p].toString());
}
b.append(open?"]":")");
return b.toString();
}
public boolean isOpen()
{
return open;
}
public boolean isClosed()
{
return !open;
}
public void closePath()
{
open = false;
}
public void openPath()
{
open = true;
}
}
package postgresql.geometric;
import java.awt.Point;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This implements a version of java.awt.Point, except it uses double
* to represent the coordinates.
*
* <p>It maps to the point datatype in postgresql.
*/
public class PGpoint extends PGobject implements Serializable,Cloneable
{
/**
* The X coordinate of the point
*/
public double x;
/**
* The Y coordinate of the point
*/
public double y;
/**
* @param x coordinate
* @param y coordinate
*/
public PGpoint(double x,double y)
{
this();
this.x = x;
this.y = y;
}
/**
* This is called mainly from the other geometric types, when a
* point is imbeded within their definition.
*
* @param value Definition of this point in PostgreSQL's syntax
*/
public PGpoint(String value) throws SQLException
{
this();
setValue(value);
}
/**
* Required by the driver
*/
public PGpoint()
{
setType("point");
}
/**
* @param s Definition of this point in PostgreSQL's syntax
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s),',');
try {
x = Double.valueOf(t.getToken(0)).doubleValue();
y = Double.valueOf(t.getToken(1)).doubleValue();
} catch(NumberFormatException e) {
throw new PSQLException("postgresql.geo.point",e.toString());
}
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGpoint) {
PGpoint p = (PGpoint)obj;
return x == p.x && y == p.y;
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
return new PGpoint(x,y);
}
/**
* @return the PGpoint in the syntax expected by postgresql
*/
public String getValue()
{
return "("+x+","+y+")";
}
/**
* Translate the point with the supplied amount.
* @param x integer amount to add on the x axis
* @param y integer amount to add on the y axis
*/
public void translate(int x,int y)
{
translate((double)x,(double)y);
}
/**
* Translate the point with the supplied amount.
* @param x double amount to add on the x axis
* @param y double amount to add on the y axis
*/
public void translate(double x,double y)
{
this.x += x;
this.y += y;
}
/**
* Moves the point to the supplied coordinates.
* @param x integer coordinate
* @param y integer coordinate
*/
public void move(int x,int y)
{
setLocation(x,y);
}
/**
* Moves the point to the supplied coordinates.
* @param x double coordinate
* @param y double coordinate
*/
public void move(double x,double y)
{
this.x = x;
this.y = y;
}
/**
* Moves the point to the supplied coordinates.
* refer to java.awt.Point for description of this
* @param x integer coordinate
* @param y integer coordinate
* @see java.awt.Point
*/
public void setLocation(int x,int y)
{
move((double)x,(double)y);
}
/**
* Moves the point to the supplied java.awt.Point
* refer to java.awt.Point for description of this
* @param p Point to move to
* @see java.awt.Point
*/
public void setLocation(Point p)
{
setLocation(p.x,p.y);
}
}
package postgresql.geometric;
import java.io.*;
import java.sql.*;
import postgresql.util.*;
/**
* This implements the polygon datatype within PostgreSQL.
*/
public class PGpolygon extends PGobject implements Serializable,Cloneable
{
/**
* The points defining the polygon
*/
public PGpoint points[];
/**
* Creates a polygon using an array of PGpoints
*
* @param points the points defining the polygon
*/
public PGpolygon(PGpoint[] points)
{
this();
this.points = points;
}
/**
* @param s definition of the circle in PostgreSQL's syntax.
* @exception SQLException on conversion failure
*/
public PGpolygon(String s) throws SQLException
{
this();
setValue(s);
}
/**
* Required by the driver
*/
public PGpolygon()
{
setType("polygon");
}
/**
* @param s Definition of the polygon in PostgreSQL's syntax
* @exception SQLException on conversion failure
*/
public void setValue(String s) throws SQLException
{
PGtokenizer t = new PGtokenizer(PGtokenizer.removePara(s),',');
int npoints = t.getSize();
points = new PGpoint[npoints];
for(int p=0;p<npoints;p++)
points[p] = new PGpoint(t.getToken(p));
}
/**
* @param obj Object to compare with
* @return true if the two boxes are identical
*/
public boolean equals(Object obj)
{
if(obj instanceof PGpolygon) {
PGpolygon p = (PGpolygon)obj;
if(p.points.length != points.length)
return false;
for(int i=0;i<points.length;i++)
if(!points[i].equals(p.points[i]))
return false;
return true;
}
return false;
}
/**
* This must be overidden to allow the object to be cloned
*/
public Object clone()
{
PGpoint ary[] = new PGpoint[points.length];
for(int i=0;i<points.length;i++)
ary[i] = (PGpoint)points[i].clone();
return new PGpolygon(ary);
}
/**
* @return the PGpolygon in the syntax expected by postgresql
*/
public String getValue()
{
StringBuffer b = new StringBuffer();
b.append("(");
for(int p=0;p<points.length;p++) {
if(p>0) b.append(",");
b.append(points[p].toString());
}
b.append(")");
return b.toString();
}
}
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment