~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/openjdk/sun/jdbc/odbc/JdbcOdbcUpdateableResultSet.java

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2009 Volker Berlin (i-net software)
 
3
 
 
4
  This software is provided 'as-is', without any express or implied
 
5
  warranty.  In no event will the authors be held liable for any damages
 
6
  arising from the use of this software.
 
7
 
 
8
  Permission is granted to anyone to use this software for any purpose,
 
9
  including commercial applications, and to alter it and redistribute it
 
10
  freely, subject to the following restrictions:
 
11
 
 
12
  1. The origin of this software must not be misrepresented; you must not
 
13
     claim that you wrote the original software. If you use this software
 
14
     in a product, an acknowledgment in the product documentation would be
 
15
     appreciated but is not required.
 
16
  2. Altered source versions must be plainly marked as such, and must not be
 
17
     misrepresented as being the original software.
 
18
  3. This notice may not be removed or altered from any source distribution.
 
19
 
 
20
  Jeroen Frijters
 
21
  jeroen@frijters.net
 
22
  
 
23
 */
 
24
package sun.jdbc.odbc;
 
25
 
 
26
import java.sql.*;
 
27
 
 
28
import cli.System.Data.*;
 
29
import cli.System.Data.Odbc.*;
 
30
 
 
31
/**
 
32
 * @author Volker Berlin
 
33
 */
 
34
public class JdbcOdbcUpdateableResultSet extends JdbcOdbcDTResultSet{
 
35
 
 
36
    private final OdbcDataAdapter da;
 
37
 
 
38
    private final DataTable data;
 
39
 
 
40
    private DataRow insertRow;
 
41
 
 
42
 
 
43
    public JdbcOdbcUpdateableResultSet(OdbcCommand cmd){
 
44
        this(new DataTable(), cmd);
 
45
    }
 
46
 
 
47
 
 
48
    private JdbcOdbcUpdateableResultSet(DataTable data, OdbcCommand cmd){
 
49
        super(data, CONCUR_UPDATABLE);
 
50
        this.data = data;
 
51
        da = new OdbcDataAdapter(cmd);
 
52
        da.Fill(data);
 
53
        OdbcCommandBuilder cmdBldr = new OdbcCommandBuilder(da);
 
54
        cmdBldr.GetUpdateCommand(); // throw an exception if update is not possible, we want a very early exception
 
55
    }
 
56
 
 
57
 
 
58
    @Override
 
59
    protected DataRow getDataRow() throws SQLException{
 
60
        if(insertRow != null){
 
61
            return insertRow;
 
62
        }
 
63
        return super.getDataRow();
 
64
    }
 
65
 
 
66
 
 
67
    @Override
 
68
    protected void setDataRow() throws SQLException{
 
69
        insertRow = null;
 
70
        super.setDataRow();
 
71
    }
 
72
 
 
73
 
 
74
    @Override
 
75
    public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException{
 
76
        try{
 
77
            x = JdbcOdbcUtils.convertJava2Net(x, scaleOrLength);
 
78
            getDataRow().set_Item(columnIndex - 1, x);
 
79
        }catch(ArrayIndexOutOfBoundsException ex){
 
80
            throw new SQLException("Invalid column number (" + columnIndex + "). A number between 1 and "
 
81
                    + data.get_Columns().get_Count() + " is valid.", "S1002", ex);
 
82
        }
 
83
    }
 
84
 
 
85
 
 
86
    @Override
 
87
    public void updateRow() throws SQLException{
 
88
        if(insertRow != null){
 
89
            throw new SQLException("Cursor is on the insert row.");
 
90
        }
 
91
        try{
 
92
            da.Update(data);
 
93
        }catch(Throwable th){
 
94
            throw JdbcOdbcUtils.createSQLException(th);
 
95
        }
 
96
    }
 
97
 
 
98
 
 
99
    @Override
 
100
    public void deleteRow() throws SQLException{
 
101
        if(insertRow != null){
 
102
            throw new SQLException("Cursor is on the insert row.");
 
103
        }
 
104
        try{
 
105
            getDataRow().Delete(); // Delete the current row
 
106
            da.Update(data);
 
107
            setDataRow(); // set a new Current Row
 
108
        }catch(Throwable th){
 
109
            throw JdbcOdbcUtils.createSQLException(th);
 
110
        }
 
111
    }
 
112
 
 
113
 
 
114
    @Override
 
115
    public void insertRow() throws SQLException{
 
116
        if(insertRow == null){
 
117
            throw new SQLException("Cursor is not on the insert row.");
 
118
        }
 
119
        try{
 
120
            getRows().Add(insertRow);
 
121
            insertRow = null;
 
122
            da.Update(data);
 
123
            last();
 
124
        }catch(Throwable th){
 
125
            throw JdbcOdbcUtils.createSQLException(th);
 
126
        }
 
127
 
 
128
    }
 
129
 
 
130
 
 
131
    @Override
 
132
    public void moveToInsertRow(){
 
133
        insertRow = data.NewRow();
 
134
    }
 
135
 
 
136
 
 
137
    @Override
 
138
    public void moveToCurrentRow(){
 
139
        insertRow = null;
 
140
    }
 
141
 
 
142
 
 
143
    @Override
 
144
    public void cancelRowUpdates() throws SQLException{
 
145
        getDataRow().CancelEdit();
 
146
    }
 
147
 
 
148
 
 
149
    @Override
 
150
    public boolean rowDeleted(){
 
151
        return false;
 
152
    }
 
153
 
 
154
 
 
155
    @Override
 
156
    public boolean rowInserted(){
 
157
        return false;
 
158
    }
 
159
 
 
160
 
 
161
    @Override
 
162
    public boolean rowUpdated(){
 
163
        return false;
 
164
    }
 
165
}