Datasource Overview

It is just reference Services.

Usage Example

services.xml

<?xml version="1.0" encoding="UTF-8"?>

<services>
	<service id="DataSourceService" 
	  class="sunheart.service.datasource.DBCPDataSourceService" />
</services>          
          

dbcp.xml

<?xml version="1.0" encoding="UTF-8"?>

<dbcp>
	<pool id="default">
		<driver>oracle.jdbc.driver.OracleDriver</driver>
		<dburl>jdbc:oracle:thin:@localhost:1521:ora82</dburl>
		<user>scott</user>
		<password>tiger</password>

		<max>10</max>
		<max_idle>0</max_idle>
		<keep-alive></keep-alive>
		<max_wait>30000</max_wait>
	</pool>
</dbcp>          
          

Java code

package example;

import java.sql.Connection;
import java.sql.SQLException;

import sunheart.service.ServiceManager;
import sunheart.service.datasource.DataSourceService;

/**
 *  
 */
public class DataSourceTest {

    public static void main(String[] args) {
        System.out.println("start");
        // get a default DataSourceService
        Object service = ServiceManager.lookupService(DataSourceService.id);

        if (service != null) {
            DataSourceService ds = (DataSourceService) service;

            try {
                // get default connect;
                Connection conn = ds.getConnection();
                System.out.println(conn);
            } catch (SQLException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            System.out.println("oh no");
        }

        System.out.println("end");
    }
}

          

Result

start
*INFO * [main] ServiceManager: ############################## 
*INFO * [main] ServiceManager: # ServiceManger is creating...........  
*INFO * [main] ServiceManager: use DefaultRepository class 
*INFO * [main] ServiceManager: Daemon set=null 
*INFO * [main] ServiceManager: Regist services is started 
*INFO * [main] ServiceManager: SUCCESS TO CREATE SERVICE:[DataSourceService]=sunheart.service.datasource.DBCPDataSourceService 
*INFO * [main] ServiceManager: Regist services is ended. Success:1, Failure:0 
*INFO * [main] ServiceManager: Daemon set=null 
*INFO * [main] ServiceManager: # ServiceManger is created. Duration(ms)= 3074 
*INFO * [main] ServiceManager: ############################## 
org.apache.commons.dbcp.PoolableConnection@d81784
end
####################
# JVM is killed... 
# Shutdown is started 
Shutdown service ....DataSourceService
# Shutdown is ended
####################