Coverage Report - org.naftulin.configmgr.content.DbJndiRecordImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
DbJndiRecordImpl
80%
20/25
0%
0/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.DbJndiParserImpl;
 9  
 
 10  
 /**
 11  
  * Represents a db jndi 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;dbjndi key="the key"
 16  
                 initialContextFactory="optional contenxt factory" 
 17  
                 jndiName="jdni name"                
 18  
                 sql="sql that selects at least key and value columns from any table(s) or view with any static where condition"
 19  
                 keyColumnName="column name where the key is selected"
 20  
                 valueColumnName="column name where the value is selected"
 21  
  * 
 22  
  * &gt;
 23  
                 &lt;param name="key1" value="value1" /&gt;
 24  
                 .....
 25  
                 &lt;param name="keyn" value="valuen" /&gt;
 26  
         &lt;/dbjndi&gt;
 27  
  * </pre>
 28  
  * 
 29  
  * @author Henry Henry
 30  
  * @since 1.3
 31  
  */
 32  10
 public class DbJndiRecordImpl extends AbstractRecordImpl {
 33  
         private String initialContextFactory;
 34  
         private String jndiName;
 35  
         private String sql;
 36  
         private String keyColumnName;
 37  
         private String valueColumnName;
 38  5
         private final List<NameValuePairImpl> nameValuePairs = new LinkedList<NameValuePairImpl>();
 39  
         private ConfigEntryParser parser;
 40  
 
 41  
         
 42  
         
 43  
         public String getKeyColumnName() {
 44  5
                 return keyColumnName;
 45  
         }
 46  
 
 47  
         public void setKeyColumnName(final String keyColumnName) {
 48  5
                 this.keyColumnName = keyColumnName;
 49  5
         }
 50  
 
 51  
         public List<NameValuePairImpl> getNameValuePairs() {
 52  5
                 return nameValuePairs;
 53  
         }
 54  
 
 55  
         /**
 56  
          * Adds a name-value pair as it is read from the master configuration.
 57  
          * @param nv the name value pair.
 58  
          */
 59  
         public void addNameValuePair(final NameValuePairImpl nv) {
 60  5
                 nameValuePairs.add(nv);
 61  5
         }
 62  
 
 63  
         public String getInitialContextFactory() {
 64  5
                 return initialContextFactory;
 65  
         }
 66  
 
 67  
         public void setInitialContextFactory(final String initialContextFactory) {
 68  5
                 this.initialContextFactory = initialContextFactory;
 69  5
         }
 70  
 
 71  
         public String getJndiName() {
 72  5
                 return jndiName;
 73  
         }
 74  
 
 75  
         public void setJndiName(final String jndiName) {
 76  5
                 this.jndiName = jndiName;
 77  5
         }
 78  
 
 79  
         public String getSql() {
 80  5
                 return sql;
 81  
         }
 82  
 
 83  
         public void setSql(final String sql) {
 84  5
                 this.sql = sql;
 85  5
         }
 86  
 
 87  
         
 88  
 
 89  
         public String getValueColumnName() {
 90  5
                 return valueColumnName;
 91  
         }
 92  
 
 93  
         public void setValueColumnName(final String valueColumnName) {
 94  5
                 this.valueColumnName = valueColumnName;
 95  5
         }
 96  
 
 97  
         public synchronized ConfigEntryParser getParser() throws ConfigurationManagerException {
 98  0
                 if (parser == null) {
 99  0
                         parser = new DbJndiParserImpl(jndiName, initialContextFactory, sql, keyColumnName, valueColumnName, nameValuePairs);
 100  
                 }
 101  0
                 return parser;
 102  
         }
 103  
 
 104  
         
 105  
         
 106  
         /**
 107  
          * Since it is not a file-based cofiguration, we need to overwrite the method.
 108  
          * @return false
 109  
          */
 110  
         public boolean isGetUrlForFile() {
 111  0
                 return false;
 112  
         }
 113  
 
 114  
         public String getFileName() {
 115  0
                 return "jndi name : " + jndiName + " initial Context Factory " + initialContextFactory + " sql " + sql;                
 116  
         }
 117  
 }