View Javadoc

1   /**
2   The contents of this file are subject to the Mozilla Public License Version 1.1 
3   (the "License"); you may not use this file except in compliance with the License. 
4   You may obtain a copy of the License at http://www.mozilla.org/MPL/ 
5   Software distributed under the License is distributed on an "AS IS" basis, 
6   WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 
7   specific language governing rights and limitations under the License. 
8   
9   The Original Code is "TableRepository.java".  Description: 
10  "A place where table keys and values are stored" 
11  
12  The Initial Developer of the Original Code is University Health Network. Copyright (C) 
13  2001.  All Rights Reserved. 
14  
15  Contributor(s): ______________________________________. 
16  
17  Alternatively, the contents of this file may be used under the terms of the 
18  GNU General Public License (the  �GPL�), in which case the provisions of the GPL are 
19  applicable instead of those above.  If you wish to allow use of your version of this 
20  file only under the terms of the GPL and not to allow others to use your version 
21  of this file under the MPL, indicate your decision by deleting  the provisions above 
22  and replace  them with the notice and other provisions required by the GPL License.  
23  If you do not delete the provisions above, a recipient may use your version of 
24  this file under either the MPL or the GPL. 
25  
26  */
27  
28  package ca.uhn.hl7v2.database;
29  
30  import java.sql.SQLException;
31  import java.util.HashMap;
32  import java.util.Map;
33  
34  import ca.uhn.hl7v2.LookupException;
35  import ca.uhn.hl7v2.UndefinedTableException;
36  import ca.uhn.hl7v2.UnknownValueException;
37  
38  /**
39   * A place where table keys and values are stored.  This may be implemented
40   * with a database, an LDAP directory, local RAM, etc.  At a minimum, any
41   * underlying repository must supply the values for standard HL7 tables.
42   * Site-defined tables may also be supported.
43   * @author Bryan Tripp (bryan_tripp@sourceforge.net)
44   * @deprecated This code is probably no longer used and will be removed in an upcoming
45   *    release. Please get in touch if you are still using it.
46   */
47  public abstract class TableRepository {
48  
49    private static Map<String, DBTableRepository> reps = new HashMap<String, DBTableRepository>();
50  
51    /**
52     * Returns a TableRepository object.
53     */
54    public static TableRepository getInstance(String jdbcUrl) throws SQLException {
55        if (reps.containsKey(jdbcUrl) == false) {
56            reps.put(jdbcUrl, new DBTableRepository(jdbcUrl));
57        }
58        
59      return (TableRepository)reps.get(jdbcUrl);
60    }
61  
62    /**
63     * Returns a list of HL7 tables.  
64     */  
65    public abstract int[] getTables() throws LookupException;
66    
67    /**
68     * Returns true if the given value exists in the given table.
69     */
70    public abstract boolean checkValue(int table, String value) throws UndefinedTableException, LookupException;
71   
72    /**
73     * Returns a list of the values in the given table. 
74     */ 
75    public abstract String[] getValues(int table) throws LookupException, UndefinedTableException;
76    
77    /**
78     * Returns the value corresponding to the given table and key.
79     * @throws UnknownValueException if the value can not be found.  This may be an UnknownTableException.  
80     */
81    public abstract String getDescription(int table, String value) throws LookupException, UnknownValueException;
82    
83    //test
84    /*
85    public static void main(String[] args) {
86        
87        if (args.length != 2) {
88            System.out.println("Usage: TableRepository table value");
89            System.exit(1);
90        }
91        int table = Integer.parseInt(args[0]);
92        String value = args[1];
93        
94        try {
95          //needed by normative DB ... 
96          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
97          System.setProperty("ca.on.uhn.hl7.database.url", "jdbc:odbc:hl7");
98          System.out.println("Description: " + TableRepository.getInstance().getDescription(table, value));
99        } catch (UnknownValueException e) {
100           e.printStackTrace();
101           Log.tryToLog(e, "");
102       } catch (ClassNotFoundException cne) {
103           cne.printStackTrace();
104       }
105   }*/
106   
107 }