Changeset: 6e8ca38e2bc8 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6e8ca38e2bc8
Modified Files:
pathfinder/debian/libpf_ferry0.install
Branch: default
Log Message:
Merge with Oct2010 branch.
diffs (truncated from 377 to 300 lines):
diff -r c89203cffcff -r 6e8ca38e2bc8 MonetDB/src/gdk/gdk_system.mx
--- a/MonetDB/src/gdk/gdk_system.mx Tue Nov 09 10:55:56 2010 +0100
+++ b/MonetDB/src/gdk/gdk_system.mx Tue Nov 09 16:07:06 2010 +0100
@@ -516,15 +516,19 @@
DWORD t;
struct winthread *w;
- assert(winthread_cs_init);
- t = GetCurrentThreadId();
- EnterCriticalSection(&winthread_cs);
- for (w = winthreads; w && w->tid != t; w = w->next)
- ;
- LeaveCriticalSection(&winthread_cs);
- if (w->hdl == NULL)
- rm_winthread(w);
- ExitThread(s);
+ if (winthread_cs_init) {
+ t = GetCurrentThreadId();
+ EnterCriticalSection(&winthread_cs);
+ for (w = winthreads; w && w->tid != t; w = w->next)
+ ;
+ LeaveCriticalSection(&winthread_cs);
+ if (w->hdl == NULL)
+ rm_winthread(w);
+ ExitThread(s);
+ } else {
+ /* no threads started yet, so this is a global exit */
+ MT_global_exit(s);
+ }
}
int
diff -r c89203cffcff -r 6e8ca38e2bc8 java/ChangeLog.Oct2010
--- a/java/ChangeLog.Oct2010 Tue Nov 09 10:55:56 2010 +0100
+++ b/java/ChangeLog.Oct2010 Tue Nov 09 16:07:06 2010 +0100
@@ -1,3 +1,12 @@
# ChangeLog file for java
# This file is updated with mchangelog (Gentoo echangelog bastard script)
+* Tue Nov 9 2010 Fabian Groffen <[email protected]>
+- Fix SQL syntax of inserting BLOB code, using setBytes()
+- Added propery 'treat_blob_as_binary' to simulate BINARY types based on
+ BLOBs for applications, (e.g. Hibernate-based) that rely on BINARY's
+ byte array mapping
+- Added code to handle BINARY types
+- Fixed implementation of getBytes to match the specifications
+- Implemented getBinaryStream according to the specifications
+
diff -r c89203cffcff -r 6e8ca38e2bc8
java/src/nl/cwi/monetdb/jdbc/MonetConnection.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java Tue Nov 09 10:55:56
2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetConnection.java Tue Nov 09 16:07:06
2010 +0100
@@ -122,6 +122,8 @@
/** Whether or not to use a Java based PreparedStatement
* implementation */
private final boolean javaPreparedStatements;
+ /** Whether or not BLOB is mapped to BINARY within the driver */
+ private final boolean blobIsBinary;
/**
* Constructor of a Connection for MonetDB. At this moment the
@@ -154,6 +156,7 @@
String language = props.getProperty("language");
boolean debug =
Boolean.valueOf(props.getProperty("debug")).booleanValue();
String hash = props.getProperty("hash");
+ blobIsBinary =
Boolean.valueOf(props.getProperty("treat_blob_as_binary")).booleanValue();
// check input arguments
if (hostname == null || hostname.trim().equals(""))
@@ -1064,6 +1067,13 @@
//== end methods of interface Connection
/**
+ * Returns whether the BLOB type should be mapped to BINARY type.
+ */
+ boolean getBlobAsBinary() {
+ return(blobIsBinary);
+ }
+
+ /**
* Sends the given string to MonetDB as regular statement, making
* sure there is a prompt after the command is sent. All possible
* returned information is discarded. Encountered errors are
diff -r c89203cffcff -r 6e8ca38e2bc8
java/src/nl/cwi/monetdb/jdbc/MonetDriver.java.in
--- a/java/src/nl/cwi/monetdb/jdbc/MonetDriver.java.in Tue Nov 09 10:55:56
2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetDriver.java.in Tue Nov 09 16:07:06
2010 +0100
@@ -240,6 +240,11 @@
prop.description = "Whether redirects issued by the server
should be followed";
props.add(prop);
+ prop = new DriverPropertyInfo("treat_blob_as_binary", "false");
+ prop.required = false;
+ prop.description = "Whether BLOBs on the server should be
treated as BINARY types, thus mapped to byte[]";
+ props.add(prop);
+
DriverPropertyInfo[] dpi = new DriverPropertyInfo[props.size()];
return((DriverPropertyInfo[])props.toArray(dpi));
}
@@ -310,7 +315,7 @@
return(tp.intValue());
} else {
// this should not be able to happen
- // do not assert, since maybe feature versions introduce
+ // do not assert, since maybe future versions introduce
// new types
return(Types.OTHER);
}
diff -r c89203cffcff -r 6e8ca38e2bc8
java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java Tue Nov 09
10:55:56 2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java Tue Nov 09
16:07:06 2010 +0100
@@ -591,7 +591,7 @@
hex.append(HEXES.charAt((b & 0xF0) >> 4))
.append(HEXES.charAt((b & 0x0F)));
}
- setString(parameterIndex, hex.toString());
+ setValue(parameterIndex, "blob '" + hex.toString() + "'");
}
/**
diff -r c89203cffcff -r 6e8ca38e2bc8
java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java Tue Nov 09 10:55:56
2010 +0100
+++ b/java/src/nl/cwi/monetdb/jdbc/MonetResultSet.java Tue Nov 09 16:07:06
2010 +0100
@@ -287,13 +287,76 @@
not implemented for now */
public InputStream getAsciiStream(int columnIndex) throws SQLException
{ throw new SQLException("Method getAsciiStream not implemented yet, sorry!"); }
public InputStream getAsciiStream(String columnName) throws
SQLException { throw new SQLException("Method getAsciiStream not implemented
yet, sorry!"); }
- public InputStream getBinaryStream(int columnIndex) throws SQLException
{ throw new SQLException("Method getBinaryStream not implemented yet, sorry!");
}
- public InputStream getBinaryStream(String columnName) throws
SQLException { throw new SQLException("Method getBinaryStream not implemented
yet, sorry!"); }
public InputStream getUnicodeStream(int columnIndex) throws
SQLException { throw new SQLException("Method getUnicodeStream not implemented
yet, sorry!"); }
public InputStream getUnicodeStream(String columnName) throws
SQLException { throw new SQLException("Method getUnicodeStream not implemented
yet, sorry!"); }
/**
* Retrieves the value of the designated column in the current row
+ * of this ResultSet object as a stream of uninterpreted bytes. The
+ * value can then be read in chunks from the stream. This method is
+ * particularly suitable for retrieving large LONGVARBINARY values.
+ * <br/><br/>
+ * Note: All the data in the returned stream must be read prior to
+ * getting the value of any other column. The next call to a getter
+ * method implicitly closes the stream. Also, a stream may return 0
+ * when the method InputStream.available is called whether there is
+ * data available or not.
+ *
+ * @param columnIndex the first column is 1, the second is 2, ...
+ * @return a Java input stream that delivers the database column
+ * value as a stream of uninterpreted bytes; if the value is SQL
+ * NULL, the value returned is null
+ * @throws SQLException if the columnIndex is not valid; if a
+ * database access error occurs or this method is called on a closed
+ * result set
+ */
+ public InputStream getBinaryStream(int columnIndex) throws SQLException
{
+ switch (getJavaType(types[columnIndex - 1])) {
+ case Types.BLOB:
+ Blob blob = getBlob(columnIndex);
+ if (blob == null)
+ return(null);
+ return(blob.getBinaryStream());
+ case Types.BINARY:
+ case Types.VARBINARY:
+ case Types.LONGVARBINARY:
+ byte[] bte = getBytes(columnIndex);
+ if (bte == null)
+ return(null);
+ return(new ByteArrayInputStream(bte));
+ }
+ throw new SQLException("Cannot operate on " +
+ types[columnIndex - 1] + " type");
+ }
+
+ /**
+ * Retrieves the value of the designated column in the current row
+ * of this ResultSet object as a stream of uninterpreted bytes. The
+ * value can then be read in chunks from the stream. This method is
+ * particularly suitable for retrieving large LONGVARBINARY values.
+ * <br/><br/>
+ * Note: All the data in the returned stream must be read prior to
+ * getting the value of any other column. The next call to a getter
+ * method implicitly closes the stream. Also, a stream may return 0
+ * when the method available is called whether there is data
+ * available or not.
+ *
+ * @param columnLabel the label for the column specified with
+ * the SQL AS clause. If the SQL AS clause was not specified, then
+ * the label is the name of the column
+ * @return a Java input stream that delivers the database column
+ * value as a stream of uninterpreted bytes; if the value is SQL
+ * NULL, the result is null
+ * @throws SQLException if the columnLabel is not valid; if a
+ * database access error occurs or this method is called on a closed
+ * result set
+ */
+ public InputStream getBinaryStream(String columnName) throws
SQLException {
+ return(getBinaryStream(findColumn(columnName)));
+ }
+
+ /**
+ * Retrieves the value of the designated column in the current row
* of this ResultSet object as a java.io.Reader object.
*
* @param columnIndex the first column is 1, the second is 2, ...
@@ -481,7 +544,7 @@
* @throws SQLException if there is no such column
*/
public boolean getBoolean(int columnIndex) throws SQLException{
- int dataType = MonetDriver.getJavaType(types[columnIndex - 1]);
+ int dataType = getJavaType(types[columnIndex - 1]);
if (dataType == Types.TINYINT ||
dataType == Types.SMALLINT ||
dataType == Types.INTEGER ||
@@ -570,10 +633,6 @@
* ResultSet object as a byte array in the Java programming language.
The
* bytes represent the raw values returned by the driver.
* <br /><br />
- * NOTE: Since the mapi protocol is ASCII-based, this method only
returns
- * Java byte representations of Strings, which is nothing more
than
- * an encoding into a sequence of bytes using the platform's
default
- * charset.
*
* @param columnIndex the first column is 1, the second is 2, ...
* @return the column value; if the value is SQL NULL, the value
returned
@@ -581,11 +640,28 @@
* @throws SQLException if a database access error occurs
*/
public byte[] getBytes(int columnIndex) throws SQLException {
- String bytes = getString(columnIndex);
- if (bytes == null) {
+ // According to Table B-6, getBytes() only operates on BINARY
+ // types
+ switch (getJavaType(types[columnIndex - 1])) {
+ case Types.BINARY:
+ case Types.VARBINARY:
+ case Types.LONGVARBINARY:
+ // pass
+ break;
+ default:
+ throw new SQLException("Cannot operate on " +
+ types[columnIndex - 1] + "
type");
+ }
+ String tmp = getString(columnIndex);
+ if (tmp == null) {
return(null);
} else {
- return(bytes.getBytes());
+ // unpack the HEX (BLOB) notation to real bytes
+ int len = tmp.length() / 2;
+ byte[] buf = new byte[len];
+ for (int j = 0; j < len; j++)
+ buf[j] = (byte)Integer.parseInt(tmp.substring(2
* j, (2 * j) + 2), 16);
+ return(buf);
}
}
@@ -1135,7 +1211,7 @@
try {
return(
getClassForType(
-
MonetDriver.getJavaType(types[column - 1])
+
getJavaType(types[column - 1])
).getName()
);
} catch (IndexOutOfBoundsException e) {
@@ -1181,7 +1257,7 @@
public int getColumnType(int column) throws
SQLException {
String type = getColumnTypeName(column);
- return(MonetDriver.getJavaType(type));
+ return(getJavaType(type));
}
/**
@@ -1281,8 +1357,8 @@
return(null);
}
- Class type = getClassForType(MonetDriver.getJavaType(types[i -
1]));
-
+ Class type = getClassForType(getJavaType(types[i - 1]));
+
if (type == BigDecimal.class) {
return(getBigDecimal(i));
} else if (type == Boolean.class) {
@@ -1305,6 +1381,8 @@
return(getClob(i));
} else if (type == Blob.class) {
return(getBlob(i));
+ } else if (type == byte[].class) {
+ return(getBytes(i));
} else {
return(getString(i));
}
@@ -1354,6 +1432,10 @@
return(Clob.class);
case Types.BLOB:
return(Blob.class);
+ case Types.BINARY: // MonetDB currently does not
support these
+ case Types.VARBINARY: // see treat_blob_as_binary
property
+ case Types.LONGVARBINARY:
+ return(byte[].class);
// all below are currently not implemented and used
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list