diff --git a/src/main/java/org/jenkinsci/plugins/database/GenericDatabase.java b/src/main/java/org/jenkinsci/plugins/database/GenericDatabase.java index 65d23f5..42ca8d8 100644 --- a/src/main/java/org/jenkinsci/plugins/database/GenericDatabase.java +++ b/src/main/java/org/jenkinsci/plugins/database/GenericDatabase.java @@ -6,11 +6,15 @@ import jenkins.model.Jenkins; import org.apache.tools.ant.AntClassLoader; import org.kohsuke.stapler.DataBoundConstructor; +import org.kohsuke.stapler.DataBoundSetter; import org.kohsuke.stapler.QueryParameter; +import javax.annotation.Nonnull; +import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.sql.DataSource; import java.io.File; +import java.io.IOException; import java.sql.SQLException; import org.kohsuke.stapler.verb.POST; @@ -25,6 +29,11 @@ public class GenericDatabase extends Database { public final Secret password; public final String url; + private Integer initialSize = DescriptorImpl.defaultInitialSize; + private Integer maxTotal = DescriptorImpl.defaultMaxTotal; + private Integer maxIdle = DescriptorImpl.defaultMaxIdle; + private Integer minIdle = DescriptorImpl.defaultMinIdle; + private transient DataSource source; @DataBoundConstructor @@ -35,6 +44,46 @@ public GenericDatabase(String url, String driver, String username, Secret passwo this.password = password; } + @Nonnull + public Integer getInitialSize() { + return initialSize; + } + + @DataBoundSetter + public void setInitialSize(final Integer initialSize) { + this.initialSize = initialSize == null ? DescriptorImpl.defaultInitialSize : initialSize; + } + + @Nonnull + public Integer getMaxTotal() { + return maxTotal; + } + + @DataBoundSetter + public void setMaxTotal(final Integer maxTotal) { + this.maxTotal = maxTotal == null ? DescriptorImpl.defaultMaxTotal : maxTotal; + } + + @Nonnull + public Integer getMaxIdle() { + return maxIdle; + } + + @DataBoundSetter + public void setMaxIdle(final Integer maxIdle) { + this.maxIdle = maxIdle == null ? DescriptorImpl.defaultMaxIdle : maxIdle; + } + + @Nonnull + public Integer getMinIdle() { + return minIdle; + } + + @DataBoundSetter + public void setMinIdle(final Integer minIdle) { + this.minIdle = minIdle == null ? DescriptorImpl.defaultMinIdle : minIdle; + } + @Override public synchronized DataSource getDataSource() throws SQLException { if (source==null) { @@ -44,6 +93,10 @@ public synchronized DataSource getDataSource() throws SQLException { source.setUrl(url); source.setUsername(username); source.setPassword(Secret.toString(password)); + source.setInitialSize(initialSize); + source.setMaxTotal(maxTotal); + source.setMaxIdle(maxIdle); + source.setMinIdle(minIdle); this.source = source.createDataSource(); } return source; @@ -58,6 +111,11 @@ public DescriptorImpl getDescriptor() { public static class DescriptorImpl extends DatabaseDescriptor { private transient AntClassLoader loader; + public static final Integer defaultInitialSize = 0; + public static final Integer defaultMaxTotal = 8; + public static final Integer defaultMaxIdle = 8; + public static final Integer defaultMinIdle = 0; + @Override public String getDisplayName() { return "Generic"; @@ -86,7 +144,7 @@ private synchronized ClassLoader getClassLoader() { @POST public FormValidation doCheckDriver(@QueryParameter String value) { Jenkins.get().checkPermission(Jenkins.ADMINISTER); - + if (value.length()==0) return FormValidation.ok(); // no value typed yet. diff --git a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/config.groovy b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/config.groovy index 12ae0c7..cd326e3 100644 --- a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/config.groovy +++ b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/config.groovy @@ -14,6 +14,20 @@ f.entry(field:"username",title:_("User Name")) { f.entry(field:"password",title:_("Password")) { f.password() } +f.advanced { + f.entry(field: "initialSize", title: _("Initial Size")) { + f.number(clazz: "number", min: 0, max: 65535, step: 1, default: "${descriptor.defaultInitialSize}") + } + f.entry(field: "maxTotal", title: _("Max Total")) { + f.number(clazz: "number", min: -1, max: 65535, step: 1, default: "${descriptor.defaultMaxTotal}") + } + f.entry(field: "maxIdle", title: _("Max Idle")) { + f.number(clazz: "number", min: -1, max: 65535, step: 1, default: "${descriptor.defaultMaxIdle}") + } + f.entry(field: "minIdle", title: _("Min Idle")) { + f.number(clazz: "number", min: 0, max: 65535, step: 1, default: "${descriptor.defaultMinIdle}") + } +} f.block() { f.validateButton(method:"validate",title:_("Test Connection"),with:"driver,url,username,password") } \ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-initialSize.html b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-initialSize.html new file mode 100644 index 0000000..71af7e0 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-initialSize.html @@ -0,0 +1,3 @@ +
+ The initial number of connections that are created when the pool is started. +
\ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxIdle.html b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxIdle.html new file mode 100644 index 0000000..e76a875 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxIdle.html @@ -0,0 +1,3 @@ +
+ The maximum number of connections that can remain idle in the pool, without extra ones being released, or negative for no limit. +
\ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxTotal.html b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxTotal.html new file mode 100644 index 0000000..ee9bd43 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-maxTotal.html @@ -0,0 +1,3 @@ +
+ The maximum number of active connections that can be allocated from this pool at the same time, or negative for no limit. +
\ No newline at end of file diff --git a/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-minIdle.html b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-minIdle.html new file mode 100644 index 0000000..359dd49 --- /dev/null +++ b/src/main/resources/org/jenkinsci/plugins/database/GenericDatabase/help-minIdle.html @@ -0,0 +1,3 @@ +
+ The minimum number of connections that can remain idle in the pool, without extra ones being created, or zero to create none. +
\ No newline at end of file