Search in sources :

Example 11 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestSQLException method testCodeAsVendorCode.

@Test
public void testCodeAsVendorCode() {
    // $NON-NLS-1$
    TeiidException sqlexception = new TeiidException(Event.TEIID21, "foo");
    // $NON-NLS-1$
    String message = "top level message";
    TeiidSQLException exception = TeiidSQLException.create(sqlexception, message);
    assertEquals(sqlexception.getCode(), exception.getTeiidCode());
    assertEquals(21, exception.getErrorCode());
}
Also used : TeiidException(org.teiid.core.TeiidException) Test(org.junit.Test)

Example 12 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestSQLException method testCreateThrowable_01.

/*
	 * Test method for 'com.metamatrix.jdbc.MMSQLException.create(Throwable)'
	 * 
	 * Tests various simple exceptions to see if the expected SQLState is
	 * returend.
	 */
@Test
public void testCreateThrowable_01() {
    testCreateThrowable(new CommunicationException(// $NON-NLS-1$
    "A test MM Communication Exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new ConnectionException("A test MM Connection Exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new IOException(// $NON-NLS-1$
    "A test Generic java.io.IOException"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(new MalformedURLException(// $NON-NLS-1$
    "A test java.net.MalformedURLException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(new TeiidException("A test Generic MM Core Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(// $NON-NLS-1$
    new TeiidException("A test MM Exception"), SQLStates.DEFAULT);
    testCreateThrowable(new TeiidProcessingException(// $NON-NLS-1$
    "A test Generic MM Query Processing Exception"), SQLStates.USAGE_ERROR);
    testCreateThrowable(new TeiidRuntimeException("A test MM Runtime Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new TeiidSQLException("A test Generic MM SQL Exception"), // $NON-NLS-1$
    SQLStates.DEFAULT);
    testCreateThrowable(new NoRouteToHostException(// $NON-NLS-1$
    "A test java.net.NoRouteToHostException"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new NullPointerException("A test NPE"), SQLStates.DEFAULT);
    testCreateThrowable(new ProcedureErrorInstructionException(// $NON-NLS-1$
    "A test SQL Procedure Error exception"), SQLStates.VIRTUAL_PROCEDURE_ERROR);
    testCreateThrowable(new SocketTimeoutException(// $NON-NLS-1$
    "A test socket timeout exception"), SQLStates.CONNECTION_EXCEPTION_STALE_CONNECTION);
    testCreateThrowable(// $NON-NLS-1$
    new UnknownHostException("A test connection attempt exception"), SQLStates.CONNECTION_EXCEPTION_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION);
}
Also used : MalformedURLException(java.net.MalformedURLException) CommunicationException(org.teiid.net.CommunicationException) UnknownHostException(java.net.UnknownHostException) ProcedureErrorInstructionException(org.teiid.client.ProcedureErrorInstructionException) IOException(java.io.IOException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) NoRouteToHostException(java.net.NoRouteToHostException) TeiidException(org.teiid.core.TeiidException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) SocketTimeoutException(java.net.SocketTimeoutException) ConnectionException(org.teiid.net.ConnectionException) ConnectException(java.net.ConnectException) Test(org.junit.Test)

Example 13 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class SocketServerConnection method connect.

private ILogon connect(HostInfo hostInfo) throws CommunicationException, IOException {
    hostInfo.setSsl(secure);
    this.serverInstance = connectionFactory.getServerInstance(hostInfo);
    this.logonResult = logonResults.get(hostInfo);
    ILogon newLogon = this.serverInstance.getService(ILogon.class);
    if (this.logonResult != null) {
        try {
            newLogon.assertIdentity(logonResult.getSessionToken());
        } catch (TeiidException e) {
            // session is no longer valid
            disconnect();
        }
    }
    return newLogon;
}
Also used : ILogon(org.teiid.client.security.ILogon) TeiidException(org.teiid.core.TeiidException)

Example 14 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class SocketServerConnectionFactory method getConnection.

/**
 * @param connectionProperties will be updated with additional information before logon
 */
public SocketServerConnection getConnection(Properties connectionProperties) throws CommunicationException, ConnectionException {
    TeiidURL url;
    try {
        url = new TeiidURL(connectionProperties.getProperty(TeiidURL.CONNECTION.SERVER_URL));
    } catch (MalformedURLException e1) {
        throw new ConnectionException(JDBCPlugin.Event.TEIID20014, e1, e1.getMessage());
    }
    String discoveryStrategyName = connectionProperties.getProperty(TeiidURL.CONNECTION.DISCOVERY_STRATEGY, URL);
    ServerDiscovery discovery;
    if (URL.equalsIgnoreCase(discoveryStrategyName)) {
        discovery = new UrlServerDiscovery();
    } else {
        try {
            discovery = (ServerDiscovery) ReflectionHelper.create(discoveryStrategyName, null, this.getClass().getClassLoader());
        } catch (TeiidException e) {
            throw new ConnectionException(e);
        }
    }
    discovery.init(url, connectionProperties);
    return new SocketServerConnection(this, url.isUsingSSL(), discovery, connectionProperties);
}
Also used : MalformedURLException(java.net.MalformedURLException) TeiidURL(org.teiid.net.TeiidURL) ConnectionException(org.teiid.net.ConnectionException) TeiidException(org.teiid.core.TeiidException)

Example 15 with TeiidException

use of org.teiid.core.TeiidException in project teiid by teiid.

the class TestExceptionHolder method testSourceWarning.

@Test
public void testSourceWarning() throws Exception {
    // $NON-NLS-1$
    ClassLoader cl = new URLClassLoader(new URL[] { UnitTestUtil.getTestDataFile("test.jar").toURI().toURL() });
    ArrayList<String> args = new ArrayList<String>();
    // $NON-NLS-1$
    args.add("Unknown Exception");
    // $NON-NLS-1$
    Exception obj = (Exception) ReflectionHelper.create("test.UnknownException", args, cl);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(new ExceptionHolder(new SourceWarning("x", "y", obj, true)));
    oos.flush();
    ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
    ExceptionHolder holder = (ExceptionHolder) ois.readObject();
    SourceWarning sw = (SourceWarning) holder.getException();
    assertEquals(sw.getConnectorBindingName(), "y");
    assertEquals(sw.getModelName(), "x");
    assertTrue(sw.isPartialResultsError());
    try {
        ois = new ObjectInputStream(new FileInputStream(UnitTestUtil.getTestDataFile("old-exceptionholder.ser")));
        holder = (ExceptionHolder) ois.readObject();
        assertTrue(holder.getException() instanceof TeiidException);
    } finally {
        ois.close();
    }
}
Also used : SourceWarning(org.teiid.client.SourceWarning) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidException(org.teiid.core.TeiidException) IOException(java.io.IOException) SQLException(java.sql.SQLException) TeiidProcessingException(org.teiid.core.TeiidProcessingException) FileInputStream(java.io.FileInputStream) TeiidException(org.teiid.core.TeiidException) ByteArrayInputStream(java.io.ByteArrayInputStream) URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Aggregations

TeiidException (org.teiid.core.TeiidException)85 TeiidRuntimeException (org.teiid.core.TeiidRuntimeException)26 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)13 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)10 SQLException (java.sql.SQLException)9 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)8 BigInteger (java.math.BigInteger)6 Column (org.teiid.metadata.Column)6 Command (org.teiid.query.sql.lang.Command)6 TranslatorException (org.teiid.translator.TranslatorException)6 IOException (java.io.IOException)5 TeiidProcessingException (org.teiid.core.TeiidProcessingException)5 List (java.util.List)4 EdmEntityType (org.apache.olingo.commons.api.edm.EdmEntityType)4 ODataApplicationException (org.apache.olingo.server.api.ODataApplicationException)4 TeiidComponentException (org.teiid.core.TeiidComponentException)4 UpdateResponse (org.teiid.odata.api.UpdateResponse)4 Update (org.teiid.query.sql.lang.Update)4 SocketTimeoutException (java.net.SocketTimeoutException)3