PageRenderTime 27ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/maven-amps-plugin/src/main/java/com/atlassian/maven/plugins/amps/DataSource.java

https://bitbucket.org/cofarrell/amps
Java | 246 lines | 138 code | 43 blank | 65 comment | 21 complexity | 531ebba7caeb307e4850ea93b5262113 MD5 | raw file
Possible License(s): Apache-2.0
  1. package com.atlassian.maven.plugins.amps;
  2. import java.util.List;
  3. import org.apache.commons.lang.StringUtils;
  4. import com.google.common.collect.Lists;
  5. import static com.google.common.base.Objects.firstNonNull;
  6. /**
  7. * Definition of a datasource.
  8. * For more information about the properties, see http://cargo.codehaus.org/DataSource+and+Resource+Support
  9. * @since 3.11
  10. */
  11. public class DataSource
  12. {
  13. /**
  14. * Connection url, such as "jdbc:hsqldb:/path/to/database"
  15. */
  16. private String url;
  17. /**
  18. * Driver, such as "org.hsqldb.jdbcDriver"
  19. */
  20. private String driver;
  21. /**
  22. * Username, e.g. "sa"
  23. */
  24. private String username;
  25. /**
  26. * Password. May be empty.
  27. */
  28. private String password;
  29. /**
  30. * JNDI name, such as jdbc/JiraDS
  31. */
  32. private String jndi;
  33. /**
  34. * Type of driver: "java.sql.Driver" or "javax.sql.XSDataSource".
  35. * Will not be forwarded to Cargo if empty.
  36. */
  37. private String type;
  38. /**
  39. * Which transaction support. LOCAL_TRANSACTION or XQ_TRANSACTION.
  40. * Will not be forwarded to Cargo if empty.
  41. */
  42. private String transactionSupport;
  43. /**
  44. * Properties to pass to the driver. Semi-colon delimited string.
  45. * Will not be forwarded to Cargo if empty.
  46. */
  47. private String properties;
  48. /**
  49. * Cargo-style string to pass to Cargo in the "cargo.datasource.datasource" property.
  50. * If set, the other properties will not be read.
  51. *
  52. * <p>Example:
  53. * cargo.datasource.username=sa|cargo.datasource.password...|...
  54. * </p>
  55. */
  56. private String cargoString;
  57. /**
  58. * Additional libraries required in the container (e.g. Tomcat) to support the driver.
  59. * Example with a random library:
  60. *
  61. * <pre>
  62. * {@code
  63. * <libArtifacts>
  64. * <libArtifact>
  65. * <groupId>postgres</groupId>
  66. * <artifactId>postgres</artifactId>
  67. * <version>9.1-901-1.jdbc4</artifactId>
  68. * </libArtifact>
  69. * </libArtifacts>
  70. * }
  71. * </pre>
  72. */
  73. private List<LibArtifact> libArtifacts = Lists.newArrayList();
  74. public DataSource()
  75. {
  76. // Default constructor
  77. }
  78. public String getCargoString()
  79. {
  80. if (cargoString != null)
  81. return cargoString;
  82. List<String> cargoProperties = Lists.newArrayList();
  83. cargoProperties.add("cargo.datasource.url=" + firstNonNull(url, ""));
  84. cargoProperties.add("cargo.datasource.driver=" + firstNonNull(driver, ""));
  85. cargoProperties.add("cargo.datasource.username=" + firstNonNull(username, ""));
  86. cargoProperties.add("cargo.datasource.password=" + firstNonNull(password, ""));
  87. cargoProperties.add("cargo.datasource.jndi=" + firstNonNull(jndi, ""));
  88. if (!StringUtils.isBlank(type))
  89. cargoProperties.add("cargo.datasource.type=" + type);
  90. if (!StringUtils.isBlank(transactionSupport))
  91. cargoProperties.add("cargo.datasource.transactionsupport=" + transactionSupport);
  92. if (!StringUtils.isBlank(properties))
  93. cargoProperties.add("cargo.datasource.properties=" + properties);
  94. cargoString = StringUtils.join(cargoProperties, "|");
  95. return cargoString;
  96. }
  97. /**
  98. * @param cargoString
  99. * the cargo-style string to pass to Cargo in the "cargo.datasource.datasource" property.
  100. */
  101. public DataSource(String cargoString)
  102. {
  103. this.cargoString = cargoString;
  104. }
  105. /**
  106. * Apply default values to the current bean
  107. * @param defaultValues a bean that default values will be read from.
  108. */
  109. public void useForUnsetValues(DataSource defaultValues)
  110. {
  111. if (this.jndi == null) this.jndi = defaultValues.jndi;
  112. if (this.url == null) this.url = defaultValues.url;
  113. if (this.driver == null) this.driver = defaultValues.driver;
  114. if (this.username == null) this.username = defaultValues.username;
  115. if (this.password == null) this.password = defaultValues.password;
  116. if (this.type == null) this.type = defaultValues.type;
  117. if (this.transactionSupport == null) this.transactionSupport = defaultValues.transactionSupport;
  118. if (this.properties == null) this.properties = defaultValues.properties;
  119. }
  120. public String getUrl()
  121. {
  122. return url;
  123. }
  124. public void setUrl(String url)
  125. {
  126. this.url = url;
  127. }
  128. public String getDriver()
  129. {
  130. return driver;
  131. }
  132. public void setDriver(String driver)
  133. {
  134. this.driver = driver;
  135. }
  136. public String getUsername()
  137. {
  138. return username;
  139. }
  140. public void setUsername(String username)
  141. {
  142. this.username = username;
  143. }
  144. public String getPassword()
  145. {
  146. return password;
  147. }
  148. public void setPassword(String password)
  149. {
  150. this.password = password;
  151. }
  152. public String getJndi()
  153. {
  154. return jndi;
  155. }
  156. public void setJndi(String jndi)
  157. {
  158. this.jndi = jndi;
  159. }
  160. public String getType()
  161. {
  162. return type;
  163. }
  164. public void setType(String type)
  165. {
  166. this.type = type;
  167. }
  168. public String getTransactionSupport()
  169. {
  170. return transactionSupport;
  171. }
  172. public void setTransactionSupport(String transactionSupport)
  173. {
  174. this.transactionSupport = transactionSupport;
  175. }
  176. public String getProperties()
  177. {
  178. return properties;
  179. }
  180. public void setProperties(String properties)
  181. {
  182. this.properties = properties;
  183. }
  184. public List<LibArtifact> getLibArtifacts()
  185. {
  186. return libArtifacts;
  187. }
  188. public void setLibArtifacts(List<LibArtifact> libArtifacts)
  189. {
  190. this.libArtifacts = libArtifacts;
  191. }
  192. public void setCargoString(String cargoString)
  193. {
  194. this.cargoString = cargoString;
  195. }
  196. @Override
  197. public String toString()
  198. {
  199. return "DataSource [url=" + url + ", driver=" + driver + ", username=" + username + ", password=" + password + ", jndi=" + jndi + ", type=" + type
  200. + ", transactionSupport=" + transactionSupport + ", properties=" + properties + ", cargoString=" + cargoString + ", libArtifacts="
  201. + libArtifacts + "]";
  202. }
  203. }