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

Cleanup.

上级 a75bf79a
......@@ -263,6 +263,7 @@ 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) {
......@@ -466,6 +467,7 @@ public class PgServer implements Service {
*
* @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();
......
......@@ -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());
......
......@@ -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;
......@@ -64,16 +66,34 @@ public class ValueGeometry extends Value {
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
......@@ -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
......@@ -138,23 +158,30 @@ public class ValueGeometry extends Value {
}
/**
* 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();
......@@ -166,7 +193,10 @@ public class ValueGeometry extends Value {
}
/**
* 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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论