Skip to content
Snippets Groups Projects
DatabaseDocument.java 29.7 KiB
Newer Older
  • Learn to ignore specific revisions
  • tjc's avatar
    tjc committed
       */
    
    tjc's avatar
    tjc committed
      private void appendToLogFile(String logEntry, String logFileName)
      {
    
    tjc's avatar
    tjc committed
        if(System.getProperty("debug") == null)
          return;
    
    
    tjc's avatar
    tjc committed
        BufferedWriter bw = null;
        try
        {
          String dat = new java.util.Date().toString();
    
          bw = new BufferedWriter(new FileWriter(logFileName, true));
    
    tjc's avatar
    tjc committed
          bw.write(dat + ":: " + logEntry);
    
    tjc's avatar
    tjc committed
          bw.newLine();
          bw.flush();
        }
    
    tjc's avatar
    tjc committed
        catch(Exception ioe)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          System.out.println("Error writing to log file " + logFileName);
    
    tjc's avatar
    tjc committed
          ioe.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
        finally
        // always close the file
    
    tjc's avatar
    tjc committed
        {
          if(bw != null)
    
    tjc's avatar
    tjc committed
            try
            {
              bw.close();
            }
            catch(IOException ioe2)
            {
            }
    
    tjc's avatar
    tjc committed
        }
      }
    
    
    tjc's avatar
    tjc committed
      public void commit(Vector sql)
      {
        try
        {
          Connection conn = getConnection();
          int row = 0;
    
    
    tjc's avatar
    tjc committed
          for(int i = 0; i < sql.size(); i++)
    
    tjc's avatar
    tjc committed
          {
    
    tjc's avatar
    tjc committed
            ChadoTransaction tsn = (ChadoTransaction) sql.get(i);
    
            String[] sql_array = tsn.getSqlQuery(schema);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
            for(int j = 0; j < sql_array.length; j++)
    
            {
              System.out.println(sql_array[j]);
    
              Statement st = conn.createStatement();
              row += st.executeUpdate(sql_array[j]);
            }
    
    tjc's avatar
    tjc committed
          }
    
          conn.close();
        }
    
    tjc's avatar
    tjc committed
        catch (java.sql.SQLException sqlExp)
    
    tjc's avatar
    tjc committed
        {
          sqlExp.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
        catch (java.net.ConnectException conn)
    
    tjc's avatar
    tjc committed
        {
          JOptionPane.showMessageDialog(null, "Problems connecting...",
    
    tjc's avatar
    tjc committed
                                        "Database Connection Error - Check Server",
                                        JOptionPane.ERROR_MESSAGE);
    
    tjc's avatar
    tjc committed
          conn.printStackTrace();
        }
    
      }
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
      public static void main(String args[])
      {
        try
        {
          DbSqlConfig.init(new JPasswordField());
          SqlMapClient sqlMap = DbSqlConfig.getSqlMapInstance();
    
    
    tjc's avatar
    tjc committed
          Feature feature = new Feature();
    
    tjc's avatar
    tjc committed
          feature.setId(Integer.parseInt(args[0]));
          feature.setSchema(args[1]);
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
          List featureList = sqlMap.queryForList("getGffLine", feature);
     
          for(int i = 0; i < featureList.size(); i++)
          {
            feature = (Feature)featureList.get(i);
            int fmin     = feature.getFmin() + 1;
            int fmax     = feature.getFmax();
    
            System.out.print(fmin+" "+fmax);
            System.out.print(" "+feature.getType_id());
            System.out.print(" "+feature.getProp_type_id());
            System.out.print(" "+feature.getStrand());
            System.out.print(" "+feature.getUniquename());
            System.out.print(" "+feature.getTimelastmodified().toString());
            System.out.println(" "+Integer.toString(feature.getId()));
          }
    
    tjc's avatar
    tjc committed
        }
        catch(SQLException sqle)
        {
          sqle.printStackTrace();
        }
      }
    
    tjc's avatar
    tjc committed
    }