📄 ssresultset.java
字号:
/**
* Test if it on the insert row.
* @throws SQLException if on the insert row
*/
private void testNotInsertRow() throws SQLException{
if(isInsertRow){
throw SmallSQLException.create(Language.RSET_ON_INSERT_ROW);
}
}
public void updateRow() throws SQLException {
try {
if(values == null){
// no changes then also no update needed
return;
}
st.con.log.println("updateRow()");
testNotInsertRow();
final CommandSelect command = getCmd();
command.updateRow( st.con, values);
command.relative(0); //refresh the row
clearRowBuffer();
} catch (Exception e) {
throw SmallSQLException.createFromException(e);
}
}
public void deleteRow() throws SQLException {
st.con.log.println("deleteRow()");
testNotInsertRow();
getCmd().deleteRow(st.con);
clearRowBuffer();
}
public void refreshRow() throws SQLException {
testNotInsertRow();
relative(0);
}
public void cancelRowUpdates() throws SQLException{
testNotInsertRow();
clearRowBuffer();
}
/**
* Clear the update row or insert row buffer.
*/
private void clearRowBuffer(){
if(values != null){
for(int i=values.length-1; i>=0; i--){
values[i].clear();
}
}
}
public void moveToInsertRow() throws SQLException {
if(isUpdatable){
isInsertRow = true;
clearRowBuffer();
}else{
throw SmallSQLException.create(Language.RSET_READONLY);
}
}
public void moveToCurrentRow() throws SQLException{
isInsertRow = false;
clearRowBuffer();
if(values == null){
//init the values array as insert row buffer
getUpdateValue(1);
}
}
public Statement getStatement() {
return st;
}
public Object getObject(int i, Map map) throws SQLException {
return getObject( i );
}
public Ref getRef(int i) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.getRef method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Ref object");
}
public Blob getBlob(int i) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.getBlob method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Blob object");
}
public Clob getClob(int i) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.getClob method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Clob object");
}
public Array getArray(int i) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.getArray method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Array");
}
public Object getObject(String columnName, Map map) throws SQLException {
return getObject( columnName );
}
public Ref getRef(String columnName) throws SQLException {
return getRef( findColumn( columnName ) );
}
public Blob getBlob(String columnName) throws SQLException {
return getBlob( findColumn( columnName ) );
}
public Clob getClob(String columnName) throws SQLException {
return getClob( findColumn( columnName ) );
}
public Array getArray(String columnName) throws SQLException {
return getArray( findColumn( columnName ) );
}
public Date getDate(int columnIndex, Calendar cal) throws SQLException {
try{
if(cal == null){
return getDate(columnIndex);
}
Expression expr = getValue(columnIndex);
wasNull = expr.isNull();
if(wasNull) return null;
return new Date(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
}catch(Exception e){
throw SmallSQLException.createFromException( e );
}
}
public Date getDate(String columnName, Calendar cal) throws SQLException {
return getDate( findColumn( columnName ), cal );
}
public Time getTime(int columnIndex, Calendar cal) throws SQLException {
try{
if(cal == null){
return getTime(columnIndex);
}
Expression expr = getValue(columnIndex);
wasNull = expr.isNull();
if(wasNull) return null;
return new Time(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
}catch(Exception e){
throw SmallSQLException.createFromException( e );
}
}
public Time getTime(String columnName, Calendar cal) throws SQLException {
return getTime( findColumn( columnName ), cal );
}
public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException {
try{
if(cal == null){
return getTimestamp(columnIndex);
}
Expression expr = getValue(columnIndex);
wasNull = expr.isNull();
if(wasNull) return null;
return new Timestamp(DateTime.addDateTimeOffset( expr.getLong(), cal.getTimeZone() ));
}catch(Exception e){
throw SmallSQLException.createFromException( e );
}
}
public Timestamp getTimestamp(String columnName, Calendar cal) throws SQLException {
return getTimestamp( findColumn( columnName ), cal );
}
public URL getURL(int columnIndex) throws SQLException {
try{
Expression expr = getValue(columnIndex);
wasNull = expr.isNull();
if(wasNull) return null;
return new URL( expr.getString() );
}catch(Exception e){
throw SmallSQLException.createFromException( e );
}
}
public URL getURL(String columnName) throws SQLException {
return getURL( findColumn( columnName ) );
}
public void updateRef(int columnIndex, Ref x) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.updateRef method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Ref");
}
public void updateRef(String columnName, Ref x) throws SQLException {
updateRef( findColumn( columnName ), x );
}
public void updateBlob(int columnIndex, Blob x) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.updateBlob method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Blob");
}
public void updateBlob(String columnName, Blob x) throws SQLException {
updateBlob( findColumn( columnName ), x );
}
public void updateClob(int columnIndex, Clob x) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.updateClob method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Clob");
}
public void updateClob(String columnName, Clob x) throws SQLException {
updateClob( findColumn( columnName ), x );
}
public void updateArray(int columnIndex, Array x) throws SQLException {
/**@todo: Implement this java.sql.ResultSet.updateArray method*/
throw SmallSQLException.create(Language.UNSUPPORTED_OPERATION, "Array");
}
public void updateArray(String columnName, Array x) throws SQLException {
updateArray( findColumn( columnName ), x );
}
/*========================================================
private methods
=========================================================*/
/**
* Get the expression of a column.
* This expression can be used to request a value of the current row.
*/
final private Expression getValue(int columnIndex) throws SQLException{
if(values != null){
ExpressionValue value = values[ metaData.getColumnIdx( columnIndex ) ];
if(!value.isEmpty() || isInsertRow){
return value;
}
}
return metaData.getColumnExpression(columnIndex);
}
final private ExpressionValue getUpdateValue(int columnIndex) throws SQLException{
if(values == null){
int count = metaData.getColumnCount();
values = new ExpressionValue[count];
while(count-- > 0){
values[count] = new ExpressionValue();
}
}
return values[ metaData.getColumnIdx( columnIndex ) ];
}
final private void updateValue(int columnIndex, Object x, int dataType) throws SQLException{
getUpdateValue( columnIndex ).set( x, dataType );
if(st.con.log.isLogging()){
st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType);
}
}
final private void updateValue(int columnIndex, Object x, int dataType, int length) throws SQLException{
getUpdateValue( columnIndex ).set( x, dataType, length );
if(st.con.log.isLogging()){
st.con.log.println("parameter '"+metaData.getColumnName(columnIndex)+"' = "+x+"; type="+dataType+"; length="+length);
}
}
final private CommandSelect getCmd() throws SQLException {
if(cmd == null){
throw SmallSQLException.create(Language.RSET_CLOSED);
}
st.con.testClosedConnection();
return cmd;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -