Package org.openqreg.db

Examples of org.openqreg.db.DbHandler


   * Creates a DbHandler
   *
   * @return A new DbHandler
   */
  protected DbHandler createDbHandler() {
    return new DbHandler();
  }
View Full Code Here


   * Creates a new DbHandler. This method can be overrridden in subclasses.
   *
   * @return A DbHandler
   */
  protected DbHandler createDbHandler() {
    return new DbHandler();
  }
View Full Code Here


public class DbHandlerTest {
    public static void main(String[] args) {
    try {
      DbHandler db = new DbHandler();
 
      ResultSet rs = db.executeQuery("select * from language");
      while (rs.next()) {       
        System.out.print(rs.getString(1));
                System.out.println(rs.getString(2));
      }
        }
View Full Code Here

    JNDIUnitTestHelper.shutdown();
  }

  @Test
  public void testClose() throws Exception {
    DbHandler db = new DbHandler();
    db.close();
    assertFalse(db.isConnected());
  }
View Full Code Here

    assertFalse(db.isConnected());
  }

  @Test
  public void testGetConnectInfo() {
    DbHandler db = new DbHandler();
    assertEquals("Wrong connectinfo returned", connectInfo, db
        .getConnectInfo());
  }
View Full Code Here

  }

  @Test
  public void testConnect() {
    try {
      DbHandler db = new DbHandler();
      db.connect(connectInfo);
    } catch (DbHandlerException e) {
      fail(e.getMessage());
    }
  }
View Full Code Here

  public DiagnoseHolder() {
    populate();
  }
 
  protected DbHandler createDbHandler() {
    return new DbHandler();
  }
View Full Code Here

   * Populate maps from db
   */
  public void populate() {
   
    try {
      DbHandler db = createDbHandler();
     
      //Count nr of available languages
      String query     = "select ID, NAME from language";
     
      ResultSet rs     = db.executeQuery(query);
     
      int lang     = -1;
      String langName   = "";
     
      while(rs.next()) {
        lang     = rs.getInt("ID");
        langName   = rs.getString("NAME");
       
        languages.put(""+lang, new TreeMap());
        if(debug) {
          System.out.println("Populating DiagnoseHandler with language: "+langName+"("+lang+")")
        }
       
      }
     
     
     
     
     
      int currentLanguage = -1;
     
     
      for (Iterator it = languages.keySet().iterator() ; it.hasNext() ;) {
       
        try {
          String currentKey = (String)it.next();
         
          currentLanguage = Integer.parseInt(currentKey);
        } catch (NumberFormatException nfe) {
          System.out.println("DiagnoseHandler: Can't use the found language id as an int"+nfe)
        }
       
        TreeMap languageGroups  = (TreeMap)languages.get(""+currentLanguage);
       
        if(debug) {
          System.out.println("\tLooping for language: "+currentLanguage)
        }
       
        //Loop out all diagnosegroups for this language
        Integer id = new Integer(-1);
        query = "select ID, NAME, LANGUAGE, SORTORDER from diagnose_group WHERE STATUS=1 AND LANGUAGE="+currentLanguage+" ORDER BY SORTORDER";
     
        rs = db.executeQuery(query);
       
        while(rs.next()) {
          id = new Integer(rs.getInt("ID"));
          if(debug) {
            System.out.println("Adding DiagnoseGroup: "+id+" ("+rs.getString("NAME")+")")
          }
          languageGroups.put(id, new DiagnoseGroup(id.intValue(), rs.getString("NAME"), rs.getInt("LANGUAGE"), rs.getInt("SORTORDER")));
        }
       
        //Get all diagnoses
        query = "select DIAGNOSE.ID, DIAGNOSE.CODE, DIAGNOSE.NAME, DIAGNOSE.CODE, DIAGNOSE.LANGUAGE, DIAGNOSE.SORTORDER,DIAGNOSE_REL.DIAGNOSE_GROUP from diagnose, diagnose_rel where diagnose.ID=diagnose_rel.DIAGNOSE and diagnose.STATUS=1 and diagnose_rel.STATUS=1 AND diagnose.LANGUAGE="+currentLanguage+" ORDER BY diagnose.SORTORDER";
       
        rs = db.executeQuery(query);
       
        Integer groupId = new Integer(-1);
       
        while(rs.next()) {
          groupId = new Integer(rs.getInt("DIAGNOSE_REL.DIAGNOSE_GROUP"));
          if(debug) {
            System.out.println("\t\tAdding Diagnose to group: "+groupId)
          }
         
         
         
          ((DiagnoseGroup)languageGroups.get(groupId)).addDiagnose(new Diagnose(rs.getInt("SORTORDER"), rs.getString("NAME")+(diagnoseCodeInName?" ["+rs.getString("CODE").trim()+"]":""), rs.getString("CODE").trim(), rs.getInt("LANGUAGE"), rs.getInt("SORTORDER")));
        }
       
       
      }
     
      db.close();
    } catch (DbHandlerException dbe) {
      System.out.println("Can't load diagnosegroups because of: \n"+dbe.toString())
    } catch (SQLException sqle) {
      System.out.println("Can't load diagnosegroups because of: \n"+sqle.toString())
    }
View Full Code Here

TOP

Related Classes of org.openqreg.db.DbHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.