private void initializeDatasourceConnection()

in rdb/src/main/java/org/apache/tuscany/das/rdb/impl/DASImpl.java [175:210]


    private void initializeDatasourceConnection(ConnectionInfo connectionInfo){
        Connection connection = null;

        InitialContext ctx;
        try {
            ctx = new InitialContext();
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
        try {
            DataSource ds = (DataSource) ctx.lookup(connectionInfo.getDataSource());
            try {
            	try {
	            	if(connectionInfo.getConnectionProperties() != null &&
	            	   connectionInfo.getConnectionProperties().getUserName() != null &&
	            	   connectionInfo.getConnectionProperties().getPassword() != null ) {
	            		connection = ds.getConnection(connectionInfo.getConnectionProperties().getUserName(), connectionInfo.getConnectionProperties().getPassword());
	            	} else {
	            		connection = ds.getConnection();
	            	}
            	}catch(Exception e) {
            		connection = ds.getConnection();
            	}

                if (connection == null) {
                    throw new RuntimeException("Could not obtain a Connection from DataSource");
                }
                connection.setAutoCommit(false);
                setConnection(connection);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        } catch (NamingException e) {
            throw new RuntimeException(e);
        }
    }