Package org.mule.module.db.internal.domain.database

Examples of org.mule.module.db.internal.domain.database.DbConfig


    @Override
    public MuleEvent process(MuleEvent muleEvent) throws MuleException
    {
        DbConnection connection = null;

        DbConfig dbConfig = dbConfigResolver.resolve(muleEvent);

        try
        {
            connection = dbConfig.getConnectionFactory().createConnection(transactionalAction);

            Object result = executeQuery(connection, muleEvent);

            if (mustCloseConnection())
            {
                try
                {
                    dbConfig.getConnectionFactory().releaseConnection(connection);
                }
                finally
                {
                    connection = null;
                }
            }

            if (target == null || "".equals(target) || "#[payload]".equals(target))
            {
                muleEvent.getMessage().setPayload(result);
            }
            else
            {
                muleContext.getExpressionManager().enrich(target, muleEvent, result);
            }

            return processNext(muleEvent);
        }
        catch (SQLException e)
        {
            throw new MessagingException(muleEvent, e);
        }
        finally
        {
            if (connection != null && mustCloseConnection())
            {
                dbConfig.getConnectionFactory().releaseConnection(connection);
            }
        }
    }
View Full Code Here


    private Result<MetaData> getMetaDataResult(Query query, MetadataResolver metadataResolver)
    {
        DbConnection connection = null;

        DbConfig dbConfig = dbConfigResolver.resolve(null);

        try
        {
            try
            {
                connection = dbConfig.getConnectionFactory().createConnection(TransactionalAction.NOT_SUPPORTED);
            }
            catch (SQLException e)
            {
                return new DefaultResult<MetaData>(null, Result.Status.FAILURE, e.getMessage(), FailureType.CONNECTION_FAILURE, e);
            }

            PreparedStatement preparedStatement;
            try
            {
                preparedStatement = connection.prepareStatement(query.getQueryTemplate().getSqlText());
            }
            catch (SQLException e)
            {
                return new DefaultResult<MetaData>(null, Result.Status.FAILURE, e.getMessage(), FailureType.INVALID_CONFIGURATION, e);
            }

            return metadataResolver.resolveMetaData(preparedStatement, query);
        }
        finally
        {
            dbConfig.getConnectionFactory().releaseConnection(connection);
        }
    }
View Full Code Here

    private final MuleEvent muleEvent = mock(MuleEvent.class);

    @Test
    public void resolvesDefaultDbConfig() throws Exception
    {
        DbConfig dbConfig = mock(DbConfig.class);

        MuleRegistry registry = mock(MuleRegistry.class);
        Collection<DbConfig> foundDbConfigs = new ArrayList<DbConfig>();
        foundDbConfigs.add(dbConfig);

        when(registry.lookupObjects(DbConfig.class)).thenReturn(foundDbConfigs);
        DefaultDbConfigResolver dbConfigResolver = new DefaultDbConfigResolver(registry);

        DbConfig resolvedDbConfig = dbConfigResolver.resolve(muleEvent);

        assertThat(dbConfig, sameInstance(resolvedDbConfig));
    }
View Full Code Here

    }

    @Test
    public void throwsErrorWhenMultipleDbConfigAvailable() throws Exception
    {
        DbConfig dbConfig1 = mock(DbConfig.class);
        when(dbConfig1.getName()).thenReturn("dbConfig1");
        DbConfig dbConfig2 = mock(DbConfig.class);
        when(dbConfig2.getName()).thenReturn("dbConfig2");

        MuleRegistry registry = mock(MuleRegistry.class);
        Collection<DbConfig> foundDbConfigs = new ArrayList<DbConfig>();
        foundDbConfigs.add(dbConfig1);
        foundDbConfigs.add(dbConfig2);
View Full Code Here

TOP

Related Classes of org.mule.module.db.internal.domain.database.DbConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.