use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class PgBackendProtocol method getContent.
private void getContent(ResultSet rs, PgColInfo col, int column) throws SQLException, TeiidSQLException, IOException {
switch(col.type) {
case PG_TYPE_BOOL:
boolean b = rs.getBoolean(column);
if (!rs.wasNull()) {
// $NON-NLS-1$ //$NON-NLS-2$
writer.write(b ? "t" : "f");
}
break;
case PG_TYPE_BPCHAR:
case PG_TYPE_DATE:
case PG_TYPE_FLOAT4:
case PG_TYPE_FLOAT8:
case PG_TYPE_INT2:
case PG_TYPE_INT4:
case PG_TYPE_INT8:
case PG_TYPE_NUMERIC:
case PG_TYPE_TIME:
case PG_TYPE_TIMESTAMP_NO_TMZONE:
case PG_TYPE_VARCHAR:
String value = rs.getString(column);
if (value != null) {
writer.write(value);
}
break;
case PG_TYPE_GEOMETRY:
Object val = rs.getObject(column);
if (val != null) {
Blob blob = GeometryUtils.geometryToEwkb((GeometryType) rs.unwrap(ResultSetImpl.class).getRawCurrentValue());
String hexewkb = PropertiesUtils.toHex(blob.getBytes(1, (int) blob.length()));
writer.write(hexewkb);
}
break;
case PG_TYPE_XML:
case PG_TYPE_TEXT:
Reader r = rs.getCharacterStream(column);
if (r != null) {
try {
ObjectConverterUtil.write(writer, r, this.maxLobSize, false);
} finally {
r.close();
}
}
break;
case PG_TYPE_BYTEA:
Blob blob = rs.getBlob(column);
if (blob != null) {
try {
String blobString = PGbytea.toPGString(ObjectConverterUtil.convertToByteArray(blob.getBinaryStream(), this.maxLobSize));
writer.write(blobString);
} catch (OutOfMemoryError e) {
// $NON-NLS-1$
throw new StreamCorruptedException("data too big: " + e.getMessage());
}
}
break;
case PG_TYPE_CHARARRAY:
case PG_TYPE_TEXTARRAY:
case PG_TYPE_OIDARRAY:
case PG_TYPE_BOOLARRAY:
case PG_TYPE_INT2ARRAY:
case PG_TYPE_INT4ARRAY:
case PG_TYPE_INT8ARRAY:
case PG_TYPE_FLOAT4ARRAY:
case PG_TYPE_FLOAT8ARRAY:
case PG_TYPE_NUMERICARRAY:
case PG_TYPE_DATEARRAY:
case PG_TYPE_TIMEARRAY:
case PG_TYPE_TIMESTAMP_NO_TMZONEARRAY:
{
Array obj = rs.getArray(column);
if (obj != null) {
writer.append("{");
boolean first = true;
Object array = obj.getArray();
int length = java.lang.reflect.Array.getLength(array);
for (int i = 0; i < length; i++) {
if (!first) {
writer.append(",");
} else {
first = false;
}
Object o = java.lang.reflect.Array.get(array, i);
if (o != null) {
if (col.type == PG_TYPE_TEXTARRAY) {
escapeQuote(writer, o.toString());
} else {
writer.append(o.toString());
}
}
}
writer.append("}");
}
}
break;
case PG_TYPE_INT2VECTOR:
case PG_TYPE_OIDVECTOR:
{
ArrayImpl obj = (ArrayImpl) rs.getObject(column);
if (obj != null) {
boolean first = true;
for (Object o : obj.getValues()) {
if (!first) {
writer.append(" ");
} else {
first = false;
}
if (o != null) {
writer.append(o.toString());
} else {
writer.append('0');
}
}
}
}
break;
default:
Object obj = rs.getObject(column);
if (obj != null) {
throw new TeiidSQLException("unknown datatype " + col.type + " failed to convert");
}
break;
}
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestResultSetUtil method printThrowable.
public static void printThrowable(Throwable t, String sql, PrintStream out) {
out.println(sql);
Throwable answer = t;
if (t instanceof TeiidSQLException) {
TeiidSQLException sqle = (TeiidSQLException) t;
SQLException se = sqle.getNextException();
if (se != null) {
SQLException s = null;
while ((s = se.getNextException()) != null) {
se = s;
}
answer = se;
}
}
// $NON-NLS-1$
out.print(t.getClass().getName() + " : " + answer.getMessage());
}
use of org.teiid.jdbc.TeiidSQLException in project teiid by teiid.
the class TestJDBCSocketTransport method testSyncTimeout.
/**
* Tests to ensure that a SynchronousTtl/synchTimeout does
* not cause a cancel.
* TODO: had to increase the values since the test would fail on slow machine runs
* @throws Exception
*/
@Test
public void testSyncTimeout() throws Exception {
TeiidDriver td = new TeiidDriver();
td.setSocketProfile(new ConnectionProfile() {
@Override
public ConnectionImpl connect(String url, Properties info) throws TeiidSQLException {
SocketServerConnectionFactory sscf = new SocketServerConnectionFactory();
sscf.initialize(info);
try {
return new ConnectionImpl(sscf.getConnection(info), info, url);
} catch (CommunicationException e) {
throw TeiidSQLException.create(e);
} catch (ConnectionException e) {
throw TeiidSQLException.create(e);
}
}
});
Properties p = new Properties();
p.setProperty("user", "testuser");
p.setProperty("password", "testpassword");
ConnectorManagerRepository cmr = server.getConnectorManagerRepository();
AutoGenDataService agds = new AutoGenDataService() {
@Override
public Object getConnectionFactory() throws TranslatorException {
return null;
}
};
// wait longer than the synch ttl/soTimeout, we should still succeed
agds.setSleep(2000);
cmr.addConnectorManager("source", agds);
try {
conn = td.connect("jdbc:teiid:parts@mm://" + addr.getHostName() + ":" + jdbcTransport.getPort(), p);
Statement s = conn.createStatement();
assertTrue(s.execute("select * from parts"));
} finally {
server.setConnectorManagerRepository(cmr);
}
}
Aggregations