View Javadoc

1   /*
2    * $Id: AbstractHostPortDatabaseDataSourceFactoryBean.java 22121 2011-06-06 11:10:58Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.jdbc.config;
12  
13  public abstract class AbstractHostPortDatabaseDataSourceFactoryBean extends AbstractDataSourceFactoryBean
14  {
15      protected  final String DEFAULT_HOST = "localhost";
16  
17      protected String database;
18      protected String host;
19      protected int port = -1;
20  
21      public AbstractHostPortDatabaseDataSourceFactoryBean()
22      {
23          super();
24          host = DEFAULT_HOST;
25      }
26  
27      protected void updateUrl()
28      {
29          StringBuilder buf = new StringBuilder(64);
30          buf.append(getJdbcUrlPrefix());
31          buf.append(getHost());
32          if (getPort() > 0)
33          {
34              buf.append(":");
35              buf.append(getPort());
36          }
37          buf.append("/");
38          buf.append(getDatabase());
39  
40          url = buf.toString();
41      }
42  
43      protected abstract String getJdbcUrlPrefix();
44  
45      public String getDatabase()
46      {
47          return database;
48      }
49  
50      public void setDatabase(String database)
51      {
52          this.database = database;
53          updateUrl();
54      }
55  
56      public String getHost()
57      {
58          return host;
59      }
60  
61      public void setHost(String host)
62      {
63          this.host = host;
64          updateUrl();
65      }
66  
67      public int getPort()
68      {
69          return port;
70      }
71  
72      public void setPort(int port)
73      {
74          this.port = port;
75          updateUrl();
76      }
77  }