Search in sources :

Example 11 with TeiidSQLException

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;
    }
}
Also used : Array(java.sql.Array) Blob(java.sql.Blob) ResultSetImpl(org.teiid.jdbc.ResultSetImpl) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) ArrayImpl(org.teiid.core.types.ArrayImpl) Reader(java.io.Reader) StreamCorruptedException(java.io.StreamCorruptedException)

Example 12 with TeiidSQLException

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());
}
Also used : SQLException(java.sql.SQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) TeiidSQLException(org.teiid.jdbc.TeiidSQLException)

Example 13 with TeiidSQLException

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);
    }
}
Also used : SocketServerConnectionFactory(org.teiid.net.socket.SocketServerConnectionFactory) CommunicationException(org.teiid.net.CommunicationException) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) TeiidSQLException(org.teiid.jdbc.TeiidSQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ConnectionProfile(org.teiid.jdbc.ConnectionProfile) ConnectionImpl(org.teiid.jdbc.ConnectionImpl) Properties(java.util.Properties) TeiidDriver(org.teiid.jdbc.TeiidDriver) AutoGenDataService(org.teiid.dqp.service.AutoGenDataService) ConnectionException(org.teiid.net.ConnectionException) Test(org.junit.Test)

Aggregations

TeiidSQLException (org.teiid.jdbc.TeiidSQLException)13 Test (org.junit.Test)8 SQLException (java.sql.SQLException)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 TeiidProcessingException (org.teiid.core.TeiidProcessingException)3 Statement (java.sql.Statement)2 QueryValidatorException (org.teiid.api.exception.query.QueryValidatorException)2 BlockedException (org.teiid.common.buffer.BlockedException)2 TeiidComponentException (org.teiid.core.TeiidComponentException)2 ConnectionImpl (org.teiid.jdbc.ConnectionImpl)2 TeiidDriver (org.teiid.jdbc.TeiidDriver)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)2 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 Reader (java.io.Reader)1 StreamCorruptedException (java.io.StreamCorruptedException)1 Array (java.sql.Array)1 Blob (java.sql.Blob)1