Anonymous avatar Anonymous committed 3ff7b91

Issue number: QUARTZ-115
Obtained from:
Submitted by:
Reviewed by:
CVS: ----------------------------------------------------------------------
CVS: Issue number:
CVS: If this change addresses one or more issues,
CVS: then enter the issue number(s) here.
CVS: Obtained from:
CVS: If this change has been taken from another system,
CVS: then name the system in this line, otherwise delete it.
CVS: Submitted by:
CVS: If this code has been contributed to the project by someone else; i.e.,
CVS: they sent us a patch or a set of diffs, then include their name/email
CVS: address here. If this is your work then delete this line.
CVS: Reviewed by:
CVS: If we are doing pre-commit code reviews and someone else has
CVS: reviewed your changes, include their name(s) here.
CVS: If you have not had it reviewed then delete this line.

git-svn-id: http://svn.opensymphony.com/svn/quartz/trunk@260 69f7d36a-ea1c-0410-88ea-9fd03e4c9665

Comments (0)

Files changed (1)

src/java/org/quartz/impl/StdSchedulerFactory.java

 import org.quartz.spi.JobStore;
 import org.quartz.spi.SchedulerPlugin;
 import org.quartz.spi.ThreadPool;
+import org.quartz.utils.ConnectionProvider;
 import org.quartz.utils.DBConnectionManager;
 import org.quartz.utils.JNDIConnectionProvider;
 import org.quartz.utils.PoolingConnectionProvider;
 
     public static final String PROP_DATASOURCE_PREFIX = "org.quartz.dataSource";
 
+    public static final String PROP_CONNECTION_PROVIDER_CLASS = "connectionProvider.class";
+
     public static final String PROP_DATASOURCE_DRIVER = "driver";
 
     public static final String PROP_DATASOURCE_URL = "URL";
             PropertiesParser pp = new PropertiesParser(cfg.getPropertyGroup(
                     PROP_DATASOURCE_PREFIX + "." + dsNames[i], true));
 
-            String dsDriver = pp
-                    .getStringProperty(PROP_DATASOURCE_DRIVER, null);
-            String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null);
-            boolean dsAlwaysLookup = pp.getBooleanProperty(
-                    PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false);
-            String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, "");
-            String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, "");
-            int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 10);
-            String dsJndi = pp
-                    .getStringProperty(PROP_DATASOURCE_JNDI_URL, null);
-            String dsJndiInitial = pp.getStringProperty(
-                    PROP_DATASOURCE_JNDI_INITIAL, null);
-            String dsJndiProvider = pp.getStringProperty(
-                    PROP_DATASOURCE_JNDI_PROVDER, null);
-            String dsJndiPrincipal = pp.getStringProperty(
-                    PROP_DATASOURCE_JNDI_PRINCIPAL, null);
-            String dsJndiCredentials = pp.getStringProperty(
-                    PROP_DATASOURCE_JNDI_CREDENTIALS, null);
-            String dsValidation = pp.getStringProperty(
-                    PROP_DATASOURCE_VALIDATION_QUERY, null);
-
-            if (dsJndi != null) {
-                Properties props = null;
-                if (null != dsJndiInitial || null != dsJndiProvider
-                        || null != dsJndiPrincipal || null != dsJndiCredentials) {
-                    props = new Properties();
-                    if (dsJndiInitial != null)
-                            props.put(PROP_DATASOURCE_JNDI_INITIAL,
-                                    dsJndiInitial);
-                    if (dsJndiProvider != null)
-                            props.put(PROP_DATASOURCE_JNDI_PROVDER,
-                                    dsJndiProvider);
-                    if (dsJndiPrincipal != null)
-                            props.put(PROP_DATASOURCE_JNDI_PRINCIPAL,
-                                    dsJndiPrincipal);
-                    if (dsJndiCredentials != null)
-                            props.put(PROP_DATASOURCE_JNDI_CREDENTIALS,
-                                    dsJndiCredentials);
-                }
-                JNDIConnectionProvider cp = new JNDIConnectionProvider(dsJndi,
-                        props, dsAlwaysLookup);
-                dbMgr = DBConnectionManager.getInstance();
-                dbMgr.addConnectionProvider(dsNames[i], cp);
-            } else {
-                if (dsDriver == null) {
-                    initException = new SchedulerException(
-                            "Driver not specified for DataSource: "
-                                    + dsNames[i]);
+            String cpClass = pp.getStringProperty(PROP_CONNECTION_PROVIDER_CLASS, null);
+
+            // custom connectionProvider...
+            if(cpClass != null) {
+                ConnectionProvider cp = null;
+                try {
+                    cp = (ConnectionProvider) loadHelper.loadClass(cpClass).newInstance();
+                } catch (Exception e) {
+                    initException = new SchedulerException("ConnectionProvider class '" + cpClass
+                            + "' could not be instantiated.", e);
+                    initException
+                            .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
                     throw initException;
                 }
-                if (dsURL == null) {
-                    initException = new SchedulerException(
-                            "DB URL not specified for DataSource: "
-                                    + dsNames[i]);
+
+                try {
+                    // remove the class name, so it isn't attempted to be set
+                    pp.getUnderlyingProperties().remove(
+                            PROP_CONNECTION_PROVIDER_CLASS);
+                    
+                    setBeanProps(cp, pp.getUnderlyingProperties());
+                } catch (Exception e) {
+                    initException = new SchedulerException("ConnectionProvider class '" + cpClass
+                            + "' props could not be configured.", e);
+                    initException
+                            .setErrorCode(SchedulerException.ERR_BAD_CONFIGURATION);
                     throw initException;
                 }
-                try {
-                    PoolingConnectionProvider cp = new PoolingConnectionProvider(
-                            dsDriver, dsURL, dsUser, dsPass, dsCnt,
-                            dsValidation);
+
+                dbMgr = DBConnectionManager.getInstance();
+                dbMgr.addConnectionProvider(dsNames[i], cp);
+            }
+            else {
+                String dsDriver = pp
+                .getStringProperty(PROP_DATASOURCE_DRIVER, null);
+                String dsURL = pp.getStringProperty(PROP_DATASOURCE_URL, null);
+                boolean dsAlwaysLookup = pp.getBooleanProperty(
+                        PROP_DATASOURCE_JNDI_ALWAYS_LOOKUP, false);
+                String dsUser = pp.getStringProperty(PROP_DATASOURCE_USER, "");
+                String dsPass = pp.getStringProperty(PROP_DATASOURCE_PASSWORD, "");
+                int dsCnt = pp.getIntProperty(PROP_DATASOURCE_MAX_CONNECTIONS, 10);
+                String dsJndi = pp
+                        .getStringProperty(PROP_DATASOURCE_JNDI_URL, null);
+                String dsJndiInitial = pp.getStringProperty(
+                        PROP_DATASOURCE_JNDI_INITIAL, null);
+                String dsJndiProvider = pp.getStringProperty(
+                        PROP_DATASOURCE_JNDI_PROVDER, null);
+                String dsJndiPrincipal = pp.getStringProperty(
+                        PROP_DATASOURCE_JNDI_PRINCIPAL, null);
+                String dsJndiCredentials = pp.getStringProperty(
+                        PROP_DATASOURCE_JNDI_CREDENTIALS, null);
+                String dsValidation = pp.getStringProperty(
+                        PROP_DATASOURCE_VALIDATION_QUERY, null);
+        
+                if (dsJndi != null) {
+                    Properties props = null;
+                    if (null != dsJndiInitial || null != dsJndiProvider
+                            || null != dsJndiPrincipal || null != dsJndiCredentials) {
+                        props = new Properties();
+                        if (dsJndiInitial != null)
+                                props.put(PROP_DATASOURCE_JNDI_INITIAL,
+                                        dsJndiInitial);
+                        if (dsJndiProvider != null)
+                                props.put(PROP_DATASOURCE_JNDI_PROVDER,
+                                        dsJndiProvider);
+                        if (dsJndiPrincipal != null)
+                                props.put(PROP_DATASOURCE_JNDI_PRINCIPAL,
+                                        dsJndiPrincipal);
+                        if (dsJndiCredentials != null)
+                                props.put(PROP_DATASOURCE_JNDI_CREDENTIALS,
+                                        dsJndiCredentials);
+                    }
+                    JNDIConnectionProvider cp = new JNDIConnectionProvider(dsJndi,
+                            props, dsAlwaysLookup);
                     dbMgr = DBConnectionManager.getInstance();
                     dbMgr.addConnectionProvider(dsNames[i], cp);
-                } catch (SQLException sqle) {
-                    initException = new SchedulerException(
-                            "Could not initialize DataSource: " + dsNames[i],
-                            sqle);
-                    throw initException;
+                } else {
+                    if (dsDriver == null) {
+                        initException = new SchedulerException(
+                                "Driver not specified for DataSource: "
+                                        + dsNames[i]);
+                        throw initException;
+                    }
+                    if (dsURL == null) {
+                        initException = new SchedulerException(
+                                "DB URL not specified for DataSource: "
+                                        + dsNames[i]);
+                        throw initException;
+                    }
+                    try {
+                        PoolingConnectionProvider cp = new PoolingConnectionProvider(
+                                dsDriver, dsURL, dsUser, dsPass, dsCnt,
+                                dsValidation);
+                        dbMgr = DBConnectionManager.getInstance();
+                        dbMgr.addConnectionProvider(dsNames[i], cp);
+                    } catch (SQLException sqle) {
+                        initException = new SchedulerException(
+                                "Could not initialize DataSource: " + dsNames[i],
+                                sqle);
+                        throw initException;
+                    }
                 }
+                
             }
+            
         }
 
         // Set up any SchedulerPlugins
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.