@@ -85,7 +85,7 @@ trait JdbcBackend extends RelationalBackend {
8585 /** Create a Database based on a DataSource.
8686 *
8787 * @param ds The DataSource to use.
88- * @param maxConnection The maximum number of connections that the DataSource can provide. This is necessary to
88+ * @param maxConnections The maximum number of connections that the DataSource can provide. This is necessary to
8989 * prevent deadlocks when scheduling database actions. Use `None` if there is no hard limit.
9090 * @param executor The AsyncExecutor for scheduling database actions.
9191 * @param keepAliveConnection If this is set to true, one extra connection will be opened as soon as the database
@@ -97,18 +97,25 @@ trait JdbcBackend extends RelationalBackend {
9797
9898 /** Create a Database based on the JNDI name of a DataSource.
9999 *
100- * @param ds The name of the DataSource to use.
101- * @param maxConnection The maximum number of connections that the DataSource can provide. This is necessary to
100+ * @param name The name of the DataSource to use.
101+ * @param maxConnections The maximum number of connections that the DataSource can provide. This is necessary to
102102 * prevent deadlocks when scheduling database actions. Use `None` if there is no hard limit.
103103 * @param executor The AsyncExecutor for scheduling database actions.
104104 */
105- def forName (name : String , maxConnections : Option [Int ], executor : AsyncExecutor = null ) = new InitialContext ().lookup(name) match {
106- case ds : DataSource => forDataSource(ds, maxConnections, executor match {
107- case null => AsyncExecutor .default(name)
108- case e => e
109- })
110- case x => throw new SlickException (" Expected a DataSource for JNDI name " + name+ " , but got " + x)
111- }
105+ def forName (name : String , maxConnections : Option [Int ], executor : AsyncExecutor = null ) =
106+ new InitialContext ().lookup(name) match {
107+
108+ case ds : DataSource =>
109+ val configuredExecutor =
110+ (executor, maxConnections) match {
111+ case (null , Some (maxConnec)) => AsyncExecutor .default(name, maxConnec)
112+ case (null , None ) => AsyncExecutor .default(name)
113+ case (e, _) => e
114+ }
115+ forDataSource(ds, maxConnections, configuredExecutor)
116+
117+ case x => throw new SlickException (" Expected a DataSource for JNDI name " + name+ " , but got " + x)
118+ }
112119
113120 /** Create a Database that uses the DriverManager to open new connections. */
114121 def forURL (url : String , user : String = null , password : String = null , prop : Properties = null , driver : String = null ,
@@ -287,7 +294,7 @@ trait JdbcBackend extends RelationalBackend {
287294 val source = JdbcDataSource .forConfig(usedConfig, driver, path, classLoader)
288295 val poolName = usedConfig.getStringOr(" poolName" , path)
289296 val numThreads = usedConfig.getIntOr(" numThreads" , 20 )
290- val maxConnections = source.maxConnections.fold (numThreads)(identity )
297+ val maxConnections = source.maxConnections.getOrElse (numThreads)
291298 val registerMbeans = usedConfig.getBooleanOr(" registerMbeans" , false )
292299 val executor = AsyncExecutor (poolName, numThreads, numThreads, usedConfig.getIntOr(" queueSize" , 1000 ),
293300 maxConnections, registerMbeans = registerMbeans)
0 commit comments