/**************************************************************
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*************************************************************/
package ifc.sdbc;
import java.util.Vector;
import lib.MultiMethodTest;
import com.sun.star.io.XDataInputStream;
import com.sun.star.io.XInputStream;
import com.sun.star.io.XTextInputStream;
import com.sun.star.sdbc.SQLException;
import com.sun.star.sdbc.XArray;
import com.sun.star.sdbc.XBlob;
import com.sun.star.sdbc.XClob;
import com.sun.star.sdbc.XRef;
import com.sun.star.sdbc.XRow;
import com.sun.star.util.Date;
import com.sun.star.util.DateTime;
import com.sun.star.util.Time;
/**
* Testing com.sun.star.sdbc.XRow
* interface methods :
*
* wasNull()
* getString()
* getBoolean()
* getByte()
* getShort()
* getInt()
* getLong()
* getFloat()
* getDouble()
* getBytes()
* getDate()
* getTime()
* getTimestamp()
* getBinaryStream()
* getCharacterStream()
* getObject()
* getRef()
* getBlob()
* getClob()
* getArray()
*
*
* This interface is full tested in XRowUpdate interface test. Here
* only exceptions checked.
*
*
* Object relations required :
*
* @see com.sun.star.sdbc.XRaw
* @see ifc.sdbc._XRowUpdate
*/
public class _XRow extends MultiMethodTest {
// oObj filled by MultiMethodTest
public XRow oObj = null ;
private Vector data = null ;
private boolean notNullRes = true ;
/**
* Retrieves object relation first.
*/
public void before() {
data = (Vector) tEnv.getObjRelation("CurrentRowData") ;
}
/**
* Always has OK status.
*/
public void _wasNull() {
executeMethod("getString()") ;
executeMethod("getBoolean()") ;
executeMethod("getByte()") ;
executeMethod("getShort()") ;
executeMethod("getInt()") ;
executeMethod("getLong()") ;
executeMethod("getFloat()") ;
executeMethod("getDouble()") ;
executeMethod("getBytes()") ;
executeMethod("getDate()") ;
executeMethod("getTime()") ;
executeMethod("getTimestamp()") ;
executeMethod("getBinaryStream()") ;
executeMethod("getCharacterStream()") ;
executeMethod("getObject()") ;
executeMethod("getRef()") ;
executeMethod("getBlob()") ;
executeMethod("getClob()") ;
executeMethod("getArray()") ;
tRes.tested("wasNull()", notNullRes) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getString() {
boolean result = true ;
int col = findColumnOfType(String.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
String getStr = oObj.getString(col) ;
//result &= ((String)data.get(col - 1)).equals(getStr) ;
//notNullRes &= !oObj.wasNull() ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getString()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getBoolean() {
boolean result = true ;
int col = findColumnOfType(Boolean.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
boolean getVal = oObj.getBoolean(col) ;
//result &= ((Boolean)data.get(col - 1)).booleanValue() == getVal ;
//notNullRes &= !oObj.wasNull() ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getBoolean()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getByte() {
boolean result = true ;
int col = findColumnOfType(Byte.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
byte getVal = oObj.getByte(col) ;
//result &= ((Byte)data.get(col - 1)).byteValue() == getVal ;
//notNullRes &= !oObj.wasNull() ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getByte()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getShort() {
boolean result = true ;
int col = findColumnOfType(Short.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
short getVal = oObj.getShort(col) ;
//result &= ((Short)data.get(col - 1)).shortValue() == getVal ;
//notNullRes &= !oObj.wasNull() ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getShort()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getInt() {
boolean result = true ;
int col = findColumnOfType(Integer.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
int getVal = oObj.getInt(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getInt()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getLong() {
boolean result = true ;
int col = findColumnOfType(Long.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
long getVal = oObj.getLong(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getLong()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getFloat() {
boolean result = true ;
int col = findColumnOfType(Float.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
float getVal = oObj.getFloat(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getFloat()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getDouble() {
boolean result = true ;
int col = findColumnOfType(Double.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
double getVal = oObj.getDouble(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getDouble()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getBytes() {
boolean result = true ;
int col = findColumnOfType(byte[].class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
byte[] getVal = oObj.getBytes(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getBytes()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getDate() {
boolean result = true ;
int col = findColumnOfType(Date.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
Date getVal = oObj.getDate(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getDate()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getTime() {
boolean result = true ;
int col = findColumnOfType(Time.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
Time getVal = oObj.getTime(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getTime()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getTimestamp() {
boolean result = true ;
int col = findColumnOfType(DateTime.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
DateTime getVal = oObj.getTimestamp(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getTimestamp()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getBinaryStream() {
boolean result = true ;
int col = findColumnOfType(XDataInputStream.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XInputStream getVal = oObj.getBinaryStream(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getBinaryStream()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getCharacterStream() {
boolean result = true ;
int col = findColumnOfType(XTextInputStream.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XInputStream getVal = oObj.getCharacterStream(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getCharacterStream()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getObject() {
boolean result = true ;
int col = findColumnOfType(Object[].class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
Object getVal = oObj.getObject(col, null) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getObject()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getRef() {
boolean result = true ;
int col = findColumnOfType(XRef.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XRef getVal = oObj.getRef(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getRef()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getBlob() {
boolean result = true ;
int col = findColumnOfType(XBlob.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XBlob getVal = oObj.getBlob(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getBlob()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getClob() {
boolean result = true ;
int col = findColumnOfType(XClob.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XClob getVal = oObj.getClob(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getClob()", result) ;
}
/**
* Has OK status if no exceptions occurred in method call.
*/
public void _getArray() {
boolean result = true ;
int col = findColumnOfType(XArray.class) ;
if (col < 0) log.println("Type not found in relation: not tested");
else {
try {
XArray getVal = oObj.getArray(col) ;
} catch (SQLException e) {
log.println("Unexpected SQL exception:") ;
log.println(e) ;
result = false ;
}
}
tRes.tested("getArray()", result) ;
}
/**
* Finds in relation vector index of column of the appropriate
* type.
*/
protected int findColumnOfType(Class clz) {
for (int i = 0; i < data.size(); i++)
if (clz.isInstance(data.get(i))) return i + 1 ;
return -1 ;
}
} // finish class _XRow