Beispiel #1
0
  public static void main(String[] args) {
    DbClient client = null;
    try {
      client = new DbClient();
      client.connect();

      // client.runUpdate("INSERT INTO DrWeb VALUES(0,null,null,'boogle','worp')");
      // ResultSet rs =
      // client.runQuery("SELECT LASTNAME FROM DrWeb WHERE FIRSTNAME='worp'"
      // );
      ResultSet rs = client.runQuery("SELECT LASTNAME FROM DrWeb");

      while (rs.next()) {
        System.out.println("lastname=" + rs.getString(1));
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } catch (DbException e) {
      e.printStackTrace();
    } finally {
      if ((client != null) && client.isConnected()) {
        try {
          client.disconnect();
        } catch (DbException e) {
        }
      }
    }

    System.exit(0);
  }
Beispiel #2
0
  /**
   * Inserts tuples read from child into the tableid specified by the constructor. It returns a one
   * field tuple containing the number of inserted records. Inserts should be passed through
   * BufferPool. An instances of BufferPool is available via Database.getBufferPool(). Note that
   * insert DOES NOT need check to see if a particular tuple is a duplicate before inserting it.
   *
   * @return A 1-field tuple containing the number of inserted records, or null if called more than
   *     once.
   * @see Database#getBufferPool
   * @see BufferPool#insertTuple
   */
  protected Tuple fetchNext() throws TransactionAbortedException, DbException {
    Tuple result = new Tuple(td); // use to store the insertion result
    int count = 0; // use to keep track of numbers of tuple insertion

    if (fetchNextNum
        > 0) // meaning this is not the first time calling fetchNext(), and should not return any
             // tuples
    return null;
    else {
      try {
        while (dbIt.hasNext()) {
          try {
            Database.getBufferPool().insertTuple(tranId, tableId, dbIt.next());
          } catch (IOException e) {
            e.printStackTrace();
          }
          count++;
        }

        result.setField(0, new IntField(count));
        fetchNextNum++;
      } catch (DbException e) {
        e.printStackTrace();
      } catch (TransactionAbortedException e) {
        e.printStackTrace();
      }
    }
    return result;
  }
Beispiel #3
0
 public void rewind() throws DbException, TransactionAbortedException {
   try {
     dbIt.rewind();
   } catch (DbException e) {
     e.printStackTrace();
   } catch (TransactionAbortedException e) {
     e.printStackTrace();
   }
 }
  public boolean expand(Writer output, Serializable object, RuleOptions options)
      throws IOException, RuleException {
    boolean expanded = false;
    boolean prefixPrinted = false;
    boolean atLeastOneChildPrinted = false;

    if (object == null) {
      if (Debug.isDebug()) {
        throw new NullPointerException(); // disclose programming error
        // in debug..
      } else {
        return false;
      }
    } // end if

    if (!(object instanceof DbObject)) {
      return false;
    } // end if

    DbObject dbObject = (DbObject) object;
    MetaRelationship metaRelation = getMetaRelation(dbObject);
    MetaClass childrenMetaClass = getChildrenMetaClass();

    try {
      // get metaRelation from its string representation
      if (metaRelation == null)
        metaRelation = (MetaRelationship) getMetaField(dbObject, sConnector);

      boolean state[] = {prefixPrinted, atLeastOneChildPrinted};

      if (metaRelation instanceof MetaRelation1) {
        MetaRelation1 metaRelation1 = (MetaRelation1) metaRelation;
        expanded |=
            expandMetaRelation1(output, dbObject, metaRelation1, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaRelationN) {
        expanded |=
            expandMetaRelationN(output, dbObject, metaRelation, state, childrenMetaClass, options);
      } else if (metaRelation instanceof MetaChoice) {
        MetaChoice choice = (MetaChoice) metaRelation;
        expanded |= expandMetaChoice(output, dbObject, choice, state, childrenMetaClass, options);
      } else {
        // TODO: throw 'meta-relationship not supported'
      }

      super.terminate(output, options);
    } catch (DbException ex) {
      String msg = ex.getMessage();
      throw new RuleException(msg);
    } catch (RuntimeException ex) {
      String conn = m_connector.getGUIName();
      String objectKind = dbObject.getMetaClass().getGUIName();
      String msg = InvalidConnectorRuleException.buildMessage(m_ruleName, conn, objectKind);
      throw new InvalidConnectorRuleException(msg);
    }

    return expanded;
  }
  private DbJVClass importClass(JavaClass claz, Controller controller) throws DbException {

    String packName = claz.getPackageName();
    String qualifiedName = claz.getClassName();
    int idx = qualifiedName.lastIndexOf('.');
    String classname = qualifiedName.substring(idx + 1);
    DbJVClass dbClaz = null;

    try {
      if (m_classModel != null) {
        DbJVPackage pack = findPackageByName(packName);

        // create class or interface
        int value = claz.isInterface() ? JVClassCategory.INTERFACE : JVClassCategory.CLASS;
        JVClassCategory catg = JVClassCategory.getInstance(value);
        dbClaz =
            (pack == null) ? new DbJVClass(this.m_classModel, catg) : new DbJVClass(pack, catg);
        dbClaz.setName(classname);

        // set class modifiers
        dbClaz.setAbstract(claz.isAbstract());
        dbClaz.setFinal(claz.isFinal());
        dbClaz.setStatic(claz.isStatic());
        dbClaz.setStrictfp(claz.isStrictfp());
        dbClaz.setVisibility(toVisibility(claz));

        // create inheritances
        importInheritances(dbClaz, claz);

        // create fields
        if (m_params.createFields) {
          Field[] fields = claz.getFields();
          for (Field field : fields) {
            importField(dbClaz, field);
          }
        }

        // create methods
        if (m_params.createMethods) {
          Method[] methods = claz.getMethods();
          for (Method method : methods) {
            importMethod(dbClaz, method);
          }
        }

        // keep user informed of progression
        String pattern = LocaleMgr.misc.getString("0SuccessfullyCreated");
        String msg = MessageFormat.format(pattern, qualifiedName);
        controller.println(msg);
      } // end if
    } catch (DbException ex) {
      controller.println(ex.toString());
    } // end try

    return dbClaz;
  } // end importClass()
Beispiel #6
0
 public void open() throws DbException, TransactionAbortedException {
   try {
     super.open();
     dbIt.open();
   } catch (DbException e) {
     e.printStackTrace();
   } catch (TransactionAbortedException e) {
     e.printStackTrace();
   }
 }
Beispiel #7
0
 // see DbFile.java for javadocs
 public DbFileIterator iterator(TransactionId tid) {
   try {
     return new HeapFileIterator(tid, this);
   } catch (DbException dbe) {
     dbe.printStackTrace();
   } catch (TransactionAbortedException transe) {
     transe.printStackTrace();
   } catch (NoSuchElementException nosuche) {
     nosuche.printStackTrace();
   }
   return null;
 }
Beispiel #8
0
  /**
   * Create a new TableStats object, that keeps track of statistics on each column of a table
   *
   * @param tableid The table over which to compute statistics
   * @param ioCostPerPage The cost per page of IO. This doesn't differentiate between
   *     sequential-scan IO and disk seeks.
   */
  public TableStats(int tableid, int ioCostPerPage) {
    // For this function, we use the DbFile for the table in question,
    // then scan through its tuples and calculate the values that you
    // to build the histograms.

    // TODO: Fill out the rest of the constructor.
    // Feel free to change anything already written, it's only a guideline

    this.ioCostPerPage = ioCostPerPage;
    DbFile file = Database.getCatalog().getDbFile(tableid);
    tupleDesc = file.getTupleDesc();
    numPages = ((HeapFile) file).numPages();
    numTuples = 0;

    int numFields = tupleDesc.numFields();

    // TODO: what goes here?
    statistics = new ArrayList<Object>();

    for (int i = 0; i < numFields; i++) {
      if (Type.INT_TYPE.equals(tupleDesc.getFieldType(i))) {
        statistics.add(new IntStatistics(NUM_HIST_BINS));
      } else {
        statistics.add(new StringHistogram(NUM_HIST_BINS));
      }
    }

    final DbFileIterator iter = file.iterator(null);
    try {
      iter.open();

      while (iter.hasNext()) {
        Tuple t = iter.next();
        numTuples++;

        // TODO: and here?
        for (int i = 0; i < numFields; i++) {
          if (Type.INT_TYPE.equals(tupleDesc.getFieldType(i))) {
            ((IntStatistics) statistics.get(i)).addValue(((IntField) t.getField(i)).getValue());
          } else {
            ((StringHistogram) statistics.get(i))
                .addValue(((StringField) t.getField(i)).getValue());
          }
        }
      }
      iter.close();
    } catch (DbException e) {
      e.printStackTrace();
    } catch (TransactionAbortedException e) {
      e.printStackTrace();
    }
  }
  @Override
  protected void runJob() throws Exception {

    Controller controller = getController();

    // is invoked head less?
    DefaultMainFrame mainFrame = ApplicationContext.getDefaultMainFrame();
    boolean headless = (mainFrame == null);
    Db db = null;

    try {
      if (!headless) {
        // create new project, if it was not specific by the user
        m_project = m_params.getOutputProject();
        if (m_project == null) {
          m_project = (DbSMSProject) mainFrame.createDefaultProject(db);
        }

        db = m_project.getDb();
        db.beginWriteTrans(LocaleMgr.misc.getString("ImportJavaBytecode"));

        // create class model
        m_classModel = new DbJVClassModel(m_project);
      }

      // import Java classes files (jobDone 0% to 80%)
      DbJVPackage topMostPackage = importFiles(controller, 0, 80);

      // show success/failure message
      if (controller.getErrorsCount() == 0) {
        controller.println(LocaleMgr.misc.getString("Success"));
      } else {
        controller.println(LocaleMgr.misc.getString("Failed"));
      } // end if

      // create and reveal diagram ((jobDone 80% to 100%)
      if (!headless) {
        if ((topMostPackage != null) && (m_params.createDiagrams)) {
          createAndRevealDiagram(mainFrame, topMostPackage, controller, 80, 100);
        }

        db.commitTrans();
      } // end if

      controller.checkPoint(100);

    } catch (DbException ex) {
      controller.println(ex.toString());
      controller.cancel();
    } // end try
  } // end runJob()
 /**
  * Set the file trace level.
  *
  * @param level the new level
  */
 public void setLevelFile(int level) {
   if (level == ADAPTER) {
     String adapterClass = "org.h2.message.TraceWriterAdapter";
     try {
       writer = (TraceWriter) Class.forName(adapterClass).newInstance();
     } catch (Throwable e) {
       e = DbException.get(ErrorCode.CLASS_NOT_FOUND_1, e, adapterClass);
       write(ERROR, Trace.DATABASE, adapterClass, e);
       return;
     }
     String name = fileName;
     if (name != null) {
       if (name.endsWith(Constants.SUFFIX_TRACE_FILE)) {
         name = name.substring(0, name.length() - Constants.SUFFIX_TRACE_FILE.length());
       }
       int idx = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\'));
       if (idx >= 0) {
         name = name.substring(idx + 1);
       }
       writer.setName(name);
     }
   }
   levelFile = level;
   updateLevel();
 }
 private void logWritingError(Exception e) {
   if (writingErrorLogged) {
     return;
   }
   writingErrorLogged = true;
   Exception se = DbException.get(ErrorCode.TRACE_FILE_ERROR_2, e, fileName, e.toString());
   // print this error only once
   fileName = null;
   sysOut.println(se);
   se.printStackTrace();
 }