Changeset: e026fe73bb5e for monetdb-java
URL: http://dev.monetdb.org/hg/monetdb-java?cmd=changeset;node=e026fe73bb5e
Added Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetURL.java
        src/main/java/nl/cwi/monetdb/mcl/connection/helpers/TimestampHelper.java
Modified Files:
        src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetINET.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
        src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
        
src/main/java/nl/cwi/monetdb/mcl/connection/helpers/GregorianCalendarParser.java
        src/main/java/nl/cwi/monetdb/mcl/connection/mapi/AbstractSocket.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/AbstractProtocol.java
        src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiProtocol.java
        
src/main/java/nl/cwi/monetdb/mcl/protocol/oldmapi/OldMapiTupleLineParser.java
        src/main/java/nl/cwi/monetdb/mcl/responses/DataBlockResponse.java
        src/main/java/nl/cwi/monetdb/mcl/responses/ResultSetResponse.java
Branch: embedded
Log Message:

After a lot of suffering, finnaly passed all the tests in a MAPI connection! :) 
Now I will port some for the embedded connection, as some features are no 
available on it.


diffs (truncated from 1450 to 300 lines):

diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetConnection.java
@@ -47,6 +47,11 @@ public abstract class MonetConnection ex
     /** The sequence counter */
     private static int SeqCounter = 0;
 
+    /**
+     * Gets the current sequence counter.
+     *
+     * @return The current sequence counter
+     */
     public static int GetSeqCounter() {
         return SeqCounter;
     }
@@ -69,6 +74,7 @@ public abstract class MonetConnection ex
     private Map<String,Class<?>> typeMap = new HashMap<String,Class<?>>() {
         private static final long serialVersionUID = 1L; {
             put("inet", MonetINET.class);
+            put("url", MonetURL.class);
         }
     };
 
@@ -106,6 +112,15 @@ public abstract class MonetConnection ex
     }
 
     /**
+     * Checks if the conection is embedded or not
+     *
+     * @return If the connection is embedded
+     */
+    public boolean isEmbedded() {
+        return isEmbedded;
+    }
+
+    /**
      * Gets the connection's language data.
      *
      * @return The connection's language data
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetINET.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetINET.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetINET.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetINET.java
@@ -29,6 +29,8 @@ import java.sql.SQLOutput;
  * This class allows to retrieve the value of this INET as InetAddress.
  * This is probably meaningful only and only if the netmask is 32.  The
  * getNetmaskBits() method can be used to retrieve the subnet bits.
+ *
+ * @author Fabian Groffen
  */
 public class MonetINET implements SQLData {
 
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetPreparedStatement.java
@@ -44,23 +44,11 @@ import java.util.Map;
  * [ "int",        9,      0       ]
  * </pre>
  *
- * @author Fabian Groffen, Martin van Dinther
+ * @author Fabian Groffen, Martin van Dinther, Pedro Ferreira
  * @version 0.4
  */
 public class MonetPreparedStatement extends MonetStatement implements 
PreparedStatement {
 
-       /* only parse the date patterns once, use multiple times */
-       /** Format of a timestamp with RFC822 time zone */
-       private static final SimpleDateFormat MTimestampZ = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSSZ");
-       /** Format of a timestamp */
-       private static final SimpleDateFormat MTimestamp = new 
SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
-       /** Format of a time with RFC822 time zone */
-       private static final SimpleDateFormat MTimeZ = new 
SimpleDateFormat("HH:mm:ss.SSSZ");
-       /** Format of a time */
-       private static final SimpleDateFormat MTime = new 
SimpleDateFormat("HH:mm:ss.SSS");
-       /** Format of a date used by mserver */
-       private static final SimpleDateFormat MDate = new 
SimpleDateFormat("yyyy-MM-dd");
-
        private final MonetConnection connection;
        private final String[] monetdbType;
        private final int[] javaType;
@@ -74,6 +62,12 @@ public class MonetPreparedStatement exte
        private final int rscolcnt;
        private final String[] values;
 
+       private final SimpleDateFormat mTimestampZ;
+       private final SimpleDateFormat mTimestamp;
+       private final SimpleDateFormat mTimeZ;
+       private final SimpleDateFormat mTime;
+       private final SimpleDateFormat mDate;
+
        /**
         * MonetPreparedStatement constructor which checks the arguments for 
validity. A MonetPreparedStatement is backed
         * by a {@link MonetStatement}, which deals with most of the required 
stuff of this class.
@@ -126,6 +120,12 @@ public class MonetPreparedStatement exte
 
                // PreparedStatements are by default poolable
                poolable = true;
+
+               mTimestampZ = connection.getProtocol().getMonetTimestampTz();
+               mTimestamp = connection.getProtocol().getMonetTimestamp();
+               mTimeZ = connection.getProtocol().getMonetTimeTz();
+               mTime = connection.getProtocol().getMonetTime();
+               mDate = connection.getProtocol().getMonetDate();
        }
 
        //== methods interface PreparedStatement
@@ -335,7 +335,7 @@ public class MonetPreparedStatement exte
                                        case Types.LONGVARCHAR:
                                                return true;
                                        default:
-                                               return true;
+                                               return false;
                                }
                        }
 
@@ -1307,8 +1307,8 @@ public class MonetPreparedStatement exte
                if (cal == null) {
                        setValue(parameterIndex, "date '" + x.toString() + "'");
                } else {
-                       MDate.setTimeZone(cal.getTimeZone());
-                       setValue(parameterIndex, "date '" + MDate.format(x) + 
"'");
+                       mDate.setTimeZone(cal.getTimeZone());
+                       setValue(parameterIndex, "date '" + mDate.format(x) + 
"'");
                }
        }
 
@@ -2152,7 +2152,7 @@ public class MonetPreparedStatement exte
                if (hasTimeZone) {
                        // timezone shouldn't matter, since the server is 
timezone
                        // aware in this case
-                       String RFC822 = MTimeZ.format(x);
+                       String RFC822 = mTimeZ.format(x);
                        setValue(index, "timetz '" + RFC822.substring(0, 15) + 
":" + RFC822.substring(15) + "'");
                } else {
                        // server is not timezone aware for this field, and no
@@ -2162,8 +2162,8 @@ public class MonetPreparedStatement exte
                        if (cal == null) {
                                setValue(index, "time '" + x.toString() + "'");
                        } else {
-                               MTime.setTimeZone(cal.getTimeZone());
-                               setValue(index, "time '" + MTime.format(x) + 
"'");
+                               mTime.setTimeZone(cal.getTimeZone());
+                               setValue(index, "time '" + mTime.format(x) + 
"'");
                        }
                }
        }
@@ -2209,7 +2209,7 @@ public class MonetPreparedStatement exte
                if (hasTimeZone) {
                        // timezone shouldn't matter, since the server is 
timezone
                        // aware in this case
-                       String RFC822 = MTimestampZ.format(x);
+                       String RFC822 = mTimestampZ.format(x);
                        setValue(index, "timestamptz '" + RFC822.substring(0, 
26) + ":" + RFC822.substring(26) + "'");
                } else {
                        // server is not timezone aware for this field, and no
@@ -2219,8 +2219,8 @@ public class MonetPreparedStatement exte
                        if (cal == null) {
                                setValue(index, "timestamp '" + x.toString() + 
"'");
                        } else {
-                               MTimestamp.setTimeZone(cal.getTimeZone());
-                               setValue(index, "timestamp '" + 
MTimestamp.format(x) + "'");
+                               mTimestamp.setTimeZone(cal.getTimeZone());
+                               setValue(index, "timestamp '" + 
mTimestamp.format(x) + "'");
                        }
                }
        }
@@ -2263,6 +2263,7 @@ public class MonetPreparedStatement exte
        @Override
        public void setURL(int parameterIndex, URL x) throws SQLException {
                setString(parameterIndex, x.toString());
+               values[getParamIdx(parameterIndex)] = "url " + 
values[getParamIdx(parameterIndex)];
        }
 
        /**
diff --git a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java 
b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
--- a/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
+++ b/src/main/java/nl/cwi/monetdb/jdbc/MonetResultSet.java
@@ -8,8 +8,6 @@
 
 package nl.cwi.monetdb.jdbc;
 
-import nl.cwi.monetdb.mcl.connection.helpers.GregorianCalendarParser;
-import nl.cwi.monetdb.mcl.protocol.ProtocolException;
 import nl.cwi.monetdb.mcl.responses.DataBlockResponse;
 import nl.cwi.monetdb.mcl.responses.ResultSetResponse;
 
@@ -40,7 +38,6 @@ import java.sql.Statement;
 import java.sql.Time;
 import java.sql.Timestamp;
 import java.sql.Types;
-import java.text.ParsePosition;
 import java.util.*;
 
 /**
@@ -61,7 +58,7 @@ import java.util.*;
  * for FORWARD_ONLY result sets the memory usage will be likely lower for large
  * result sets.
  *
- * @author Fabian Groffen, Martin van Dinther
+ * @author Fabian Groffen, Martin van Dinther, Pedro Ferreira
  * @version 0.8
  */
 public class MonetResultSet extends MonetWrapper implements ResultSet {
@@ -707,40 +704,36 @@ public class MonetResultSet extends Mone
                        }
                        // match type specific values
                        switch (JdbcSQLTypes[columnIndex - 1]) {
-                               case Types.BOOLEAN:
-                                       return 
currentBlock.getBooleanValue(columnIndex - 1);
-                               case Types.TINYINT:
-                                       return 
currentBlock.getByteValue(columnIndex - 1) != 0;
-                               case Types.SMALLINT:
-                                       return 
currentBlock.getShortValue(columnIndex - 1) != 0;
-                               case Types.INTEGER:
-                                       return 
currentBlock.getIntValue(columnIndex - 1) != 0;
-                               case Types.BIGINT:
-                                       return 
currentBlock.getLongValue(columnIndex - 1) != 0L;
-                               case Types.REAL:
-                                       return 
currentBlock.getFloatValue(columnIndex - 1) != 0.0f;
-                               case Types.DOUBLE:
-                                       return 
currentBlock.getDoubleValue(columnIndex - 1) != 0.0d;
-                               case Types.CHAR:
-                               case Types.VARCHAR:
-                               case Types.LONGVARCHAR:
-                               case Types.CLOB:
-                               case Types.BLOB:
-                               case Types.LONGVARBINARY:
-                                       String val = 
currentBlock.getValueAsString(columnIndex - 1);
-                                       if ("false".equalsIgnoreCase(val) || 
"0".equals(val))
-                                               return false;
-                                       if ("true".equalsIgnoreCase(val) || 
"1".equals(val))
-                                               return true;
-                                       throw 
newSQLInvalidColumnIndexException(columnIndex);
-                               case Types.NUMERIC:
-                               case Types.DECIMAL:
-                                       BigDecimal bigdec = (BigDecimal) 
currentBlock.getValueAsObject(columnIndex - 1);
-                                       return 
bigdec.compareTo(BigDecimal.ZERO) != 0;
-                               default: //OTHERS, BLOB, LONGVARBINARY, TIME...
-                                       throw new SQLException("Conversion from 
" + types[columnIndex - 1] +
-                                                       " to boolean type not 
supported", "M1M05");
-                       }
+                case Types.BOOLEAN:
+                    return currentBlock.getBooleanValue(columnIndex - 1);
+                case Types.TINYINT:
+                    return currentBlock.getByteValue(columnIndex - 1) != 0;
+                case Types.SMALLINT:
+                    return currentBlock.getShortValue(columnIndex - 1) != 0;
+                case Types.INTEGER:
+                    return currentBlock.getIntValue(columnIndex - 1) != 0;
+                case Types.BIGINT:
+                    return currentBlock.getLongValue(columnIndex - 1) != 0L;
+                case Types.REAL:
+                    return currentBlock.getFloatValue(columnIndex - 1) != 0.0f;
+                case Types.DOUBLE:
+                    return currentBlock.getDoubleValue(columnIndex - 1) != 
0.0d;
+                case Types.CHAR:
+                case Types.VARCHAR:
+                case Types.LONGVARCHAR:
+                case Types.CLOB:
+                case Types.BLOB:
+                case Types.LONGVARBINARY:
+                    String val = currentBlock.getValueAsString(columnIndex - 
1);
+                    return !"0".equals(val) && ("1".equals(val) || 
Boolean.parseBoolean(val));
+                case Types.NUMERIC:
+                case Types.DECIMAL:
+                    BigDecimal bigdec = (BigDecimal) 
currentBlock.getValueAsObject(columnIndex - 1);
+                    return bigdec.compareTo(BigDecimal.ZERO) != 0;
+                default: //OTHERS, BLOB, LONGVARBINARY, TIME...
+                    throw new SQLException("Conversion from " + 
types[columnIndex - 1] +
+                            " to boolean type not supported", "M1M05");
+            }
                } catch (ClassCastException ex) {
                        throw new SQLException(ex.getMessage());
                } catch (IndexOutOfBoundsException e) {
@@ -1828,7 +1821,7 @@ public class MonetResultSet extends Mone
                                                case 3:
                                                        if 
("url".equals(MonetDBType)) {
                                                                try {
-                                                                       return 
new URL(val);
+                                                                       return 
new MonetURL(val);
                                                                } catch 
(Exception exc) {
                                                                        // 
ignore exception and just return the val String object
                                                                        return 
val;
@@ -2504,33 +2497,40 @@ public class MonetResultSet extends Mone
                        if(setLastNullValue(columnIndex - 1)) {
                                return null;
                        }
-            Calendar res;
+                       Calendar res;
+            long millis;
             switch (JdbcSQLTypes[columnIndex - 1]) {
-                               case Types.DATE:
+                case Types.DATE:
+                case Types.TIME:
+                case Types.TIMESTAMP:
                                        res = (Calendar) 
currentBlock.getValueAsObject(columnIndex - 1);
+                    millis = res.getTimeInMillis() - 
res.getTimeZone().getRawOffset() + cal.getTimeZone().getRawOffset();
                                        break;
+                case Types.TIME_WITH_TIMEZONE:
+                case Types.TIMESTAMP_WITH_TIMEZONE:
+                    res = (Calendar) currentBlock.getValueAsObject(columnIndex 
- 1);
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to