Example #1
0
    public void load(ISession session, PreparedStatement stmt) {
      ResultSet rs = null;
      try {
        rs = stmt.executeQuery();
        StringBuffer buf = new StringBuffer(4096);
        while (rs.next()) {
          String line1 = rs.getString(1);
          String line2 = rs.getString(2);
          buf.append(line1.trim() + " ");
          buf.append(line2.trim() + " ");
        }
        String source = "";
        if (buf.length() == 0 && sourceType == TABLE_TYPE) {
          ISQLDatabaseMetaData md = session.getMetaData();
          // TODO: Need to define a better approach to getting dialects.
          // That is, we don't really want to ever prompt the user in this
          // case.  It's always Oracle.  Yet, we may have a new OracleDialect
          // at some point.
          HibernateDialect dialect = DialectFactory.getDialect("Oracle");

          // TODO: How to let the user customize this??
          CreateScriptPreferences prefs = new CreateScriptPreferences();

          ITableInfo[] tabs = new ITableInfo[] {(ITableInfo) getDatabaseObjectInfo()};
          List<ITableInfo> tables = Arrays.asList(tabs);
          // Handle table source
          List<String> sqls = dialect.getCreateTableSQL(tables, md, prefs, false);
          String sep = session.getQueryTokenizer().getSQLStatementSeparator();
          for (String sql : sqls) {
            buf.append(sql);
            buf.append(sep);
            buf.append("\n");
          }
          source = buf.toString();
        } else {
          if (s_log.isDebugEnabled()) {
            s_log.debug("View source before formatting: " + buf.toString());
          }
          source = formatter.reformat(buf.toString());
        }
        getTextArea().setText(source);
        getTextArea().setCaretPosition(0);
      } catch (SQLException ex) {
        s_log.error("Unexpected exception: " + ex.getMessage(), ex);
        session.showErrorMessage(ex);
      } finally {
        SQLUtilities.closeResultSet(rs);
      }
    }
 private String getExplainSql(String sql) {
   StringBuilder result = new StringBuilder();
   IQueryTokenizer tokenizer = _session.getQueryTokenizer();
   tokenizer.setScriptToTokenize(sql);
   while (tokenizer.hasQuery()) {
     String query = tokenizer.nextQuery();
     result.append("BEGIN").append(tokenizer.getSQLStatementSeparator());
     result.append(EXPLAIN_PREFIX).append(query).append(tokenizer.getSQLStatementSeparator());
     result.append("ROLLBACK").append(tokenizer.getSQLStatementSeparator());
   }
   if (s_log.isDebugEnabled()) {
     s_log.debug("getExplainSql - Input: " + sql);
     s_log.debug("getExplainSql - Querys: " + tokenizer.getQueryCount());
     s_log.debug("getExplainSql - Result: " + result);
   }
   return result.toString();
 }