Esempio n. 1
0
 private String getCoreSQL(RuleReturnScope parsedSQL) {
   final CommonTree ast = (CommonTree) parsedSQL.getTree();
   final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
   final CharStream inputStream = nameToken.getInputStream();
   final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
   return inputStream.substring(nameToken.getStartIndex(), stopToken.getStopIndex());
 }
Esempio n. 2
0
  /**
   * @param sql
   * @param alterTableDef
   * @return
   * @throws SqlJetException
   */
  private String getTableAlteredSql(String sql, SqlJetAlterTableDef alterTableDef)
      throws SqlJetException {

    final RuleReturnScope parsedSQL = parseTable(sql);
    final CommonTree ast = (CommonTree) parsedSQL.getTree();
    final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(1)).getToken();
    final CharStream inputStream = nameToken.getInputStream();
    final CommonToken stopToken = (CommonToken) parsedSQL.getStop();

    final StringBuilder b = new StringBuilder();

    if (alterTableDef.getNewTableName() != null) {
      b.append(inputStream.substring(0, nameToken.getStartIndex() - 1));
      b.append(getAlterTableName(alterTableDef));
      b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex()));
    } else if (alterTableDef.getNewColumnDef() != null) {
      b.append(inputStream.substring(0, stopToken.getStartIndex() - 1));
      b.append(",").append(getAlterTableName(alterTableDef));
      b.append(inputStream.substring(stopToken.getStartIndex(), stopToken.getStopIndex()));
    } else {
      throw new SqlJetException("Wrong ALTER TABLE statement");
    }

    return b.toString();
  }
Esempio n. 3
0
  private ISqlJetVirtualTableDef createVirtualTableSafe(String sql, int page)
      throws SqlJetException {

    final RuleReturnScope parseTable = parseTable(sql);
    final CommonTree ast = (CommonTree) parseTable.getTree();

    if (!isCreateVirtualTable(ast)) {
      throw new SqlJetException(SqlJetErrorCode.ERROR);
    }

    final SqlJetVirtualTableDef tableDef = new SqlJetVirtualTableDef(ast, 0);
    if (null == tableDef.getTableName()) throw new SqlJetException(SqlJetErrorCode.ERROR);
    final String tableName = tableDef.getTableName();
    if ("".equals(tableName)) {
      throw new SqlJetException(SqlJetErrorCode.ERROR);
    }

    checkNameReserved(tableName);
    checkFieldNamesRepeatsConflict(tableDef.getTableName(), tableDef.getModuleColumns());

    if (virtualTableDefs.containsKey(tableName)) {
      throw new SqlJetException(
          SqlJetErrorCode.ERROR, "Virtual table \"" + tableName + "\" exists already");
    }

    checkNameConflict(SqlJetSchemaObjectType.VIRTUAL_TABLE, tableName);

    final ISqlJetBtreeSchemaTable schemaTable = openSchemaTable(true);
    final String createVirtualTableSQL = getCreateVirtualTableSql(parseTable);

    try {

      schemaTable.lock();

      try {

        db.getOptions().changeSchemaVersion();

        final long rowId =
            schemaTable.insertRecord(TABLE_TYPE, tableName, tableName, page, createVirtualTableSQL);

        tableDef.setPage(page);
        tableDef.setRowId(rowId);
        virtualTableDefs.put(tableName, tableDef);
        return tableDef;

      } finally {
        schemaTable.unlock();
      }

    } finally {
      schemaTable.close();
    }
  }
Esempio n. 4
0
 /**
  * @param sql
  * @param alterTableName
  * @return
  * @throws SqlJetException
  */
 private String getAlteredIndexSql(String sql, String alterTableName) throws SqlJetException {
   final RuleReturnScope parsedSQL = parseIndex(sql);
   final CommonTree ast = (CommonTree) parsedSQL.getTree();
   final CommonToken nameToken = (CommonToken) ((CommonTree) ast.getChild(2)).getToken();
   final CharStream inputStream = nameToken.getInputStream();
   final CommonToken stopToken = (CommonToken) parsedSQL.getStop();
   final StringBuilder b = new StringBuilder();
   b.append(inputStream.substring(0, nameToken.getStartIndex() - 1));
   b.append(alterTableName);
   b.append(inputStream.substring(nameToken.getStopIndex() + 1, stopToken.getStopIndex()));
   return b.toString();
 }
  // $ANTLR start "tag"
  // C:\\workspace-sts\\Kettle trunk -
  // restruct\\engine\\src\\org\\pentaho\\di\\trans\\steps\\edi2xml\\grammar\\FastSimpleGenericEdifactDirectXML.g:108:1: tag returns [String name, List indexes] : tag_name ( ds i+= tag_index_id )* ;
  public final FastSimpleGenericEdifactDirectXMLParser.tag_return tag()
      throws RecognitionException {
    FastSimpleGenericEdifactDirectXMLParser.tag_return retval =
        new FastSimpleGenericEdifactDirectXMLParser.tag_return();
    retval.start = input.LT(1);

    List list_i = null;
    FastSimpleGenericEdifactDirectXMLParser.tag_name_return tag_name3 = null;

    RuleReturnScope i = null;
    try {
      // C:\\workspace-sts\\Kettle trunk -
      // restruct\\engine\\src\\org\\pentaho\\di\\trans\\steps\\edi2xml\\grammar\\FastSimpleGenericEdifactDirectXML.g:108:41: ( tag_name ( ds i+= tag_index_id )* )
      // C:\\workspace-sts\\Kettle trunk -
      // restruct\\engine\\src\\org\\pentaho\\di\\trans\\steps\\edi2xml\\grammar\\FastSimpleGenericEdifactDirectXML.g:108:43: tag_name ( ds i+= tag_index_id )*
      {
        pushFollow(FOLLOW_tag_name_in_tag208);
        tag_name3 = tag_name();

        state._fsp--;

        tagIndexes.clear();

        // C:\\workspace-sts\\Kettle trunk -
        // restruct\\engine\\src\\org\\pentaho\\di\\trans\\steps\\edi2xml\\grammar\\FastSimpleGenericEdifactDirectXML.g:108:74: ( ds i+= tag_index_id )*
        loop7:
        do {
          int alt7 = 2;
          int LA7_0 = input.LA(1);

          if ((LA7_0 == COMPLEX_ELEMENT_ITEM_SEPARATOR)) {
            alt7 = 1;
          }

          switch (alt7) {
            case 1:
              // C:\\workspace-sts\\Kettle trunk -
              // restruct\\engine\\src\\org\\pentaho\\di\\trans\\steps\\edi2xml\\grammar\\FastSimpleGenericEdifactDirectXML.g:108:75: ds i+= tag_index_id
              {
                pushFollow(FOLLOW_ds_in_tag213);
                ds();

                state._fsp--;

                pushFollow(FOLLOW_tag_index_id_in_tag217);
                i = tag_index_id();

                state._fsp--;

                if (list_i == null) list_i = new ArrayList();
                list_i.add(i.getTemplate());
              }
              break;

            default:
              break loop7;
          }
        } while (true);

        retval.name =
            (tag_name3 != null ? input.toString(tag_name3.start, tag_name3.stop) : null).trim();
      }

      retval.stop = input.LT(-1);

    }

    // do not try to recover from parse errors, propagate the error instead
    catch (RecognitionException e) {
      throw e;
    } finally {
      // do for sure before leaving
    }
    return retval;
  }
Esempio n. 6
0
  private ISqlJetTableDef createTableSafe(String sql, boolean internal) throws SqlJetException {

    final RuleReturnScope parseTable = parseTable(sql);
    final CommonTree ast = (CommonTree) parseTable.getTree();

    if (isCreateVirtualTable(ast)) {
      throw new SqlJetException(SqlJetErrorCode.ERROR);
    }

    final SqlJetTableDef tableDef = new SqlJetTableDef(ast, 0);
    if (null == tableDef.getName()) throw new SqlJetException(SqlJetErrorCode.ERROR);
    final String tableName = tableDef.getName();
    if ("".equals(tableName)) throw new SqlJetException(SqlJetErrorCode.ERROR);

    if (!internal) {
      checkNameReserved(tableName);
    }

    if (tableDefs.containsKey(tableName)) {
      if (tableDef.isKeepExisting()) {
        return tableDefs.get(tableName);
      } else {
        throw new SqlJetException(
            SqlJetErrorCode.ERROR, "Table \"" + tableName + "\" exists already");
      }
    }

    checkNameConflict(SqlJetSchemaObjectType.TABLE, tableName);
    checkFieldNamesRepeatsConflict(tableDef.getName(), tableDef.getColumns());

    final List<ISqlJetColumnDef> columns = tableDef.getColumns();
    if (null == columns || 0 == columns.size()) throw new SqlJetException(SqlJetErrorCode.ERROR);

    final String createTableSql = getCreateTableSql(parseTable);

    final ISqlJetBtreeSchemaTable schemaTable = openSchemaTable(true);

    try {

      schemaTable.lock();

      try {

        db.getOptions().changeSchemaVersion();

        final int page = btree.createTable(BTREE_CREATE_TABLE_FLAGS);
        final long rowId =
            schemaTable.insertRecord(TABLE_TYPE, tableName, tableName, page, createTableSql);

        addConstraints(schemaTable, tableDef);

        tableDef.setPage(page);
        tableDef.setRowId(rowId);
        tableDefs.put(tableName, tableDef);
        return tableDef;

      } finally {
        schemaTable.unlock();
      }

    } finally {
      schemaTable.close();
    }
  }