Postgres is an extensible database system. You can add your own functions to the backend, which can then be called from queries, or even add your own data types.
Postgres は拡張可能なデータベースシステ ムです。問い合わせから呼び出すことができる、独自の関数をバックエン ドに追加することができます。独自の型さえも追加することができます。
Now, as these are facilities unique to us, we support them from Java, with a set of extension API's. Some features within the core of the standard driver actually use these extensions to implement Large Objects, etc.
こういった独特な機構がありますので、Java でもこれを API の拡張セットを用意してサポートします。実際、 標準ドライバの中核でも、ラージオブジェクトなどの実装のためにこの拡 張を使用しています。 原文によるコメントアウト ************************************************************ Nothing marked up from here on. It looks like it will be tricky: what do we want to do with the class inheritance diagrams? - thomas 1998-10-23 ************************************************************
Accessing the extensions
拡張機能へのアクセス To access some of the extensions, you need to use some extra methods in the postgresql.Connection class. In this case, you would need to case the return value of Driver.getConnection(). For example: いくつかの拡張 API にアクセスするには、postgresql.Connection クラス の追加メソッドのいくつかを使用しなければなりません。この場合、 Driver.getConnection() からの戻り値をキャストしなければなりません。 例: Connection db = Driver.getConnection(url,user,pass); // later on Fastpath fp = ((postgresql.Connection)db).getFastpathAPI(); Class postgresql.Connection java.lang.Object | +----postgresql.Connection public class Connection extends Object implements Connection These are the extra methods used to gain access to our extensions. I have not listed the methods defined by java.sql.Connection. 拡張 API にアクセスするために使用される追加メソッドがあります。 java.sql.Connection で定義されたメソッドは示しません。 public Fastpath getFastpathAPI() throws SQLException This returns the Fastpath API for the current connection. NOTE: This is not part of JDBC, but allows access to functions on the postgresql backend itself. It is primarily used by the LargeObject API The best way to use this is as follows: import postgresql.fastpath.*; ... Fastpath fp = ((postgresql.Connection)myconn).getFastpathAPI(); where myconn is an open Connection to postgresql. Returns: Fastpath object allowing access to functions on the postgresql backend. Throws: SQLException by Fastpath when initialising for first time 現在の接続用の Fastpath API を返します。 注意 : これは JDBC の一部ではありませんが、 これによって、postgresql のバックエンド自身が持つ関数にアクセ スすることができます。 主に LargeObject API で使用されます。 この関数を使用する最善の方法は次のようなものです。 import postgresql.fastpath.*; ... Fastpath fp = ((postgresql.Connection)myconn).getFastpathAPI(); ここで、myconn は開いているpostgresqlへのConnection オブジェクトです。 戻り値: postgresql バックエンドにある関数へのアクセスを可能にする Fastpath オブジェクト 例外: SQLException Fastpath の初回の初期化時に 投げられる可能性があります public LargeObjectManager getLargeObjectAPI() throws SQLException This returns the LargeObject API for the current connection. NOTE: This is not part of JDBC, but allows access to functions on the postgresql backend itself. The best way to use this is as follows: import postgresql.largeobject.*; ... LargeObjectManager lo = ((postgresql.Connection)myconn).getLargeObjectAPI(); where myconn is an open Connection to postgresql. Returns: LargeObject object that implements the API Throws: SQLException by LargeObject when initialising for first time 現在の接続用のラージオブジェクト API を返します。 注意: これは JDBC の一部ではありませんが、 これを使って postgresql バックエンド自体にある関数にアクセス できます。 この関数の最善の使用方法は以下のものです。 import postgresql.largeobject.*; ... LargeObjectManager lo = ((postgresql.Connection)myconn).getLargeObjectAPI(); ここで、myconn は開いている postgresql への Connection オブジェクトです。 戻り値: API を実装した LargeObject オ ブジェクト 例外: SQLException LargeObject の初回の初期化時に投げられる可能性があ ります public void addDataType(String type, String name) This allows client code to add a handler for one of postgresql's more unique data types. Normally, a data type not known by the driver is returned by ResultSet.getObject() as a PGobject instance. This method allows you to write a class that extends PGobject, and tell the driver the type name, and class name to use. The down side to this, is that you must call this method each time a connection is made. NOTE: This is not part of JDBC, but an extension. The best way to use this is as follows: ... ((postgresql.Connection)myconn).addDataType("mytype","my.class.name"- ); ... where myconn is an open Connection to postgresql. The handling class must extend postgresql.util.PGobject See Also: PGobject これによってクライアントのコードが、多くの postgresql 独特の データ型の 1 つ用のハンドラを追加することができます。通常、 ドライバで認識されないデータ型は、PGobject インスタンスとして ResultSet.getObject() から返されます。 このメソッドを使って、PGobject を拡張したクラスを書くことや、 ドライバに型名と使用するクラス名を通知することができます。 この欠点は、接続を確立する度にこのメソッドを呼び出さなければ ならないことです。 注意: これは JDBC の一部でなく、拡張です。 この関数を使用する最善の方法は次のようなものです。 ... ((postgresql.Connection)myconn).addDataType("mytype","my.class.name"- ); ... ここで、myconn は開いている postgresql への Connection オブジェクトです。 取り扱うクラスは postgresql.util.PGobject を継承する必要 があります。 Fastpath Fastpath is an API that exists within the libpq C interface, and allows a client machine to execute a function on the database backend. Most client code will not need to use this method, but it's provided because the Large Object API uses it. Fastpath は libpq C インタフェース内に存在する API で、これによってクライアントマシンはデータベースバックエンドにある関 数を実行することができます。ほとんどのクライアントコードでは、このメ ソッドを使用する必要がありません。しかし、ラージオブジェクト API にて使用しますので、用意されています。 To use, you need to import the postgresql.fastpath package, using the line: import postgresql.fastpath.*; 使用するためには、次の行のように postgresql.fastpath パッケージをイン ポートしなければなりません。 import postgresql.fastpath.*; Then, in your code, you need to get a FastPath object: Fastpath fp = ((postgresql.Connection)conn).getFastpathAPI(); そして、FastPath オブジェクトを入手したい時に次のコードを書きます。 This will return an instance associated with the database connection that you can use to issue commands. The casing of Connection to postgresql.Connection is required, as the getFastpathAPI() is one of our own methods, not JDBC's. これはデータベース接続に関連づいた、コマンドを発行する際に使用する インスタンスを返します。getFastpathAPI() は JDBC のメソッドではなく、独自のメソッドですので、 Connection オブジェクトを postgresql.Connection オブジェクトにキャ ストすることが必要です。 Once you have a Fastpath instance, you can use the fastpath() methods to execute a backend function. Fastpath インスタンスを所有すれば、fastpath() メソッドを使用してバッ クエンドの関数を実行することができます。 Class postgresql.fastpath.Fastpath java.lang.Object | +----postgresql.fastpath.Fastpath public class Fastpath extends Object This class implements the Fastpath api. このクラスは Fastpath API を実装します。 This is a means of executing functions imbeded in the postgresql backend from within a java application. これは postgresql のバックエンドにある関数を Java アプリケーショ ンから実行するための手段です。 It is based around the file src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c ファイルを元に作成しています。 See Also: 参照 FastpathFastpathArg, LargeObject Methods メソッド public Object fastpath(int fnid, boolean resulttype, FastpathArg args[]) throws SQLException Send a function call to the PostgreSQL backend 関数呼び出しを PostgreSQL バックエンドに送ります。 Parameters: fnid - Function id resulttype - True if the result is an integer, false for other results args - FastpathArguments to pass to fastpath パラメータ: fnid - 関数 ID resulttype - 結果が整数ならば真、その他の場合は偽 args - fastpath に渡す FastpathArguments Returns: null if no data, Integer if an integer result, or byte[] otherwise 戻り値: データが無い場合、null、整数の結果ならば Integer 型、 さもなくば byte[] Throws: SQLException if a database-access error occurs. 例外: SQLException データベースアクセスエラーが発生した場合 public Object fastpath(String name, boolean resulttype, FastpathArg args[]) throws SQLException Send a function call to the PostgreSQL backend by name. 名前によって PostgreSQL バックエンドに関数呼び出しを送ります。 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 注意: プロシージャ名の関数 ID への割り当ては、通常は事前に addfunction() を呼び出して、存在しなければなりません。 関数 ID はバックエンドのバージョンによって異なりますの で、このメソッドの呼び出しは推奨されています。このメソ ッドの使用例については postgresql.LargeObject を参照し て下さい。 Parameters: name - Function name resulttype - True if the result is an integer, false for other results args - FastpathArguments to pass to fastpath パラメータ: name - 関数名 resulttype - 結果が整数ならば真、さもなくば偽 args - fastpath に渡す FastpathArguments オブジ ェクト Returns: null if no data, Integer if an integer result, or byte[] otherwise 戻り値: データが無ければ null、整数の結果であれば Integer 型、 さもなくば byte[] Throws: SQLException if name is unknown or if a database-access error occurs. 例外: SQLException 引数 name が未知、または、データベースアクセスエラー の場合 See Also: 参照: LargeObject public int getInteger(String name, FastpathArg args[]) throws SQLException This convenience method assumes that the return value is an Integer この簡易メソッドは結果の値が整数であることを仮定してい ます。 Parameters: name - Function name args - Function arguments パラメータ: name - 関数名 args - 関数への引数 Returns: integer result 戻り値: 整数の結果 Throws: SQLException if a database-access error occurs or no result 例外: SQLException データベースアクセスエラーが発生した、または、結果 が無い場合 public byte[] getData(String name, FastpathArg args[]) throws SQLException This convenience method assumes that the return value is binary data この簡易メソッドは結果の値がバイナリデータであると仮定し ています。 Parameters: name - Function name args - Function arguments パラメータ: name - 関数名 args - 関数への引数 Returns: byte[] array containing result 戻り値: 結果を持つbyte[] 配列 Throws: SQLException if a database-access error occurs or no result 例外: SQLException データベースアクセスエラーが発生した、または、結 果が無い場合 public void addFunction(String name, int fnid) This adds a function to our lookup table. 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. これは関数を検索テーブルに追加します。 ユーザコードは addFunctions メソッドを使用しなければなり ません。このメソッドは oid を直接記述しておらず問い合わせ に基づいたものです。関数の oid は静的のままであることは保 証されていませんし、同一のバージョンのサーバ間でさえも異な ります。 Parameters: name - Function name fnid - Function id パラメータ: name - 関数名 fnid - 関数 ID public void addFunctions(ResultSet rs) throws SQLException This takes a ResultSet containing two columns. Column 1 contains the function name, Column 2 the oid. It reads the entire ResultSet, loading the values into the function table. REMEMBER to close() the resultset after calling this!! Implementation note about function name lookups: このメソッドは 2 つのカラムを持つ ResultSet を引数とし てとります。カラム 1 は関数名、カラム 2 は oid を持ちま す。 ResultSet 全体を読み取り、その値を関数テーブル中に読み込 みます。 このメソッドを呼び出した後に resultset を close() するこ とを忘れないで下さい。 関数名の検索に関する実装時の注意書き: 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. PostgreSQL は関数 ID と ID に対応する名前を pg_proc テー ブルに保存します。ローカルに処理速度を上げるために、要求 に応じてこのテーブルに関数を問い合わせるのではなく Hashtable が使用されています。また、関数の必須項目のみが このテーブルに登録されていますので、接続を維持しておくこ とでできるだけ処理速度を向上させます。 The postgresql.LargeObject class performs a query upon it's startup, and passes the returned ResultSet to the addFunctions() method here. postgresql.LargeObject クラスはその起動時に問い合わせを 行ない、この段階で返された ResultSet を addFunctions() メソッドに渡します。 Once this has been done, the LargeObject api refers to the functions by name. これを行なった後、LargeObject API はその関数を名前で参照 します。 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. 手作業による oid への変換ができるとは考えないで下さい。 いいですか。これらは現時点のものです。開発を通して変更 されます。(V7.0でもこの問題について議論が何回かありま した。)ですから、これは将来の不当な問題を防ぐために実 装されています。 Parameters: パラメータ: rs - ResultSet Throws: SQLException if a database-access error occurs. 例外: SQLException データベースアクセスエラーが発生した場合 See Also: 参照: LargeObjectManager public int getID(String name) throws SQLException This returns the function id associated by its name If addFunction() or addFunctions() have not been called for this name, then an SQLException is thrown. このメソッドは名前に関連付けられた関数 ID を返します。 addFunction() もしくは addFunctions() がこの名前を使っ て呼び出されていなければ、SQLException が投げられます。 Parameters: name - Function name to lookup パラメータ: name - 検索対象となる関数名 Returns: Function ID for fastpath call 戻り値: fastpath 呼び出し用の関数ID Throws: SQLException is function is unknown. 例外: SQLException 関数が未知である場合 Class postgresql.fastpath.FastpathArg java.lang.Object | +----postgresql.fastpath.FastpathArg public class FastpathArg extends Object Each fastpath call requires an array of arguments, the number and type dependent on the function being called. This class implements methods needed to provide this capability. For an example on how to use this, refer to the postgresql.largeobject package 各 fastpath 呼び出しは引数の配列、引数の数、呼び出される関数に依 存する型を必要とします。 このクラスはこの能力を提供するために必要なメソッドを実装します。 このクラスの使用例については、postgresql.largeobject パッケージを 参照して下さい。 See Also: 参照: Fastpath, LargeObjectManager, LargeObject Constructors コンストラクタ public FastpathArg(int value) Constructs an argument that consists of an integer value 整数値からなる引数で構築します。 Parameters: value - int value to set パラメータ: value - 設定する整数値 public FastpathArg(byte bytes[]) Constructs an argument that consists of an array of bytes byte 型の配列からなる引数で構築します。 Parameters: bytes - array to store パラメータ: bytes - 保存する配列 public FastpathArg(byte buf[], int off, int len) Constructs an argument that consists of part of a byte array byte 型の配列の一部からなる引数で構築します。 Parameters: buf - source array off - offset within array len - length of data to include パラメータ: buf - 元となる配列 off - 配列内のオフセット len - 含めるべきデータ長 public FastpathArg(String s) Constructs an argument that consists of a String. 文字列からなる引数で構築します。 Parameters: s - String to store パラメータ: s - 保存する文字列 Geometric Data Types 地理的データ型 PostgreSQL has a set of datatypes that can store geometric features into a table. These range from single points, lines, and polygons. We support these types in Java with the postgresql.geometric package. It contains classes that extend the postgresql.util.PGobject class. Refer to that class for details on how to implement your own data type handlers. PostgreSQL は、地理的な特徴をテーブルに保存できるデータ型の集合を 持ちます。これらは 1 つの点、線、多角形を扱います。Java では postgresql.geometric パッケージを使用してこれらの型をサポートしま す。ここには postgresql.util.PGobject クラスを継承したクラスがあり ます。どのように独自のデータ型ハンドラを実装するのかについての詳細 はこのクラスを参照して下さい。 Class postgresql.geometric.PGbox java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGbox public class PGbox extends PGobject implements Serializable, Cloneable This represents the box datatype within postgresql. このクラスは postgresql における box データ型を表します。 Variables 変数 public PGpoint point[] These are the two corner points of the box. ボックスの角を示す 2 つの点があります。 Constructors public PGbox(double x1, double y1, double x2, double y2) Parameters: x1 - first x coordinate y1 - first y coordinate x2 - second x coordinate y2 - second y coordinate パラメータ: x1 - 1 番目の x 座標 y1 - 1 番目の y 座標 x2 - 2 番目の x 座標 y2 - 2 番目の y 座標 public PGbox(PGpoint p1, PGpoint p2) Parameters: p1 - first point p2 - second point パラメータ: p1 - 1 番目の点 p2 - 2 番目の点 public PGbox(String s) throws SQLException Parameters: s - Box definition in PostgreSQL syntax パラメータ: s - PostgreSQL 構文によるボックス定義 Throws: SQLException if definition is invalid 例外: SQLException 定義が無効であった場合 public PGbox() Required constructor 必須のコンストラクタ。 Methods メソッド public void setValue(String value) throws SQLException This method sets the value of this object. It should be overidden, but still called by subclasses. このメソッドはこのオブジェクトの値を設定します。これは サブクラスでオーバライドしなければなりませんが、サブク ラスからも呼び出されます。 Parameters: value - a string representation of the value of the object パラメータ: value - このオブジェクトの値の文字列表現 Throws: SQLException thrown if value is invalid for this type 例外: SQLException 値がこの型では無効であった場合 Overrides: setValue in class PGobject オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with パラメータ: obj - 比較するオブジェクト Returns: true if the two boxes are identical 戻り値: 2 つのボックスが同一ならば真 Overrides: equals in class PGobject オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 Overrides: clone in class PGobject オーバライド: PGobject クラスの clone public String getValue() Returns: the PGbox in the syntax expected by postgresql 戻り値: postgresql で期待された構文で表した PGbox Overrides: getValue in class PGobject オーバライド: PGobject クラスのgetValue Class postgresql.geometric.PGcircle java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGcircle public class PGcircle extends PGobject implements Serializable, Cloneable This represents postgresql's circle datatype, consisting of a point and a radius このクラスは、postgresql の、点と半径からなる circle データ 型を表します。 Variables 変数 public PGpoint center This is the centre point 中心点です。 public double radius This is the radius 半径です。 Constructors コンストラクタ public PGcircle(double x, double y, double r) Parameters: x - coordinate of centre y - coordinate of centre r - radius of circle パラメータ: x - 中心座標 y - 中心座標 r - 円の半径 public PGcircle(PGpoint c, double r) Parameters: c - PGpoint describing the circle's centre r - radius of circle パラメータ: c - 円の中心を示す PGpoint r - 円の半径 public PGcircle(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. パラメータ: s - PostgreSQL の構文で表した円の定義 Throws: SQLException on conversion failure 例外: SQLException 変換に失敗した場合 public PGcircle() This constructor is used by the driver. ドライバによって使用されるコンストラクタ Methods メソッド public void setValue(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQL の構文で表した円の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの円が同一ならば真 (訳注: boxesをcirclesの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスの clone public String getValue() Returns: the PGcircle in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表した PGcircle オーバライド: PGobject クラスの getValue Class postgresql.geometric.PGline java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGline public class PGline extends PGobject implements Serializable, Cloneable 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. このクラスは 2 点から構成される線を実装します。今のところまだ、 線はバックエンド内で実装されていませんが、このクラスはバックエ ンドでの実装がなされればすぐに使えることを保証します。 Variables 変数 public PGpoint point[] These are the two points. 2 つの点があります。 Constructors コンストラクタ public PGline(double x1, double y1, double x2, double y2) Parameters: x1 - coordinate for first point y1 - coordinate for first point x2 - coordinate for second point y2 - coordinate for second point パラメータ: x1 - 1 番目の座標 y1 - 1 番目の座標 x2 - 2 番目の座標 y2 - 2 番目の座標 public PGline(PGpoint p1, PGpoint p2) Parameters: p1 - first point p2 - second point パラメータ: p1 - 1 番目の点 p2 - 2 番目の点 public PGline(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. Throws: SQLException on conversion failure パラメータ: s - PostgreSQLの構文で表した線の定義 (訳注: circleをlineの間違いとして訳) 例外: SQLException 変換に失敗した場合 public PGline() reuired by the driver ドライバで必要とされます。 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of the line segment in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQLの構文で表した線分の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの線が同一ならば真 (訳注: boxesをlinesの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスの clone public String getValue() Returns: the PGline in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表した PGline オーバライド: PGobject クラスの getValue Class postgresql.geometric.PGlseg java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGlseg public class PGlseg extends PGobject implements Serializable, Cloneable This implements a lseg (line segment) consisting of two points 2 つの点からなる lseg(線分)を実装します。 Variables 変数 public PGpoint point[] These are the two points. 2 つの点があります。 Constructors コンストラクタ public PGlseg(double x1, double y1, double x2, double y2) Parameters: x1 - coordinate for first point y1 - coordinate for first point x2 - coordinate for second point y2 - coordinate for second point パラメータ: x1 - 1 番目の座標 y1 - 1 番目の座標 x2 - 2 番目の座標 y2 - 2 番目の座標 public PGlseg(PGpoint p1, PGpoint p2) Parameters: p1 - first point p2 - second point パラメータ: p1 - 1 番目の点 p2 - 2 番目の点 public PGlseg(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. Throws: SQLException on conversion failure パラメータ: s - PostgreSQLの構文で表した線分の定義 (訳注: circleをline segmentの間違いとして訳) 例外: SQLException 変換に失敗した場合 public PGlseg() reuired by the driver ドライバによって必要とされます。 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of the line segment in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQLの構文で表した線分の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの線分が同一ならば真 (訳注: boxesをline segmentsの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスのclone public String getValue() Returns: the PGlseg in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表した PGlseg オーバライド: PGobject クラスの getValue Class postgresql.geometric.PGpath java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGpath public class PGpath extends PGobject implements Serializable, Cloneable This implements a path (a multiple segmented line, which may be closed) 経路(閉じている可能性がある複数の線分)を実装します。 Variables 変数 public boolean open True if the path is open, false if closed 開いた経路ならば真、閉じた経路ならば偽。 public PGpoint points[] The points defining this path この経路を定義する点。 Constructors コンストラクタ public PGpath(PGpoint points[], boolean open) Parameters: points - the PGpoints that define the path open - True if the path is open, false if closed パラメータ: points - 経路を定義するPGpoint open - 開いた経路ならば真、閉じた経路ならば偽 public PGpath() Required by the driver ドライバで必要とされます。 public PGpath(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. Throws: SQLException on conversion failure パラメータ: s - PostgreSQLの構文で表した経路の定義 (circle を path の間違いとして訳) 例外: SQLException 変換に失敗した場合 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of the path in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQLの構文で表した経路の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの経路が同一ならば真 (訳注: boxesをpathesの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスのclone public String getValue() This returns the polygon in the syntax expected by postgresql Overrides: getValue in class PGobject postgresql で期待される構文で表した経路を返します。 (polygon を path の間違いとして訳) オーバライド: PGobject クラスの getValue public boolean isOpen() This returns true if the path is open 開いた経路ならば真を返します。 public boolean isClosed() This returns true if the path is closed 閉じた経路ならば偽を返します。 public void closePath() Marks the path as closed 閉じた経路として印をつけます。 public void openPath() Marks the path as open 開いた経路として印をつけます。 Class postgresql.geometric.PGpoint java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGpoint public class PGpoint extends PGobject implements Serializable, Cloneable This implements a version of java.awt.Point, except it uses double to represent the coordinates. It maps to the point datatype in postgresql. これは、その座標を double 型で使用している点を除き、 java.awt.Point のある版を実装したものです。 postgresql の point データ型に割り当てます。 Variables 変数 public double x The X coordinate of the point 点の X 座標 public double y The Y coordinate of the point 点の Y 座標 Constructors コンストラクタ public PGpoint(double x, double y) Parameters: x - coordinate y - coordinate パラメータ: x - 座標値 y - 座標値 public PGpoint(String value) throws SQLException This is called mainly from the other geometric types, when a point is imbeded within their definition. Parameters: value - Definition of this point in PostgreSQL's syntax 主に、その定義に点を含む、他の地理的データ型から呼び出さ れます。 パラメータ: value - PostgreSQL の構文で表された点の定義 public PGpoint() Required by the driver ドライバで必要とされます。 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of this point in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQLの構文で表した点の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの点が同一ならば真 (訳注: boxesをpointsの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスのclone public String getValue() Returns: the PGpoint in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表した PGpoint オーバライド: PGobject クラスの getValue public void translate(int x, int y) Translate the point with the supplied amount. Parameters: x - integer amount to add on the x axis y - integer amount to add on the y axis 点を指定した量分移動します。 パラメータ: x - x 座標に加える整数量 y - y 座標に加える整数量 public void translate(double x, double y) Translate the point with the supplied amount. Parameters: x - double amount to add on the x axis y - double amount to add on the y axis 点を指定した量分移動します。 パラメータ: x - x 座標に加える double 型で示された量 y - y 座標に加える double 型で示された量 public void move(int x, int y) Moves the point to the supplied coordinates. Parameters: x - integer coordinate y - integer coordinate 点を指定座標に移動します。 パラメータ: x - 座標(整数) y - 座標(整数) public void move(double x, double y) Moves the point to the supplied coordinates. Parameters: x - double coordinate y - double coordinate 点を指定座標に移動します。 パラメータ: x - 座標(double 型) y - 座標(double 型) public void setLocation(int x, int y) Moves the point to the supplied coordinates. refer to java.awt.Point for description of this Parameters: x - integer coordinate y - integer coordinate See Also: Point 点を指定座標に移動します。この記述については java.awt.Point を参照して下さい。 パラメータ: x - 座標(整数) y - 座標(整数) 参照: Point public void setLocation(Point p) Moves the point to the supplied java.awt.Point refer to java.awt.Point for description of this Parameters: p - Point to move to See Also: Point 点を与えられたjava.awt.Pointに移動します。この記述につ いては java.awt.Point を参照して下さい。 パラメータ: p - 移動先を示す Point 参照: Point Class postgresql.geometric.PGpolygon java.lang.Object | +----postgresql.util.PGobject | +----postgresql.geometric.PGpolygon public class PGpolygon extends PGobject implements Serializable, Cloneable This implements the polygon datatype within PostgreSQL. PostgreSQL の polygon データ型を実装します。 Variables 変数 public PGpoint points[] The points defining the polygon 多角形を定義する点。 Constructors コンストラクタ public PGpolygon(PGpoint points[]) Creates a polygon using an array of PGpoints Parameters: points - the points defining the polygon PGpoint の配列を使用して多角形を生成します。 パラメータ: points - 多角形を定義する点 public PGpolygon(String s) throws SQLException Parameters: s - definition of the circle in PostgreSQL's syntax. Throws: SQLException on conversion failure パラメータ: s - PostgreSQL の構文で表した多角形の定義 (circle を polygon の間違いとして訳) 例外: SQLException 変換に失敗した場合 public PGpolygon() Required by the driver ドライバで必要とされます。 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of the polygon in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQLの構文で表した多角形の定義 例外: SQLException 変換に失敗した場合 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2 つの多角形が同一ならば真 (訳注: boxesをpolygonsの間違いとして訳。) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスのclone public String getValue() Returns: the PGpolygon in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表した PGpolygon オーバライド: PGobject クラスの getValue Large Objects ラージオブジェクト Large objects are supported in the standard JDBC specification. However, that interface is limited, and the api provided by PostgreSQL allows for random access to the objects contents, as if it was a local file. ラージオブジェクトは 標準 JDBC 仕様でサポートさ れています。しかし、そのインタフェースには制限があり、また、 PostgreSQL で用意される API では、ローカルファイル同様にオブジェク トの内容にランダムアクセスを行なうことができます。 The postgresql.largeobject package profides to Java the libpq C interface's large object API. It consists of two classes, LargeObjectManager, which deals with creating, opening and deleting large obejects, and LargeObject which deals with an individual object. postgresql.largeobject パッケージは Java に対し、libpq C インタフェ ースにあるラージオブジェクト API を提供します。 ラージオブジェクトの生成、オープン、削除を扱う LargeObjectManager、 及び、個別のオブジェクトを扱う LargeObject という 2 つのクラスから 構成されています。 Class postgresql.largeobject.LargeObject java.lang.Object | +----postgresql.largeobject.LargeObject public class LargeObject extends Object This class implements the large object interface to postgresql. このクラスは postgresql のラージオブジェクトインタフェースを実 装します。 It provides the basic methods required to run the interface, plus a pair of methods that provide InputStream and OutputStream classes for this object. インタフェースの実行に必要な基本的なメソッド、及び、このオブジェクト 用の InputStream と OutputStream クラスの組合せを提供するためのメソ ッドを提供します。 Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, or setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects. 通常クライアントコードでは、ラージオブジェクトにアクセスするた めに ResultSet のメソッド getAsciiStream、getBinaryStream、ま たは getUnicodeStream、もしくは PreparedStatement のメソッド setAsciiStream、setBinaryStream、または setUnicodeStream を使 用します。 However, sometimes lower level access to Large Objects are required, that are not supported by the JDBC specification. しかし、もっと低レベルなラージオブジェクトへのアクセスが必要 となることがあります。これは JDBC 仕様では サポートされていません。 Refer to postgresql.largeobject.LargeObjectManager on how to gain access to a Large Object, or how to create one. どのようにラージオブジェクトへのアクセスを得るかやどうやって生成 するかについては postgresql.largeobject.LargeObjectManager を参照 して下さい。 See Also: 参照: LargeObjectManager Variables 変数 public static final int SEEK_SET Indicates a seek from the begining of a file ファイルの先頭からシークすることを示します。 public static final int SEEK_CUR Indicates a seek from the current position 現在位置からシークすることを示します。 public static final int SEEK_END Indicates a seek from the end of a file ファイルの終端からシークすることを示します。 Methods メソッド public int getOID() Returns: the OID of this LargeObject 戻り値: ラージオブジェクトの OID public void close() throws SQLException This method closes the object. You must not call methods in this object after this is called. Throws: SQLException if a database-access error occurs. オブジェクトを閉じます。このメソッドを呼び出した後にそ のオブジェクトのメソッドを呼び出してはいけません。 例外: SQLException データベースアクセスエラーが発生した場合 public byte[] read(int len) throws SQLException Reads some data from the object, and return as a byte[] array Parameters: len - number of bytes to read Returns: byte[] array containing data read Throws: SQLException if a database-access error occurs. オブジェクトからデータを一部読みとり、byte[] 型の配 列として返します。 パラメータ: len - 読みとるバイト数 戻り値: 読みとったデータを持つ byte[] 型の配列 例外: SQLException データベースアクセスエラーが発生した場合 public void read(byte buf[], int off, int len) throws SQLException Reads some data from the object into an existing array Parameters: buf - destination array off - offset within array len - number of bytes to read Throws: SQLException if a database-access error occurs. オブジェクトからデータの一部分を既存の配列に読み込 みます。 パラメータ: buf - コピー先の配列 off - 配列内のオフセット len - 読みとるバイト数 例外: SQLException データベースアクセスエラーが発生した場合 public void write(byte buf[]) throws SQLException Writes an array to the object Parameters: buf - array to write Throws: SQLException if a database-access error occurs. 配列をオブジェクトに書き込む パラメータ: buf - 書き込む配列 例外: SQLException データベースアクセスエラーが発生した場合 public void write(byte buf[], int off, int len) throws SQLException Writes some data from an array to the object Parameters: buf - destination array off - offset within array len - number of bytes to write Throws: SQLException if a database-access error occurs. 配列の一部のデータをオブジェクトに書き込む。 パラメータ: buf - コピー元となる配列 off - 配列内のオフセット len - 書き込むバイト数 例外: SQLException データベースアクセスエラーが発生した場合 public void seek(int pos, int ref) throws SQLException Sets the current position within the object. This is similar to the fseek() call in the standard C library.It allows you to have random access to the large object. Parameters: pos - position within object ref - Either SEEK_SET, SEEK_CUR or SEEK_END Throws: SQLException if a database-access error occurs. オブジェクト内の現在位置を設定します。 標準 C ライブラリの fseek() 呼び出しに似ています。ラー ジオブジェクトへのランダムアクセスが可能になります。 パラメータ: pos - オブジェクト内の位置 ref - SEEK_SET、SEEK_CUR、SEEK_ENDの内の一つ 例外: SQLException データベースアクセスエラーが発生した場合 public void seek(int pos) throws SQLException Sets the current position within the object. This is similar to the fseek() call in the standard C library.It allows you to have random access to the large object. Parameters: pos - position within object from begining Throws: SQLException if a database-access error occurs. オブジェクト内の現在位置を設定します。 標準 C ライブラリの fseek() 呼び出しに似ています。ラー ジオブジェクトへのランダムアクセスが可能になります。 パラメータ: pos - オブジェクト内の先頭からの位置 例外: SQLException データベースアクセスエラーが発生した場合 public int tell() throws SQLException Returns: the current position within the object Throws: SQLException if a database-access error occurs. 戻り値: オブジェクト内の現在位置 例外: SQLException データベースアクセスエラーが発生した場合 public int size() throws SQLException This method is inefficient, as the only way to find out the size of the object is to seek to the end, record the current position, then return to the original position. A better method will be found in the future. Returns: the size of the large object Throws: SQLException if a database-access error occurs. このメソッドは役に立ちません。ですので、オブジェクトの大き さを探す唯一の方法は終端までシークし、現在位置を記録し、そ して元の位置に戻すことです。 今後より良いメソッドができます。 戻り値: ラージオブジェクトの大きさ 例外: SQLException データベースアクセスエラーが発生した場合 public InputStream getInputStream() throws SQLException Returns an InputStream from this object. This InputStream can then be used in any method that requires an InputStream. Throws: SQLException if a database-access error occurs. このオブジェクトからの InputStream を返します。 この InputStream インスタンスは、この後に InputStream を 必要とする任意のメソッドに使うことができます 例外: SQLException データベースアクセスエラーが発生した場合 public OutputStream getOutputStream() throws SQLException Returns an OutputStream to this object This OutputStream can then be used in any method that requires an OutputStream. Throws: SQLException if a database-access error occurs. このオブジェクトへの OutputStream を返します。 この OutputStream インスタンスは、この後に OutputStream を 必要とする任意のメソッドに使うことができます 例外: SQLException データベースアクセスエラーが発生した場合 Class postgresql.largeobject.LargeObjectManager java.lang.Object | +----postgresql.largeobject.LargeObjectManager public class LargeObjectManager extends Object This class implements the large object interface to postgresql. このクラスは postgresql のラージオブジェクトインタフェースを実 装します。 It provides methods that allow client code to create, open and delete large objects from the database. When opening an object, an instance of postgresql.largeobject.LargeObject is returned, and its methods then allow access to the object. クライアントコードにて、ラージオブジェクトの生成、オープン、削除を 可能にするためのメソッドを提供します。オブジェクトを開くと、 postgresql.largeobject.LargeObject のインスタンスが返され、そのイン スタンスのメソッドを使ってラージオブジェクトにアクセスできます。 This class can only be created by postgresql.Connection このクラスは postgresql.Connection によってのみ作成できます。 To get access to this class, use the following segment of code: このクラスへのアクセスを得るには、次のようなコードの一部を使用します。 import postgresql.largeobject.*; Connection conn; LargeObjectManager lobj; ... code that opens a connection ... lobj = ((postgresql.Connection)myconn).getLargeObjectAPI(); Normally, client code would use the getAsciiStream, getBinaryStream, or getUnicodeStream methods in ResultSet, or setAsciiStream, setBinaryStream, or setUnicodeStream methods in PreparedStatement to access Large Objects. 通常クライアントコードでは、ラージオブジェクトにアクセスするた めに ResultSet のメソッド getAsciiStream、getBinaryStream、ま たは getUnicodeStream、もしくは PreparedStatement のメソッド setAsciiStream、setBinaryStream、または setUnicodeStream を使 用します。 However, sometimes lower level access to Large Objects are required, that are not supported by the JDBC specification. しかし、もっと低レベルなラージオブジェクトへのアクセスが必要 となることがあります。これは JDBC 仕様では サポートされていません。 Refer to postgresql.largeobject.LargeObject on how to manipulate the contents of a Large Object. どのようにラージオブジェクトの内容を扱うのかについては、 postgresql.largeobject.LargeObject を参照して下さい。 See Also: 参照: LargeObject Variables 変数 public static final int WRITE This mode indicates we want to write to an object このモードはオブジェクトに書き込みを行なう予定であるこ とを示します。 public static final int READ This mode indicates we want to read an object このモードはオブジェクトに読み取りを行なう予定であるこ とを示します。 public static final int READWRITE This mode is the default. It indicates we want read and write access to a large object このモードがデフォルトです。オブジェクトに読み取り、及び、 書き込みを行なう予定であることを示します。 Methods public LargeObject open(int oid) throws SQLException This opens an existing large object, based on its OID. This method assumes that READ and WRITE access is required (the default). Parameters: oid - of large object Returns: LargeObject instance providing access to the object Throws: SQLException on error 既存のラージオブジェクトを、その OID に基づいて開きます。 このメソッドは (デフォルトである)READ と WRITE アクセ スが要求されているものと仮定します。 パラメータ: oid - ラージオブジェクトの oid 戻り値: そのオブジェクトへのアクセスを提供する LargeObject インスタンス 例外: SQLException エラー時 public LargeObject open(int oid, int mode) throws SQLException This opens an existing large object, based on its OID Parameters: oid - of large object mode - mode of open Returns: LargeObject instance providing access to the object Throws: SQLException on error 既存のラージオブジェクトを、その OID に基づいて開きます。 パラメータ: oid - ラージオブジェクトの oid mode - オープンモード 戻り値: そのオブジェクトへのアクセスを提供する LargeObject インスタンス 例外: SQLException エラー時 public int create() throws SQLException This creates a large object, returning its OID. It defaults to READWRITE for the new object's attributes. Returns: oid of new object Throws: SQLException on error ラージオブジェクトを作成し、その OID を返します。 新しいオブジェクトの属性のデフォルトは READWRITE です。 戻り値: 新しいオブジェクトの oid Throws: SQLException エラー時 public int create(int mode) throws SQLException This creates a large object, returning its OID Parameters: mode - a bitmask describing different attributes of the new object Returns: oid of new object Throws: SQLException on error ラージオブジェクトを作成し、その OID を返します。 パラメータ: mode - 新しいオブジェクトの異なった属性を示すビットマスク 戻り値: 新しいオブジェクトの oid 例外: SQLException エラー時 public void delete(int oid) throws SQLException This deletes a large object. Parameters: oid - describing object to delete Throws: SQLException on error ラージオブジェクトを削除します。 パラメータ: oid - 削除するオブジェクトを示す oid 例外: SQLException エラー時 public void unlink(int oid) throws SQLException This deletes a large object. It is identical to the delete method, and is supplied as the C API uses unlink. Parameters: oid - describing object to delete Throws: SQLException on error ラージオブジェクトを削除します。delete メソッドと同一です。こ れは C API 同様に unlink を使用するために用 意されています。 Object Serialisation オブジェクト直列化 PostgreSQL is not a normal SQL Database. It is far more extensible than most other databases, and does support Object Oriented features that are unique to it. PostgreSQL はごく普通の SQL データベースではありません。他のほと んどのデータベースよりもかなり拡張性があり、特有のオブジェクト指 向機能をサポートしています。 One of the consequences of this, is that you can have one table refer to a row in another table. For example: 他のテーブルにある行を参照するテーブルを持つことができるということはこ の結果の1つです。例えば、 test=> create table users (username name,fullname text); CREATE test=> create table server (servername name,adminuser users); CREATE test=> insert into users values ('peter','Peter Mount'); INSERT 2610132 1 test=> insert into server values ('maidast',2610132::users); INSERT 2610133 1 test=> select * from users; username|fullname --------+-------------- peter |Peter Mount (1 row) test=> select * from server; servername|adminuser ----------+--------- maidast | 2610132 (1 row) Ok, the above example shows that we can use a table name as a field, and the row's oid value is stored in that field. わかりますか。上の例では、テーブルの名前をフィールドとして持つことが でき、行の oid がそのフィールドに埋め込まれていることを示しています。 What does this have to do with Java? Java ではこれをどう扱わなければならないでしょうか? In Java, you can store an object to a Stream as long as it's class implements the java.io.Serializable interface. This process, known as Object Serialization, can be used to store complex objects into the database. Java では java.io.Serializable インタフェースを実装するクラスならば ストリームにオブジェクトを保存することができます。オブジェクト直列化 として知られるこの処理は、複雑なオブジェクトをデータベースに保存する ことに使用することができます。 Now, under JDBC, you would have to use a LargeObject to store them. However, you cannot perform queries on those objects. さて、JDBC では、それらを保存する際に LargeObject を使用しなければなりません。しかし、これらのオブジェクトに問い合わせ を行なうことができません。 What the postgresql.util.Serialize class does, is provide a means of storing an object as a table, and to retrieve that object from a table. In most cases, you would not need to access this class direct, but you would use the PreparedStatement.setObject() and ResultSet.getObject() methods. Those methods will check the objects class name against the table's in the database. If a match is found, it assumes that the object is a Serialized object, and retrieves it from that table. As it does so, if the object contains other serialized objects, then it recurses down the tree. postgresql.util.Serialize クラスが行なうことは、オブジェクトをテーブ ルとして保存する手段、及び、テーブルからオブジェクトを取り出す手段を 提供することです。ほとんどの場合では、このクラスを直接アクセスする必 要はなく、PreparedStatement.setObject() と ResultSet.getObject() メ ソッドを使うことになります。これらのメソッドはオブジェクトのクラス名 をデータベース内のテーブル名で照合します。合うものがあれば、そのオブ ジェクトは直列化されたオブジェクトとみなし、そのテーブルから取り出し ます。その処理の際にそのオブジェクトが直列化された別のオブジェクトを 持つ場合、再帰的にそのツリーを辿ります。 Sound's complicated? In fact, it's simpler than what I wrote - it's just difficult to explain. 複雑に見えますか?実際は、私が述べたことよりは簡単です。説明すること が難しいだけです。 The only time you would access this class, is to use the create() methods. These are not used by the driver, but issue one or more "create table" statements to the database, based on a Java Object or Class that you want to serialize. このクラスにアクセスする機会は、create() メソッド群を使用する時だけ です。これらはドライバから使用されるものではありませんが、直列化要 求のあった Java のオブジェクトやクラスに基づいた 1 つ以上の "create table" 文をデータベースに対して発行します。 Oh, one last thing. If your object contains a line like: public int oid; then, when the object is retrieved from the table, it is set to the oid within the table. Then, if the object is modified, and re- serialized, the existing entry is updated. さて、これが最後ですが、もし対象とするオブジェクトが、 public int oid; という行を含むのならば、テーブルからオブジェクトを取り出す際に、そ こにテーブル内の oid が設定されます。そして、オブジェクトが変更され、 再度直列化されると、既存のエントリは更新されます。 If the oid variable is not present, then when the object is serialized, it is always inserted into the table, and any existing entry in the table is preserved. oid 変数がなければ、オブジェクトが直列化された時に常に挿入され、そ して、テーブルに既存のエントリは全て保存されます。 Setting oid to 0 before serialization, will also cause the object to be inserted. This enables an object to be duplicated in the database. 直列化前に oid 変数を 0 にすると、そのオブジェクトは挿入されるように なります。これにより、あるオブジェクトをデータベース内に複数持たせる ことができます。 Class postgresql.util.Serialize java.lang.Object | +----postgresql.util.Serialize public class Serialize extends Object This class uses PostgreSQL's object oriented features to store Java Objects. It does this by mapping a Java Class name to a table in the database. Each entry in this new table then represents a Serialized instance of this class. As each entry has an OID (Object IDentifier), this OID can be included in another table. This is too complex to show here, and will be documented in the main documents in more detail. このクラスは、Java のオブジェクトを保存するために PostgreSQL のオブ ジェクト指向機能を使用します。このクラスでは、Java のクラス名をデー タベース内のテーブルに対応させることでそれを行ないます。この新しい テーブル各エントリはこのクラスの直列化されたインスタンスを表します。 各エントリは OID(オブジェクト識別子)を持ちますので、この OID を別 のテーブルに持たせることができます。このクラスはここで示すには複雑 過ぎますので、より詳細については主文書にて記載させる予定です。 Constructors コンストラクタ public Serialize(Connection c, String type) throws SQLException This creates an instance that can be used to serialize ordeserialize a Java object from a PostgreSQL table. このメソッドは、PostgreSQL のテーブルからある Java オブ ジェクトを直列化または復号化するために使用できる、インス タンスを生成します。 Methods メソッド public Object fetch(int oid) throws SQLException This fetches an object from a table, given it's OID Parameters: oid - The oid of the object Returns: Object relating to oid Throws: SQLException on error 指定した OID のオブジェクトをテーブルから入手します。 パラメータ: oid - オブジェクトの oid 戻り値: oid に対応するオブジェクト 例外: SQLException エラー時 public int store(Object o) throws SQLException This stores an object into a table, returning it's OID. If the object has an int called OID, and it is > 0, then that value is used for the OID, and the table will be updated. If the value of OID is 0, then a new row will be created, and the value of OID will be set in the object. This enables an object's value in the database to be updateable. If the object has no int called OID, then the object is stored. However if the object is later retrieved, amended and stored again, it's new state will be appended to the table, and will not overwrite the old entries. テーブルにオブジェクトを保存し、その OID を返します。 そのオブジェクトが OID という名前の整数型変数をもち、それ が 0 より大きい場合、その値が OID として使われ、テーブルは 更新されます。OID 変数が 0 ならば、新しい行が作成され、行の OID がそのオブジェクトに設定されます。これにより、データベー ス内のオブジェクトの値が更新可能になります。オブジェクトが OID という整数型変数を持たない場合、オブジェクトは保存されま す。が、その後にそのオブジェクトを取り出し、修正し、再度保存 した場合に、その新しい状態はテーブルに追加され、古いエントリ を上書きしません。 Parameters: o - Object to store (must implement Serializable) Returns: oid of stored object Throws: SQLException on error パラメータ: o - 保存するオブジェクト(Serializable を実装する必 要があります) 戻り値: 保存したオブジェクトの oid 例外: SQLException エラー時 public static void create(Connection con, Object o) throws SQLException This method is not used by the driver, but it creates a table, given a Serializable Java Object. It should be used before serializing any objects. このメソッドはドライバで使われませんが、Serializable を実 装した指定 Java オブジェクトに対応するテーブルを作成します。 オブジェクトの直列化を行なう前に使用しなければなりません。 Parameters: c - Connection to database o - Object to base table on Throws: SQLException on error Returns: Object relating to oid Throws: SQLException on error パラメータ: c - データベースへの Connection オブジェクト o - テーブルに基づくオブジェクト Throws: SQLException エラー時 Returns: oidに対応したオブジェクト (訳注: 間違いです。シグネチャでは void です。) Throws: SQLException エラー時 public int store(Object o) throws SQLException (訳注: 前述されています。) This stores an object into a table, returning it's OID. If the object has an int called OID, and it is > 0, then that value is used for the OID, and the table will be updated. If the value of OID is 0, then a new row will be created, and the value of OID will be set in the object. This enables an object's value in the database to be updateable. If the object has no int called OID, then the object is stored. However if the object is later retrieved, amended and stored again, it's new state will be appended to the table, and will not overwrite the old entries. オブジェクトをテーブルに保存し、その OID を返します。 そのオブジェクトが OID という名前の整数型変数をもち、それ が 0 より大きい場合、その値が OID として使われ、テーブルは 更新されます。OID 変数が 0 ならば、新しい行が作成され、行の OID がそのオブジェクトに設定されます。これにより、データベー ス内のオブジェクトの値が更新可能になります。オブジェクトが OID という整数型変数を持たない場合、オブジェクトは保存されま す。が、その後にそのオブジェクトを取り出し、修正し、再度保存 した場合に、その新しい状態はテーブルに追加され、古いエントリ を上書きしません。 Parameters: o - Object to store (must implement Serializable) Returns: oid of stored object Throws: SQLException on error パラメータ: o - 保存するオブジェクト(Serializable を実装する必 要があります) 戻り値: 保存したオブジェクトの oid 例外: SQLException エラー時 public static void create(Connection con, Object o) throws SQLException (このメソッドも前述されています。) This method is not used by the driver, but it creates a table, given a Serializable Java Object. It should be used before serializing any objects. このメソッドはドライバで使われませんが、Serializable を実 装した指定 Java オブジェクトに対応するテーブルを作成します。 オブジェクトの直列化を行なう前に使用しなければなりません。 Parameters: c - Connection to database o - Object to base table on Throws: SQLException on error パラメータ: c - データベースへの Connection オブジェクト o - テーブルに基づくオブジェクト 例外: SQLException エラー時 public static void create(Connection con, Class c) throws SQLException (このメソッドも前述されています。) This method is not used by the driver, but it creates a table, given a Serializable Java Object. It should be used before serializing any objects. このメソッドはドライバで使われませんが、Serializable を実 装した指定 Java オブジェクトに対応するテーブルを作成します。 オブジェクトの直列化を行なう前に使用しなければなりません。 Parameters: c - Connection to database o - Class to base table on Throws: SQLException on error パラメータ: c - データベースへの Connection オブジェクト o - テーブルに基づくオブジェクト 例外: SQLException エラー時 public static String toPostgreSQL(String name) throws SQLException This converts a Java Class name to a postgresql table, by replacing . with _ Because of this, a Class name may not have _ in the name. Another limitation, is that the entire class name (including packages) cannot be longer than 31 characters (a limit forced by PostgreSQL). Java のクラス名を「 . 」を「 _ 」に置換してpostgresql テー ブルに変換します。 この理由は、クラス名は「 _ 」を持つことができないからです。 他の制限として、(パッケージを含めた)完全なクラス名は 31 文字を越えられないことがあります。(これは PostgreSQL によ る制限です。) Parameters: name - Class name Returns: PostgreSQL table name Throws: SQLException on error パラメータ: name - クラス名 戻り値: PostgreSQL のテーブル名 例外: SQLException エラー時 public static String toClassName(String name) throws SQLException This converts a postgresql table to a Java Class name, by replacing _ with . Parameters: name - PostgreSQL table name Returns: Class name Throws: SQLException on error postgresql のテーブルを「 _ 」を「 . 」に置換して Java の クラス名に変換します。 パラメータ: name - PostgreSQL テーブル名 戻り値: クラス名 例外: SQLException エラー時 Utility Classes ユーティリティクラス The postgresql.util package contains classes used by the internals of the main driver, and the other extensions. postgresql.util パッケージには主ドライバやその他の拡張機能の内部で使 用されるクラスがあります。 Class postgresql.util.PGmoney java.lang.Object | +----postgresql.util.PGobject | +----postgresql.util.PGmoney public class PGmoney extends PGobject implements Serializable, Cloneable This implements a class that handles the PostgreSQL money type PostgreSQL のmoney 型を取り扱うクラスを実装したものです。 Variables 変数 public double val The value of the field フィールドの値。 Constructors コンストラクタ public PGmoney(double value) Parameters: value - of field パラメータ: value - フィールドの値 public PGmoney(String value) throws SQLException This is called mainly from the other geometric types, when a point is imbeded within their definition. Parameters: value - Definition of this point in PostgreSQL's syntax 主に、その定義にpoint型を持っている他の地理的データ型から呼 び出されます。 (訳注: 間違いと思われます。PGpoint(String value)の説明が書 いてあります。) public PGmoney() Required by the driver ドライバで必要とされます。 Methods メソッド public void setValue(String s) throws SQLException Parameters: s - Definition of this point in PostgreSQL's syntax Throws: SQLException on conversion failure Overrides: setValue in class PGobject パラメータ: s - PostgreSQL 構文によるこの金額の定義 (訳注: pointはmoneyの間違いとして訳) 例外: SQLException 変換失敗時 オーバライド: PGobject クラスの setValue public boolean equals(Object obj) Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class PGobject パラメータ: obj - 比較するオブジェクト 戻り値: 2つの金額が同一ならば真 (訳注: boxesはmoneysの間違いとして訳) オーバライド: PGobject クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class PGobject このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: PGobject クラスのclone public String getValue() Returns: the PGpoint in the syntax expected by postgresql Overrides: getValue in class PGobject 戻り値: postgresql で期待される構文で表したPGmoney (訳注: PGpoint を PGmoney の間違いとして訳) オーバライド: PGobject クラスの getValue Class postgresql.util.PGobject java.lang.Object | +----postgresql.util.PGobject public class PGobject extends Object implements Serializable, Cloneable This class is used to describe data types that are unknown by JDBC Standard. A call to postgresql.Connection permits a class that extends this class to be associated with a named type. This is how the postgresql.geometric package operates. ResultSet.getObject() will return this class for any type that is not recognised on having it's own handler. Because of this, any postgresql data type is supported. このクラスは JDBC の標準では未知のデータ型を記 述するために使用されます。 postgresql.Connection への呼び出しでは、指定した型に関連付けられた、 このクラスを継承したクラスを使用することができます。 ResultSet.getObject() はそのハンドラを使って認識できなかった型の場 合、全てこのクラスを返します。これにより任意の postgresql のデータ 型がサポートされます。 Constructors コンストラクタ public PGobject() This is called by postgresql.Connection.getObject() to create the object. オブジェクトを作成する時に postgresql.Connection.getObject() から呼び出されます。 Methods メソッド public final void setType(String type) This method sets the type of this object. It should not be extended by subclasses, hence its final このメソッドはこのオブジェクトの型を設定します。 サブクラスで継承されてはなりませんので、final メソッドで す。 Parameters: type - a string describing the type of the object パラメータ: type - オブジェクトの型を示す文字列 public void setValue(String value) throws SQLException This method sets the value of this object. It must be overidden. このオブジェクトに値を設定します。オーバライドされな ければなりません。 Parameters: value - a string representation of the value of the object Throws: SQLException thrown if value is invalid for this type パラメータ: value - そのオブジェクトの値の文字列表現 例外: SQLException 値がこの型で無効だった場合 public final String getType() As this cannot change during the life of the object, it's final. このオブジェクトが有効である間に変更することができないよう に、final とします。 Returns: the type name of this object 戻り値: このオブジェクトの型名 public String getValue() This must be overidden, to return the value of the object, in the form required by postgresql. オブジェクトの値をpostgresqlで要求された形式で返すために、 これはオーバライドされなければなりません。 Returns: the value of this object 戻り値: オブジェクトの値 public boolean equals(Object obj) This must be overidden to allow comparisons of objects Parameters: obj - Object to compare with Returns: true if the two boxes are identical Overrides: equals in class Object オブジェクトの比較ができるように、オーバライドされなけれ ばなりません。 パラメータ: obj - 比較するオブジェクト 戻り値: 2つのオブジェクトが同一ならば真 (訳注: boxesはobjectsの間違いとして訳) オーバライド: Object クラスの equals public Object clone() This must be overidden to allow the object to be cloned Overrides: clone in class Object このメソッドはオブジェクトの複製を可能にするためにオーバ ライドする必要があります。 オーバライド: Object クラスの clone public String toString() This is defined here, so user code need not overide it. Returns: the value of this object, in the syntax expected by postgresql Overrides: toString in class Object ここで定義されています。ユーザのコードでオーバライドする 必要はありません。 戻り値: postgresql で期待される構文を使ったこのオブジェクトの値。 オーバライド: Object クラスの toString Class postgresql.util.PGtokenizer java.lang.Object | +----postgresql.util.PGtokenizer public class PGtokenizer extends Object This class is used to tokenize the text output of postgres. We could have used StringTokenizer to do this, however, we needed to handle nesting of '(' ')' '[' ']' '<' and '>' as these are used by the geometric data types. It's mainly used by the geometric classes, but is useful in parsing any output from custom data types output from postgresql. See Also: PGbox, PGcircle, PGlseg, PGpath, PGpoint, PGpolygon このクラスはpostgresのテキスト出力のトークン化に使用されます。 以前はStringTokenizer を使用していましたが、地理的データ型で使 用される、入れ子状の '(' ')' '[' ']' '<' 及び '>' を扱う必要が ありました。 主に地理的クラスにて使用されますが、postgresql から生成されるど のようなカスタムデータ型の出力の解析にも使用できます。 Constructors コンストラクタ public PGtokenizer(String string, char delim) Create a tokeniser. Parameters: string - containing tokens delim - single character to split the tokens トークン化機構を生成します。 パラメータ: string - トークン化する文字列 delim - トークンをわける 1 つの文字 Methods メソッド public int tokenize(String string, char delim) This resets this tokenizer with a new string and/or delimiter. Parameters: string - containing tokens delim - single character to split the tokens 新しい文字列と区切り文字でトークン化機構をリセット します。 パラメータ: string - トークン化する文字列 delim - トークンをわける 1 つの文字 public int getSize() Returns: the number of tokens available 戻り値: 利用可能なトークン数 public String getToken(int n) Parameters: n - Token number ( 0 ... getSize()-1 ) Returns: The token value パラメータ: n - トークン番号 ( 0 ... getSize()-1 ) 戻り値: トークンの値 public PGtokenizer tokenizeToken(int n, char delim) This returns a new tokenizer based on one of our tokens. The geometric datatypes use this to process nested tokens (usually PGpoint). Parameters: n - Token number ( 0 ... getSize()-1 ) delim - The delimiter to use Returns: A new instance of PGtokenizer based on the token トークンの1つに基づく新しいトークン化機構を返します。地理的データ型(通常は PGpoint )はこれを使用して入れ子状のトークンを処理します。 パラメータ: n - トークン番号 ( 0 ... getSize()-1 ) delim - 使用する区切り文字 戻り値: トークンに基づく新しいPGtokenizer インスタンス public static String remove(String s, String l, String t) This removes the lead/trailing strings from a string Parameters: s - Source string l - Leading string to remove t - Trailing string to remove Returns: String without the lead/trailing strings 文字列の前/後ろの文字列を削除します。 パラメータ: s - 元となる文字列 l - 前から削除する文字列 t - 後ろから削除する文字列 文字列: 前/後ろの文字列を削除した文字列 public void remove(String l, String t) This removes the lead/trailing strings from all tokens Parameters: l - Leading string to remove t - Trailing string to remove 全てのトークンから前/後ろの文字列を削除します。 パラメータ: l - 前から削除する文字列 t - 後ろから削除する文字列 public static String removePara(String s) Removes ( and ) from the beginning and end of a string Parameters: s - String to remove from Returns: String without the ( or ) 文字列の始めと終りにある ( と ) を削除します。 パラメータ: s - 削除対象文字列 戻り値: ( と ) を削除した文字列 public void removePara() Removes ( and ) from the beginning and end of all tokens Returns: String without the ( or ) 全てのトークンの始めと終りにある ( と ) を削除します。 戻り値: ( と ) を削除した文字列 (訳注: シグネチャは void です。) public static String removeBox(String s) Removes [ and ] from the beginning and end of a string Parameters: s - String to remove from Returns: String without the [ or ] 文字列の始めと終りにある [ と ] を削除します。 パラメータ: s - 削除対象文字列 戻り値: [ と ] を削除した文字列 public void removeBox() Removes [ and ] from the beginning and end of all tokens Returns: String without the [ or ] 全てのトークンの始めと終りにある [ と ] を削除します。 戻り値: [ と ] を削除した文字列 (訳注: 間違いです。シグネチャは void です。) public static String removeAngle(String s) Removes < and > from the beginning and end of a string Parameters: s - String to remove from Returns: String without the < or > 文字列の始めと終りにある < と > を削除します。 パラメータ: s - 削除対象文字列 戻り値: < と > を削除した文字列 public void removeAngle() Removes < and > from the beginning and end of all tokens Returns: String without the < or > 全てのトークンの始めと終りにある < と > を削除します。 戻り値: < と > を削除した文字列 (訳注: シグネチャは void です。) Class postgresql.util.Serialize This was documented earlier under Object Serialisation. このクラスは上のオブジェクト直列化の節にて説明されました。 Class postgresql.util.UnixCrypt java.lang.Object | +----postgresql.util.UnixCrypt public class UnixCrypt extends Object This class provides us with the ability to encrypt passwords when sent over the network stream Contains static methods to encrypt and compare passwords with Unix encrypted passwords. See John Dumas's Java Crypt page for the original source. http://www.zeh.com/local/jfd/crypt.html このクラスはネットワークに暗号化パスワードを送信する能力を提供し ます。 暗号化、及び Unix の暗号化パスワードと比較する静的メソッドを持ち ます。 元となったソースについては、次の John Dumas 氏の Java 暗号ページ を参照して下さい。 http://www.zeh.com/local/jfd/crypt.html Methods メソッド public static final String crypt(String salt, String original) Encrypt a password given the cleartext password and a "salt". Parameters: salt - A two-character string representing the salt used to iterate the encryption engine in lots of different ways. If you are generating a new encryption then this value should be randomised. original - The password to be encrypted. Returns: A string consisting of the 2-character salt followed by the encrypted password. 指定された平文パスワードと "ソルト" でパスワードを暗号化します。 パラメータ: salt - 暗号化エンジンを多くの異なった方法で繰り返させ るために使用するソルトを表した 2 文字の文字列。新 しく暗号を生成したい場合は、この値を乱数化しな ければなりません。 original - 暗号化対象のパスワード 戻り値: 2 文字のソルトとそれに続く暗号化パスワードからなる 文字列 public static final String crypt(String original) Encrypt a password given the cleartext password. This method generates a random salt using the 'java.util.Random' class. Parameters: original - The password to be encrypted. Returns: A string consisting of the 2-character salt followed by the encrypted password. 指定平文パスワードを暗号化します。このメソッドは 'java.util.Random' クラスを使用して乱数化されたソルトを 生成します。 パラメータ: original - 暗号化対象パスワード 戻り値: 2 文字のソルトとそれに続く暗号化パスワードからなる 文字列 public static final boolean matches(String encryptedPassword, String enteredPassword) Check that enteredPassword encrypts to encryptedPassword. Parameters: encryptedPassword - The encryptedPassword. The first two characters are assumed to be the salt. This string would be the same as one found in a Unix /etc/passwd file. enteredPassword - The password as entered by the user (or otherwise aquired). Returns: true if the password should be considered correct. 引数 enteredPasswordを暗号化し、引数 encryptedPassword と 照合します。 パラメータ: encryptedPassword - 暗号化されたパスワード。最初の 2 文字はソルトと仮定されます。この文字列は Unix の /etc/passwd ファイルにあるものと同一のものです。 enteredPassword - ユーザが入力した(または別の方法 で入手した)パスワード 戻り値: パスワードが正しいとみなされた場合、真 Using the driver in a multi Threaded or Servlet environment 複数のスレッド、サーブレット環境におけるドライバの使用 A problem with many JDBC drivers, is that only one thread can use a Connection at any one time - otherwise a thread could send a query while another one is receiving results, and this would be a bad thing for the database engine. 多くの JDBC ドライバでは、ある時点でたった 1 つ のスレッドだけが Connection オブジェクトを使用できるという問題があ ります。あるスレッドが結果を受け取っている時に別のスレッドが問い合 わせを送る場合は別です。このことはデータベースエンジンにとって有害 です。 PostgreSQL 6.4, brings thread safety to the entire driver. Standard JDBC was thread safe in 6.3.x, but the Fastpath API wasn't. PostgreSQL 6.4 で、ドライバ全体をスレッドセーフにしました。標準 JDBC は 6.3.x の段階でスレッドセーフでしたが、 Fastpath API はそうではありませんでした。 So, if your application uses multiple threads (which most decent ones would), then you don't have to worry about complex schemes to ensure only one uses the database at any time. ですので、アプリケーションで複数のスレッドを使用する(ほとんどのまと もなアプリケーションでそうするでしょう)場合、同時にデータベースを使 用するスレッドがないことを確実にするための複雑な仕組みを考える必要が ありません。 If a thread attempts to use the connection while another is using it, it will wait until the other thread has finished it's current operation. スレッドが別のスレッドが使用している時に接続を使用しようとすると、他 のスレッドが完了するまでその操作は待たされます。 If it's a standard SQL statement, then the operation is sending the statement, and retrieving any ResultSet (in full). 標準 SQL 文の場合、操作とは文を送信し、何らかの ResultSet を(完全に) 受け取ることです。 If it's a Fastpath call (ie: reading a block from a LargeObject), then it's the time to send, and retrieve that block. Fastpath 呼び出し(つまり LargeObject からブロックを読むこと)の場合、 それはブロックを送信する、または、受け取る瞬間です。 This is fine for applications & applets, but can cause a performance problem with servlets. これはアプリケーションやアプレットでは優れていますが、サーブレットの 場合は性能に関する問題を発生させます。 With servlets, you can have a heavy load on the connection. If you have several threads performing queries, then each one will pause, which may not be what you are after. サーブレットでは、その接続に重い負荷をかけることができます。問い合わ せを行なう複数のスレッドがある場合、それぞれは待たされ、そして、それ がその次に行なわれるとは限りません To solve this, you would be advised to create a pool of Connections. これを解消するために、Connection オブジェクトのプールを作成すること を勧めます。 When ever a thread needs to use the database, it asks a manager class for a Connection. It hands a free connection to the thread, and marks it as busy. If a free connection is not available, it opens one. あるスレッドがデータベースへの接続を必要とした時には常に、 Connection オブジェクトを管理するクラスに尋ねます。管理クラスは空きの 接続をそのスレッドに渡し、その接続に使用中と印をつけます。空き接続が なければ、接続を開きます。 Once the thread has finished with it, it returns it to the manager, who can then either close it, or add it to the pool. The manager would also check that the connection is still alive, and remove it from the pool if it's dead. スレッドが処理を終えた段階で、管理クラスに返却します。管理クラスはその 接続を閉じることも、また、プールに追加することもできます。また、管理ク ラスは接続が現在も有効かどうか点検し、もし無効であればそれをプールから 削除します。 So, with servlets, it's up to you to use either a single connection, or a pool. The plus side for a pool is that threads will not be hit by the bottle neck caused by a single network connection. The down side, is that it increases the load on the server, as a backend is created for each Connection. ですので、サーブレットでは、1 つの接続を使用するかプールを使用するかは 設計者に依存します。プールの場合の利点は、そのスレッドが 1 つのネット ワーク接続が原因となるボトルネックの影響を受けないことです。欠点は、バ ックエンドプロセスが各接続用に生成されますので、サーバの負荷が増大する ことです。 It's up to you, and your applications requirements. 設計者、そしてそのアプリケーションの要求仕様に依存します。