1515import org .postgresql .util .PSQLException ;
1616
1717
18- /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.8 2002/09/11 05:38:45 barry Exp $
18+ /* $Header: /cvsroot/pgsql/src/interfaces/jdbc/org/postgresql/jdbc2/Attic/AbstractJdbc2ResultSet.java,v 1.9 2002/10/17 19:17:08 barry Exp $
1919 * This class defines methods of the jdbc2 specification. This class extends
2020 * org.postgresql.jdbc1.AbstractJdbc1ResultSet which provides the jdbc1
2121 * methods. The real Statement class (for jdbc2) is org.postgresql.jdbc2.Jdbc2ResultSet
@@ -623,7 +623,11 @@ public synchronized void insertRow()
623623for (int i =1 ;keys .hasMoreElements ();i ++)
624624{
625625String key = (String )keys .nextElement ();
626- insertStatement .setObject (i ,updateValues .get (key ) );
626+ Object o =updateValues .get (key );
627+ if (o instanceof NullObject )
628+ insertStatement .setNull (i ,java .sql .Types .NULL );
629+ else
630+ insertStatement .setObject (i ,o );
627631}
628632
629633insertStatement .executeUpdate ();
@@ -735,14 +739,7 @@ public synchronized void updateAsciiStream(int columnIndex,
735739 )
736740throws SQLException
737741{
738-
739- if ( !isUpdateable () )
740- {
741- throw new PSQLException ("postgresql.updateable.notupdateable" );
742- }
743-
744742byte []theData =null ;
745-
746743try
747744{
748745x .read (theData ,0 ,length );
@@ -756,9 +753,7 @@ public synchronized void updateAsciiStream(int columnIndex,
756753throw new PSQLException ("postgresql.updateable.ioerror" +ie );
757754}
758755
759- doingUpdates = !onInsertRow ;
760-
761- updateValues .put (fields [columnIndex -1 ].getName (),theData );
756+ updateValue (columnIndex ,theData );
762757
763758}
764759
@@ -767,15 +762,7 @@ public synchronized void updateBigDecimal(int columnIndex,
767762java .math .BigDecimal x )
768763throws SQLException
769764{
770-
771- if ( !isUpdateable () )
772- {
773- throw new PSQLException ("postgresql.updateable.notupdateable" );
774- }
775-
776- doingUpdates = !onInsertRow ;
777- updateValues .put (fields [columnIndex -1 ].getName (),x );
778-
765+ updateValue (columnIndex ,x );
779766}
780767
781768
@@ -785,14 +772,7 @@ public synchronized void updateBinaryStream(int columnIndex,
785772 )
786773throws SQLException
787774{
788-
789- if ( !isUpdateable () )
790- {
791- throw new PSQLException ("postgresql.updateable.notupdateable" );
792- }
793-
794775byte []theData =null ;
795-
796776try
797777{
798778x .read (theData ,0 ,length );
@@ -806,57 +786,31 @@ public synchronized void updateBinaryStream(int columnIndex,
806786{
807787throw new PSQLException ("postgresql.updateable.ioerror" +ie );
808788}
809-
810- doingUpdates = !onInsertRow ;
811-
812- updateValues .put (fields [columnIndex -1 ].getName (),theData );
789+ updateValue (columnIndex ,theData );
813790
814791}
815792
816793
817794public synchronized void updateBoolean (int columnIndex ,boolean x )
818795throws SQLException
819796{
820-
821- if ( !isUpdateable () )
822- {
823- throw new PSQLException ("postgresql.updateable.notupdateable" );
824- }
825-
826797if (Driver .logDebug )
827798Driver .debug ("updating boolean " +fields [columnIndex -1 ].getName () +"=" +x );
828-
829- doingUpdates = !onInsertRow ;
830- updateValues .put (fields [columnIndex -1 ].getName (),new Boolean (x ) );
831-
799+ updateValue (columnIndex ,new Boolean (x ));
832800}
833801
834802
835803public synchronized void updateByte (int columnIndex ,byte x )
836804throws SQLException
837805{
838- if ( !isUpdateable () )
839- {
840- throw new PSQLException ("postgresql.updateable.notupdateable" );
841- }
842-
843- doingUpdates =true ;
844- updateValues .put (fields [columnIndex -1 ].getName (),String .valueOf (x ) );
806+ updateValue (columnIndex ,String .valueOf (x ));
845807}
846808
847809
848810public synchronized void updateBytes (int columnIndex ,byte []x )
849811throws SQLException
850812{
851-
852- if ( !isUpdateable () )
853- {
854- throw new PSQLException ("postgresql.updateable.notupdateable" );
855- }
856-
857- doingUpdates = !onInsertRow ;
858- updateValues .put (fields [columnIndex -1 ].getName (),x );
859-
813+ updateValue (columnIndex ,x );
860814}
861815
862816
@@ -866,14 +820,7 @@ public synchronized void updateCharacterStream(int columnIndex,
866820 )
867821throws SQLException
868822{
869-
870- if ( !isUpdateable () )
871- {
872- throw new PSQLException ("postgresql.updateable.notupdateable" );
873- }
874-
875823char []theData =null ;
876-
877824try
878825{
879826x .read (theData ,0 ,length );
@@ -887,124 +834,66 @@ public synchronized void updateCharacterStream(int columnIndex,
887834{
888835throw new PSQLException ("postgresql.updateable.ioerror" +ie );
889836}
890-
891- doingUpdates = !onInsertRow ;
892- updateValues .put (fields [columnIndex -1 ].getName (),theData );
893-
837+ updateValue (columnIndex ,theData );
894838}
895839
896840
897841public synchronized void updateDate (int columnIndex ,java .sql .Date x )
898842throws SQLException
899843{
900-
901- if ( !isUpdateable () )
902- {
903- throw new PSQLException ("postgresql.updateable.notupdateable" );
904- }
905-
906- doingUpdates = !onInsertRow ;
907- updateValues .put (fields [columnIndex -1 ].getName (),x );
844+ updateValue (columnIndex ,x );
908845}
909846
910847
911848public synchronized void updateDouble (int columnIndex ,double x )
912849throws SQLException
913850{
914- if ( !isUpdateable () )
915- {
916- throw new PSQLException ("postgresql.updateable.notupdateable" );
917- }
918-
919851if (Driver .logDebug )
920852Driver .debug ("updating double " +fields [columnIndex -1 ].getName () +"=" +x );
921-
922- doingUpdates = !onInsertRow ;
923- updateValues .put (fields [columnIndex -1 ].getName (),new Double (x ) );
924-
853+ updateValue (columnIndex ,new Double (x ));
925854}
926855
927856
928857public synchronized void updateFloat (int columnIndex ,float x )
929858throws SQLException
930859{
931- if ( !isUpdateable () )
932- {
933- throw new PSQLException ("postgresql.updateable.notupdateable" );
934- }
935-
936860if (Driver .logDebug )
937861Driver .debug ("updating float " +fields [columnIndex -1 ].getName () +"=" +x );
938-
939- doingUpdates = !onInsertRow ;
940-
941- updateValues .put (fields [columnIndex -1 ].getName (),new Float (x ) );
942-
862+ updateValue (columnIndex ,new Float (x ));
943863}
944864
945865
946866public synchronized void updateInt (int columnIndex ,int x )
947867throws SQLException
948868{
949- if ( !isUpdateable () )
950- {
951- throw new PSQLException ("postgresql.updateable.notupdateable" );
952- }
953-
954869if (Driver .logDebug )
955870Driver .debug ("updating int " +fields [columnIndex -1 ].getName () +"=" +x );
956-
957- doingUpdates = !onInsertRow ;
958- updateValues .put (fields [columnIndex -1 ].getName (),new Integer (x ) );
959-
871+ updateValue (columnIndex ,new Integer (x ));
960872}
961873
962874
963875public synchronized void updateLong (int columnIndex ,long x )
964876throws SQLException
965877{
966- if ( !isUpdateable () )
967- {
968- throw new PSQLException ("postgresql.updateable.notupdateable" );
969- }
970-
971878if (Driver .logDebug )
972879Driver .debug ("updating long " +fields [columnIndex -1 ].getName () +"=" +x );
973-
974- doingUpdates = !onInsertRow ;
975- updateValues .put (fields [columnIndex -1 ].getName (),new Long (x ) );
976-
880+ updateValue (columnIndex ,new Long (x ));
977881}
978882
979883
980884public synchronized void updateNull (int columnIndex )
981885throws SQLException
982886{
983- if ( !isUpdateable () )
984- {
985- throw new PSQLException ("postgresql.updateable.notupdateable" );
986- }
987-
988- doingUpdates = !onInsertRow ;
989- updateValues .put (fields [columnIndex -1 ].getName (),null );
990-
991-
887+ updateValue (columnIndex ,new NullObject ());
992888}
993889
994890
995891public synchronized void updateObject (int columnIndex ,Object x )
996892throws SQLException
997893{
998- if ( !isUpdateable () )
999- {
1000- throw new PSQLException ("postgresql.updateable.notupdateable" );
1001- }
1002-
1003894if (Driver .logDebug )
1004895Driver .debug ("updating object " +fields [columnIndex -1 ].getName () +" = " +x );
1005-
1006- doingUpdates = !onInsertRow ;
1007- updateValues .put (fields [columnIndex -1 ].getName (),x );
896+ updateValue (columnIndex ,x );
1008897}
1009898
1010899
@@ -1152,7 +1041,11 @@ public synchronized void updateRow()
11521041Iterator iterator =updateValues .values ().iterator ();
11531042for (;iterator .hasNext ();i ++)
11541043{
1155- updateStatement .setObject (i +1 ,iterator .next () );
1044+ Object o =iterator .next ();
1045+ if (o instanceof NullObject )
1046+ updateStatement .setNull (i +1 ,java .sql .Types .NULL );
1047+ else
1048+ updateStatement .setObject (i +1 ,o );
11561049
11571050}
11581051for (int j =0 ;j <numKeys ;j ++,i ++)
@@ -1194,11 +1087,7 @@ public synchronized void updateShort(int columnIndex, short x)
11941087{
11951088if (Driver .logDebug )
11961089Driver .debug ("in update Short " +fields [columnIndex -1 ].getName () +" = " +x );
1197-
1198-
1199- doingUpdates = !onInsertRow ;
1200- updateValues .put (fields [columnIndex -1 ].getName (),new Short (x ) );
1201-
1090+ updateValue (columnIndex ,new Short (x ));
12021091}
12031092
12041093
@@ -1207,10 +1096,7 @@ public synchronized void updateString(int columnIndex, String x)
12071096{
12081097if (Driver .logDebug )
12091098Driver .debug ("in update String " +fields [columnIndex -1 ].getName () +" = " +x );
1210-
1211- doingUpdates = !onInsertRow ;
1212- updateValues .put (fields [columnIndex -1 ].getName (),x );
1213-
1099+ updateValue (columnIndex ,x );
12141100}
12151101
12161102
@@ -1219,11 +1105,7 @@ public synchronized void updateTime(int columnIndex, Time x)
12191105{
12201106if (Driver .logDebug )
12211107Driver .debug ("in update Time " +fields [columnIndex -1 ].getName () +" = " +x );
1222-
1223-
1224- doingUpdates = !onInsertRow ;
1225- updateValues .put (fields [columnIndex -1 ].getName (),x );
1226-
1108+ updateValue (columnIndex ,x );
12271109}
12281110
12291111
@@ -1232,10 +1114,7 @@ public synchronized void updateTimestamp(int columnIndex, Timestamp x)
12321114{
12331115if (Driver .logDebug )
12341116Driver .debug ("updating Timestamp " +fields [columnIndex -1 ].getName () +" = " +x );
1235-
1236- doingUpdates = !onInsertRow ;
1237- updateValues .put (fields [columnIndex -1 ].getName (),x );
1238-
1117+ updateValue (columnIndex ,x );
12391118
12401119}
12411120
@@ -1564,6 +1443,17 @@ public void setStatement(Statement statement)
15641443this .statement =statement ;
15651444}
15661445
1446+ protected void updateValue (int columnIndex ,Object value )throws SQLException {
1447+ if ( !isUpdateable () )
1448+ {
1449+ throw new PSQLException ("postgresql.updateable.notupdateable" );
1450+ }
1451+ doingUpdates = !onInsertRow ;
1452+ if (value ==null )
1453+ updateNull (columnIndex );
1454+ else
1455+ updateValues .put (fields [columnIndex -1 ].getName (),value );
1456+ }
15671457
15681458private class PrimaryKey
15691459{
@@ -1581,7 +1471,8 @@ Object getValue() throws SQLException
15811471}
15821472};
15831473
1584-
1474+ class NullObject {
1475+ };
15851476
15861477}
15871478