use of org.teiid.core.types.ArrayImpl 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;
}
}
Aggregations