提交 86fba974 authored 作者: Thomas Mueller's avatar Thomas Mueller

Cleanup.

上级 a75bf79a
......@@ -543,7 +543,7 @@ public class JdbcStatement extends TraceObject implements Statement {
/**
* Check whether the statement was cancelled.
*
*
* @return true if yes
*/
public boolean wasCancelled() {
......
......@@ -262,7 +262,8 @@ public class PgServer implements Service {
/**
* Get the thread with the given process id.
*
*
* @param processId the process id
* @return the thread
*/
PgServerThread getThread(int processId) {
......@@ -463,9 +464,10 @@ public class PgServer implements Service {
* A fake wrapper around pg_get_expr(expr_text, relation_oid), in PostgreSQL
* it "decompiles the internal form of an expression, assuming that any vars
* in it refer to the relation indicated by the second parameter".
*
*
* @param exprText the expression text
* @param relationOid the relation object id
* @return always null
*/
public static String getPgExpr(String exprText, int relationOid) {
return null;
......@@ -475,12 +477,14 @@ public class PgServer implements Service {
* Check if the current session has access to this table.
* This method is called by the database.
*
* @param pgType the postgres type oid
* @param conn the connection
* @param pgType the PostgreSQL type oid
* @param typeMod the type modifier (typically -1)
* @return A string name for the given type
* @return the name of the given type
*/
public static String formatType(Connection conn, int pgType, int typeMod) throws SQLException {
PreparedStatement prep = conn.prepareStatement("select typname from pg_catalog.pg_type where oid = ? and typtypmod = ?");
PreparedStatement prep = conn.prepareStatement(
"select typname from pg_catalog.pg_type where oid = ? and typtypmod = ?");
prep.setInt(1, pgType);
prep.setInt(2, typeMod);
ResultSet rs = prep.executeQuery();
......
......@@ -155,7 +155,8 @@ public class PgServerThread implements Runnable {
if (c != null && key == c.secret) {
c.cancelRequest();
} else {
// According to http://www.postgresql.org/docs/9.1/static/protocol-flow.html#AEN91739,
// According to
// http://www.postgresql.org/docs/9.1/static/protocol-flow.html#AEN91739,
// when canceling a request, if an invalid secret is provided then no exception
// should be sent back to the client.
server.trace("Invalid CancelRequest: pid=" + pid + ", key=" + key);
......@@ -548,7 +549,8 @@ public class PgServerThread implements Runnable {
return clientEncoding;
}
private void setParameter(PreparedStatement prep, int pgType, int i, int[] formatCodes) throws SQLException, IOException {
private void setParameter(PreparedStatement prep,
int pgType, int i, int[] formatCodes) throws SQLException, IOException {
boolean text = (i >= formatCodes.length) || (formatCodes[i] == 0);
int col = i + 1;
int paramLen = readInt();
......@@ -711,7 +713,7 @@ public class PgServerThread implements Runnable {
/**
* Check whether the given type should be formatted as text.
*
*
* @return true for binary
*/
private static boolean formatAsText(int pgType) {
......
......@@ -675,14 +675,8 @@ public class Data {
writeByte((byte) type);
byte[] b = v.getBytes();
int len = b.length;
if (len < 32) {
writeByte((byte) (BYTES_0_31 + len));
write(b, 0, b.length);
} else {
writeByte((byte) type);
writeVarInt(b.length);
write(b, 0, b.length);
}
writeVarInt(len);
write(b, 0, len);
break;
}
default:
......@@ -854,6 +848,12 @@ public class Data {
}
return ValueResultSet.get(rs);
}
case Value.GEOMETRY: {
int len = readVarInt();
byte[] b = DataUtils.newBytes(len);
read(b, 0, len);
return ValueGeometry.get(b);
}
default:
if (type >= INT_0_15 && type < INT_0_15 + 16) {
return ValueInt.get(type - INT_0_15);
......@@ -1092,10 +1092,7 @@ public class Data {
case Value.GEOMETRY: {
byte[] b = v.getBytesNoCopy();
int len = b.length;
if (len < 32) {
return 1 + b.length;
}
return 1 + getVarIntLen(b.length) + b.length;
return 1 + getVarIntLen(len) + len;
}
default:
throw DbException.throwInternalError("type=" + v.getType());
......
......@@ -155,7 +155,7 @@ public abstract class Value {
* The value type for string values with a fixed size.
*/
public static final int GEOMETRY = 22;
/**
* The number of value types.
*/
......
......@@ -9,6 +9,8 @@ package org.h2.value;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import org.h2.message.DbException;
import org.h2.util.StringUtils;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;
import com.vividsolutions.jts.io.WKBReader;
......@@ -49,7 +51,7 @@ public class ValueGeometry extends Value {
public static ValueGeometry get(String s) {
return (ValueGeometry) Value.cache(new ValueGeometry(fromWKT(s)));
}
/**
* Get or create a geometry value for the given geometry.
*
......@@ -59,23 +61,41 @@ public class ValueGeometry extends Value {
public static ValueGeometry get(byte[] bytes) {
return (ValueGeometry) Value.cache(new ValueGeometry(fromWKB(bytes)));
}
public Geometry getGeometry() {
return geometry;
}
/**
* Check whether two values intersect.
*
* @param r the second value
* @return true if they intersect
*/
public boolean intersects(ValueGeometry r) {
return geometry.intersects(r.getGeometry());
}
/**
* Get the intersection of two values.
*
* @param r the second value
* @return the intersection
*/
public Value intersection(ValueGeometry r) {
return get(this.geometry.intersection(r.geometry));
return get(geometry.intersection(r.geometry));
}
/**
* Get the union of two values.
*
* @param r the second value
* @return the union
*/
public Value union(ValueGeometry r) {
return get(this.geometry.union(r.geometry));
return get(geometry.union(r.geometry));
}
@Override
public int getType() {
return Value.GEOMETRY;
......@@ -83,13 +103,13 @@ public class ValueGeometry extends Value {
@Override
public String getSQL() {
return "'" + toWKT() + "'";
return StringUtils.quoteStringSQL(toWKT());
}
@Override
protected int compareSecure(Value v, CompareMode mode) {
Geometry g = ((ValueGeometry) v).geometry;
return this.geometry.compareTo(g);
return geometry.compareTo(g);
}
@Override
......@@ -104,7 +124,7 @@ public class ValueGeometry extends Value {
@Override
public int hashCode() {
return this.geometry.hashCode();
return geometry.hashCode();
}
@Override
......@@ -116,7 +136,7 @@ public class ValueGeometry extends Value {
public byte[] getBytes() {
return toWKB();
}
@Override
public void set(PreparedStatement prep, int parameterIndex) throws SQLException {
prep.setObject(parameterIndex, geometry);
......@@ -136,25 +156,32 @@ public class ValueGeometry extends Value {
public boolean equals(Object other) {
return other instanceof ValueGeometry && geometry.equals(((ValueGeometry) other).geometry);
}
/**
* Convert to Well-Known-Text format.
* Convert the value to the Well-Known-Text format.
*
* @return the well-known-text
*/
public String toWKT() {
WKTWriter w = new WKTWriter();
return w.write(this.geometry);
return w.write(geometry);
}
/**
* Convert to Well-Known-Binary format.
* Convert to value to the Well-Known-Binary format.
*
* @return the well-known-binary
*/
public byte[] toWKB() {
WKBWriter w = new WKBWriter();
return w.write(this.geometry);
return w.write(geometry);
}
/**
* Convert from Well-Known-Text format.
* Convert a Well-Known-Text to a Geometry object.
*
* @param s the well-known-text
* @return the Geometry object
*/
private static Geometry fromWKT(String s) {
WKTReader r = new WKTReader();
......@@ -164,9 +191,12 @@ public class ValueGeometry extends Value {
throw DbException.convert(ex);
}
}
/**
* Convert from Well-Known-Binary format.
* Convert a Well-Known-Binary to a Geometry object.
*
* @param s the well-known-binary
* @return the Geometry object
*/
private static Geometry fromWKB(byte[] bytes) {
WKBReader r = new WKBReader();
......@@ -176,4 +206,5 @@ public class ValueGeometry extends Value {
throw DbException.convert(ex);
}
}
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论