Skip to content
Snippets Groups Projects
DatabaseDocument.java 34.6 KiB
Newer Older
  • Learn to ignore specific revisions
  •           else if(tsn.getType() == ChadoTransaction.INSERT_ALIAS)
                dao.insertFeatureAlias(schema, tsn);
    
              else if(tsn.getType() == ChadoTransaction.UPDATE_FEATURE_RELATIONSHIP)
                dao.updateFeatureRelationshipsForSubjectId(schema, tsn);
    
            }
    
            //
            // update timelastmodified timestamp
            Timestamp ts = null;
            Timestamp ts2;
            names_checked = new Vector();
            for(int j = 0; j < sql.size(); j++)
            {
              ChadoTransaction tsn = (ChadoTransaction) sql.get(j);
    
    
              if(tsn.getType() != ChadoTransaction.INSERT_FEATURE &&
                 tsn.getType() != ChadoTransaction.DELETE_FEATURE)
    
                final List uniquename = tsn.getUniquename();
    
                // update timelastmodified timestamp
                for(int k = 0; k < uniquename.size(); k++)
                {
                  if(names_checked.contains((String) uniquename.get(k)))
                    continue;
    
                  names_checked.add((String) uniquename.get(k));
    
                  dao.writeTimeLastModified(schema, (String) uniquename.get(k), ts);
                  ts2 = dao.getTimeLastModified(schema, (String) uniquename.get(k));
                  if(ts2 == null)
                    continue;
    
                  if(ts == null)
                    ts = ts2;
    
                  GFFStreamFeature gff_feature = (GFFStreamFeature) tsn
                      .getFeatureObject();
    
                  gff_feature.setLastModified(ts);
                }
    
            
            if(dao instanceof IBatisDAO && 
               System.getProperty("nocommit") == null)
               ((IBatisDAO) dao).commitTransaction();
          }
          finally
          {
            if(dao instanceof IBatisDAO)
              ((IBatisDAO) dao).endTransaction();
          }
    
    tjc's avatar
    tjc committed
        }
    
    tjc's avatar
    tjc committed
        catch (java.sql.SQLException sqlExp)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          JOptionPane.showMessageDialog(null, "Problems Writing...\n" +
    
    tjc's avatar
    tjc committed
                                        sqlExp.getMessage(),
    
    tjc's avatar
    tjc committed
                                        "Problems Writing to Database ",
    
    tjc's avatar
    tjc committed
                                        JOptionPane.ERROR_MESSAGE);
    
    tjc's avatar
    tjc committed
          sqlExp.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
        catch (java.net.ConnectException conn_ex)
    
    tjc's avatar
    tjc committed
        {
    
    tjc's avatar
    tjc committed
          JOptionPane.showMessageDialog(null, "Problems connecting..."+
                                        conn_ex.getMessage(),
    
    tjc's avatar
    tjc committed
                                        "Database Connection Error - Check Server",
                                        JOptionPane.ERROR_MESSAGE);
    
    tjc's avatar
    tjc committed
          conn_ex.printStackTrace();
    
    tjc's avatar
    tjc committed
        }
    
    tjc's avatar
    tjc committed
        return i;
    
    tjc's avatar
    tjc committed
      }
    
      
      /**
       * Check the <code>Timestamp</code> on a feature (for versioning).
       * @param schema      the schema
       * @param uniquename  the feature uniquename
       * @param timestamp   the last read feature timestamp
       * @throws SQLException
       */
    
      public boolean checkFeatureTimestamp(final String schema,
    
    tjc's avatar
    tjc committed
                                           final String uniquename,
                                           final Timestamp timestamp,
                                           final ChadoDAO dao)
                                           throws SQLException
    
      {
        Timestamp now = dao.getTimeLastModified(schema, uniquename);
        
    
    tjc's avatar
    tjc committed
        if(now != null && timestamp != null)
    
        {
          now.setNanos(0);
          timestamp.setNanos(0);
          
    
          if(now.compareTo(timestamp) != 0)
          {
            SimpleDateFormat date_format = 
                       new SimpleDateFormat("dd.MM.yyyy hh:mm:ss z");
    
            //System.out.println(date_format.format(now)+"   "+
            //                   date_format.format(timestamp));
    
            int select = JOptionPane.showConfirmDialog(null, uniquename +
    
                                          " has been altered at :\n"+
    
                                          date_format.format(now)+"\nOverwite?", 
                                          "Feature Changed", 
                                          JOptionPane.OK_CANCEL_OPTION);
            if(select == JOptionPane.OK_OPTION)
              return true;
            else
              return false;
    
        return true;
    
    tjc's avatar
    tjc committed
    
    
    tjc's avatar
    tjc committed
      public static void main(String args[])
      {
        try
        {
    
    tjc's avatar
    tjc committed
          ChadoDAO dao;
          DatabaseEntrySource src = new DatabaseEntrySource();
          src.setLocation(true);
          
          if(System.getProperty("ibatis") == null)
            dao = new JdbcDAO(src.getLocation(), src.getPfield()); 
          else
            dao = new IBatisDAO(src.getPfield());
          
    
    tjc's avatar
    tjc committed
          ChadoFeature feature = new ChadoFeature();
          feature.setUniquename(args[0]);
    
    tjc's avatar
    tjc committed
          List schemas = new Vector();
          schemas.add(args[1]);
    
    tjc's avatar
    tjc committed
          List featureList = dao.getLazyFeature(feature, schemas); 
    
    tjc's avatar
    tjc committed
          System.out.println("FINISHED getFeature()");
    
    tjc's avatar
    tjc committed
          for(int i = 0; i < featureList.size(); i++)
          {
    
    tjc's avatar
    tjc committed
            feature = (ChadoFeature)featureList.get(i);
    
    tjc's avatar
    tjc committed
            
    
    tjc's avatar
    tjc committed
            String abb  = feature.getOrganism().getAbbreviation();
    
    tjc's avatar
    tjc committed
            String type = feature.getCvterm().getName();
    
    tjc's avatar
    tjc committed
            int fmin    = feature.getFeatureloc().getFmin() + 1;
            int fmax    = feature.getFeatureloc().getFmax();
    
    tjc's avatar
    tjc committed
            String featprop = 
              ((ChadoFeatureProp)feature.getFeaturepropList().get(0)).getCvterm().getName();
            
    
    tjc's avatar
    tjc committed
            System.out.print(fmin+".."+fmax);
    
    tjc's avatar
    tjc committed
            System.out.print(" "+type);
    
    tjc's avatar
    tjc committed
            System.out.print(" "+featprop);
    
    tjc's avatar
    tjc committed
            System.out.print(" "+feature.getFeatureloc().getStrand());
    
    tjc's avatar
    tjc committed
            System.out.print(" "+feature.getUniquename());
    
    tjc's avatar
    tjc committed
            System.out.print(" "+abb);
    
    tjc's avatar
    tjc committed
            System.out.println(" "+Integer.toString(feature.getId()));
    
    tjc's avatar
    tjc committed
            
            Hashtable synonyms   = dao.getAlias(args[1], feature.getUniquename());
            Vector syns = (Vector)synonyms.get(new Integer(feature.getId()));
            for(int j=0; j<syns.size(); j++)
            {
    
    tjc's avatar
    tjc committed
              ChadoFeatureSynonym alias = (ChadoFeatureSynonym)syns.get(j);
              System.out.print(" "+alias.getSynonym().getCvterm().getName()+
                               "="+alias.getSynonym().getName());
    
    tjc's avatar
    tjc committed
            }
            
            System.out.println(" "); 
    
    tjc's avatar
    tjc committed
          }
    
    tjc's avatar
    tjc committed
        }
        catch(SQLException sqle)
        {
          sqle.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
        catch(ConnectException e)
        {
          e.printStackTrace();
        }
    
    tjc's avatar
    tjc committed
      }
    
    tjc's avatar
    tjc committed
    }