Coverage Report - org.naftulin.configmgr.content.DbDirectRecordImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DbDirectRecordImpl
97%
30/31
50%
1/2
0
 
 1  
 package org.naftulin.configmgr.content;
 2  
 
 3  
 import java.util.LinkedList;
 4  
 import java.util.List;
 5  
 
 6  
 import org.naftulin.configmgr.ConfigurationManagerException;
 7  
 import org.naftulin.configmgr.parsers.ConfigEntryParser;
 8  
 import org.naftulin.configmgr.parsers.DbDirectParserImpl;
 9  
 
 10  
 /**
 11  
  * Represents a db direct entry, with it's key, name-value pairs and parser class.
 12  
  * Intended to mirror master configuration rules for external configuration.
 13  
  * The external configuraton xml is:
 14  
  * <pre>
 15  
  *         &lt;dbdirect key="the key"
 16  
                 driverClass="database driver class" 
 17  
                 connectionURl="database connection url"                
 18  
                 sql="sql that selects at least key and value columns from any table(s) or view with any static where condition"
 19  
                 user="user name to login to db if any"
 20  
                 password="password for the user if any"
 21  
                 keyColumnName="column name where the key is selected"
 22  
                 valueColumnName="column name where the value is selected"
 23  
  * 
 24  
  * &gt;
 25  
                 &lt;param name="key1" value="value1" /&gt;
 26  
                 .....
 27  
                 &lt;param name="keyn" value="valuen" /&gt;
 28  
         &lt;/dbdirect&gt;
 29  
  * </pre>
 30  
  * 
 31  
  * @author Henry Henry
 32  
  * @since 1.3
 33  
  */
 34  180
 public class DbDirectRecordImpl extends AbstractRecordImpl {
 35  
         private String driverClass;
 36  
         private String connectionUrl;
 37  
         private String sql;
 38  
         private String user;
 39  
         private String password;
 40  
         private String keyColumnName;
 41  
         private String valueColumnName;
 42  90
         private final List<NameValuePairImpl> nameValuePairs = new LinkedList<NameValuePairImpl>();
 43  
         private ConfigEntryParser parser;
 44  
 
 45  
         
 46  
         public String getDriverClass() {
 47  0
                 return driverClass;
 48  
         }
 49  
 
 50  
         public void setDriverClass(final String driverClass) {
 51  90
                 this.driverClass = driverClass;
 52  90
         }
 53  
 
 54  
         public String getKeyColumnName() {
 55  5
                 return keyColumnName;
 56  
         }
 57  
 
 58  
         public void setKeyColumnName(final String keyColumnName) {
 59  90
                 this.keyColumnName = keyColumnName;
 60  90
         }
 61  
 
 62  
         public List<NameValuePairImpl> getNameValuePairs() {
 63  5
                 return nameValuePairs;
 64  
         }
 65  
 
 66  
         /**
 67  
          * Adds a name-value pair as it is read from the master configuration.
 68  
          * @param nv the name value pair.
 69  
          */
 70  
         public void addNameValuePair(final NameValuePairImpl nv) {
 71  10
                 nameValuePairs.add(nv);
 72  10
         }
 73  
 
 74  
         public String getPassword() {
 75  5
                 return password;
 76  
         }
 77  
 
 78  
         public void setPassword(final String password) {
 79  90
                 this.password = password;
 80  90
         }
 81  
 
 82  
         public String getSql() {
 83  5
                 return sql;
 84  
         }
 85  
 
 86  
         public void setSql(final String sql) {
 87  90
                 this.sql = sql;
 88  90
         }
 89  
 
 90  
         public String getUser() {
 91  5
                 return user;
 92  
         }
 93  
 
 94  
         public void setUser(final String user) {
 95  90
                 this.user = user;
 96  90
         }
 97  
 
 98  
         public String getValueColumnName() {
 99  5
                 return valueColumnName;
 100  
         }
 101  
 
 102  
         public void setValueColumnName(final String valueColumnName) {
 103  90
                 this.valueColumnName = valueColumnName;
 104  90
         }
 105  
 
 106  
         /**
 107  
          * Returns a database parser instance.
 108  
          * @return a database parser instance.
 109  
          */
 110  
         public synchronized ConfigEntryParser getParser() throws ConfigurationManagerException {
 111  80
                 if (parser == null) {
 112  80
                         parser = new DbDirectParserImpl(driverClass, connectionUrl, sql, user, password, keyColumnName, valueColumnName, nameValuePairs);
 113  
                 }
 114  80
                 return parser;
 115  
         }
 116  
 
 117  
         public String getConnectionUrl() {
 118  5
                 return connectionUrl;
 119  
         }
 120  
 
 121  
         public void setConnectionUrl(final String connectionUrl) {
 122  5
                 this.connectionUrl = connectionUrl;
 123  5
         }
 124  
         
 125  
         /**
 126  
          * Since it is not a file-based cofiguration, we need to overwrite the method.
 127  
          * @return false
 128  
          */
 129  
         public boolean isGetUrlForFile() {
 130  80
                 return false;
 131  
         }
 132  
 
 133  
         public String getFileName() {
 134  80
                 return "driver : " + driverClass + " connection " + connectionUrl + " sql " + sql + " user " + user;                
 135  
         }
 136  
 }