public void deParse(CreateTable createTable) {
    buffer.append("CREATE TABLE ").append(createTable.getTable().getFullyQualifiedName());
    if (createTable.getColumnDefinitions() != null) {
      buffer.append(" (");
      for (Iterator<ColumnDefinition> iter = createTable.getColumnDefinitions().iterator();
          iter.hasNext(); ) {
        ColumnDefinition columnDefinition = iter.next();
        buffer.append(columnDefinition.getColumnName());
        buffer.append(" ");
        buffer.append(columnDefinition.getColDataType().toString());
        if (columnDefinition.getColumnSpecStrings() != null) {
          for (String s : columnDefinition.getColumnSpecStrings()) {
            buffer.append(" ");
            buffer.append(s);
          }
        }

        if (iter.hasNext()) {
          buffer.append(", ");
        }
      }

      if (createTable.getIndexes() != null) {
        for (Iterator<Index> iter = createTable.getIndexes().iterator(); iter.hasNext(); ) {
          buffer.append(", ");
          Index index = iter.next();
          buffer.append(index.toString());
        }
      }

      buffer.append(")");
    }
  }
Exemplo n.º 2
0
  @Override
  public AuthorizationProperty generateAuthorizationProperty(Object... arguments) {

    if ((arguments == null) || (arguments.length != 1) || !(arguments[0] instanceof String)) {

      return null;
    }

    String sql = (String) arguments[0];

    Statement statement = null;

    try {
      statement = _jSqlParser.parse(new StringReader(sql));
    } catch (Exception e) {
      _log.error("Unable to parse SQL " + sql);

      return null;
    }

    String key = null;
    String value = null;

    if (statement instanceof CreateIndex) {
      key = "security-manager-sql-tables-index-create";

      CreateIndex createIndex = (CreateIndex) statement;

      Table table = createIndex.getTable();

      value = table.getName();
    } else if (statement instanceof CreateTable) {
      key = "security-manager-sql-tables-create";

      CreateTable createTable = (CreateTable) statement;

      Table table = createTable.getTable();

      value = table.getName();
    } else if (statement instanceof Delete) {
      key = "security-manager-sql-tables-delete";

      TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

      Delete delete = (Delete) statement;

      List<String> tableNames = tablesNamesFinder.getTableList(delete);

      value = StringUtil.merge(tableNames);
    } else if (statement instanceof Drop) {
      key = "security-manager-sql-tables-drop";

      Drop drop = (Drop) statement;

      value = drop.getName();
    } else if (statement instanceof Insert) {
      key = "security-manager-sql-tables-insert";

      TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

      Insert insert = (Insert) statement;

      List<String> tableNames = tablesNamesFinder.getTableList(insert);

      value = StringUtil.merge(tableNames);
    } else if (statement instanceof Replace) {
      key = "security-manager-sql-tables-replace";

      TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

      Replace replace = (Replace) statement;

      List<String> tableNames = tablesNamesFinder.getTableList(replace);

      value = StringUtil.merge(tableNames);
    } else if (statement instanceof Select) {
      key = "security-manager-sql-tables-select";

      TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

      Select select = (Select) statement;

      List<String> tableNames = tablesNamesFinder.getTableList(select);

      value = StringUtil.merge(tableNames);
    } else if (statement instanceof Truncate) {
      key = "security-manager-sql-tables-truncate";

      Truncate truncate = (Truncate) statement;

      Table table = truncate.getTable();

      value = table.getName();
    } else if (statement instanceof Update) {
      key = "security-manager-sql-tables-update";

      TablesNamesFinder tablesNamesFinder = new TablesNamesFinder();

      Update update = (Update) statement;

      List<String> tableNames = tablesNamesFinder.getTableList(update);

      value = StringUtil.merge(tableNames);
    } else {
      return null;
    }

    AuthorizationProperty authorizationProperty = new AuthorizationProperty();

    authorizationProperty.setKey(key);
    authorizationProperty.setValue(value);

    return authorizationProperty;
  }
  public void parseCreate(
      ArrayList<CreateTable> createqueries, Environment myDbEnvironment, File dataDir) {
    try {
      this.myDbEnvironment = myDbEnvironment;

      // System.out.println(createqueries);
      for (CreateTable ct : createqueries) {

        // Open the database. Create it if it does not already exist.
        DatabaseConfig dbConfig = new DatabaseConfig();
        dbConfig.setAllowCreate(true);
        dbConfig.setAllowCreate(true);
        // dbConfig.setSortedDuplicates(true);

        myDatabase = myDbEnvironment.openDatabase(null, ct.getTable().getName(), dbConfig);
        for (File data : dataDir.listFiles()) {

          if (data.getName().endsWith(".tbl") || data.getName().endsWith(".dat")) {
            if (ct.getTable()
                    .getName()
                    .toLowerCase()
                    .equals(data.getName().substring(0, data.getName().lastIndexOf('.')))
                || ct.getTable()
                    .getName()
                    .toUpperCase()
                    .equals(data.getName().substring(0, data.getName().lastIndexOf('.')))) {
              path = data;
            }
          }
        }

        ArrayList<ColumnDefinition> schema =
            (ArrayList<ColumnDefinition>) ct.getColumnDefinitions();
        // Start load phase
        LoadPhase load = new LoadPhase(myDatabase, path, myDbEnvironment, schema);

        if (ct.getTable().getName().equals("lineitem")
            || ct.getTable().getName().equals("LINEITEM")) {

          myDatabase = load.processLineItem();
        }
        if (ct.getTable().getName().equals("orders") || ct.getTable().getName().equals("ORDERS")) {
          myDatabase = load.processOrders();
        }
        if (ct.getTable().getName().equals("customer")
            || ct.getTable().getName().equals("CUSTOMER")) {
          myDatabase = load.processCustomer();
        }
        if (ct.getTable().getName().equals("supplier")
            || ct.getTable().getName().equals("SUPPLIER")) {
          myDatabase = load.processSupplier();
        }
        if (ct.getTable().getName().equals("partsupp")
            || ct.getTable().getName().equals("PARTSUPP")) {
          myDatabase = load.processPartSupp();
        }
        if (ct.getTable().getName().equals("nation") || ct.getTable().getName().equals("NATION")) {
          myDatabase = load.processNation();
        }
        if (ct.getTable().getName().equals("region") || ct.getTable().getName().equals("REGION")) {
          myDatabase = load.processRegion();
        }

        if (myDatabase != null) {
          myDatabase.close();
        }
      }

    } catch (DatabaseException dbe) {
      System.out.println("Error in database / environment" + dbe);
    }
  }
Exemplo n.º 4
0
 protected boolean hasSQL(CreateTable createTable) {
   return isAllowedTable(createTable.getTable(), _createTableNames);
 }