public void translate(AlterTable alterTable) throws SQLException {
    Table table = alterTable.getTable();
    for (AlterOperation alterOperation : alterTable.getAlterOperations()) {
      switch (alterOperation.getType()) {
        case ADD:
          {
            AddColumn addColumn = (AddColumn) alterOperation;
            String schemaName = Helper.getSchemaName(this.connector, table);
            String dataType = addColumn.getColumnDefinition().getColDataType().getDataType();
            String columnName = addColumn.getColumnDefinition().getColumnName();
            Integer domainId, type3domainId;
            if ((domainId = getFuzzyDomainId(schemaName, dataType, "5")) != null) {
              type3domainId = Helper.getType3DomainIdRelated(connector, domainId);

              operations.add(
                  new AddFuzzyColumnOperation(
                      connector, schemaName, table.getName(), columnName, domainId, type3domainId));
            }
            break;
          }
        case DROP:
          {
            DropColumn dropColumn = (DropColumn) alterOperation;
            String schemaName = Helper.getSchemaName(this.connector, table);
            String columnName = dropColumn.getColumnOld();
            operations.add(
                new RemoveFuzzyColumnsOperation(
                    connector, schemaName, table.getName(), columnName));
            break;
          }
      }
    }
  }
 private static List getTableColumns(ISession session, Table table) throws IOException {
   List colNames = new ArrayList();
   String tableName = table.getSchemaName() + "." + table.getName();
   SeColumnDefinition[] cols = session.describe(tableName);
   for (int i = 0; i < cols.length; i++) {
     String colName = cols[i].getName();
     colName = tableName + "." + colName;
     colNames.add(colName);
   }
   return colNames;
 }
 public Datum[] convertType(String[] singleTableElement) {
   // Map tupleKeyValueMap = new HashMap();
   String key = null, value = null, type = null;
   Column col = null;
   Datum[] t = new Datum[singleTableElement.length];
   int i = 0;
   int j = 0;
   while (tableMap.size() != j
       && !tableMap
           .get(j)
           .getTable()
           .toString()
           .equalsIgnoreCase(tableName.getName().toString())) {
     j++;
   }
   while (i < singleTableElement.length) {
     col = tableMap.get(j);
     value = singleTableElement[i];
     type = tableColTypeMap.get(tableName.getName().toString().toLowerCase()).get(i).toLowerCase();
     if (type.equalsIgnoreCase("int")) {
       // tupleKeyValueMap.put(key, Integer.parseInt(value));
       t[i] = new Datum.dLong(singleTableElement[i], new Column(tableName, col.getColumnName()));
       // System.out.print(t[i].toComString());
     } else if (type.equalsIgnoreCase("decimal")) {
       // tupleKeyValueMap.put(key, Integer.parseInt(value));
       t[i] =
           new Datum.dDecimal(singleTableElement[i], new Column(tableName, col.getColumnName()));
       // System.out.print(t[i].toComString());
     } else if (type.equalsIgnoreCase("String")
         || type.startsWith("char")
         || type.startsWith("varchar")) {
       // tupleKeyValueMap.put(key, value);
       t[i] = new Datum.dString(singleTableElement[i], new Column(tableName, col.getColumnName()));
       // System.out.print(t[i].toComString());
     } else if (type.equalsIgnoreCase("date")) {
       // tupleKeyValueMap.put(key, (new SimpleDateFormat(
       // "YYYY-MM-DD", Locale.ENGLISH).parse(value)));
       t[i] = new Datum.dDate(singleTableElement[i], new Column(tableName, col.getColumnName()));
       // System.out.print(t[i].toComString());
     } else {
       try {
         throw new Exception("Not aware of this data type :: " + type);
       } catch (Exception e) {
         // TODO Auto-generated catch block
         e.printStackTrace();
       }
     }
     i++;
     j++;
   }
   return t;
 }
Beispiel #4
0
  public static String getDomainNameForColumn(Connector c, Table table, String columnName)
      throws SQLException {
    String schemaName = Helper.getSchemaName(c, table);
    String tableName = table.getName();
    String sql =
        "SELECT domain_name "
            + "FROM information_schema_fuzzy.domains AS D JOIN "
            + "information_schema_fuzzy.columns AS C ON (D.domain_id = C.domain_id) "
            + "WHERE C.table_schema = '"
            + schemaName
            + "' "
            + "AND C.table_name = '"
            + tableName
            + "' "
            + "AND C.column_name = '"
            + columnName
            + "'";

    Logger.debug("Looking for domain name with query:\n" + sql);

    ResultSet rs = c.executeRawQuery(sql);
    SQLException e = null;
    try {
      if (rs.first()) {
        return rs.getString("domain_name");
      }
    } catch (SQLException ex) {
      e = ex;
    }
    throw new SQLException(
        "Domain name not found for " + schemaName + "." + tableName + "." + columnName,
        "42000",
        3020,
        e);
  }
Beispiel #5
0
 @Override
 public String toString() {
   StringBuilder b = new StringBuilder();
   b.append("ALTER TABLE ").append(table.getFullyQualifiedName()).append(" ADD ");
   if (columnName != null) {
     b.append("COLUMN ").append(columnName).append(" ").append(dataType.toString());
   } else if (pkColumns != null) {
     b.append("PRIMARY KEY (").append(PlainSelect.getStringList(pkColumns)).append(")");
   } else if (ukColumns != null) {
     b.append("UNIQUE KEY ")
         .append(ukName)
         .append(" (")
         .append(PlainSelect.getStringList(ukColumns))
         .append(")");
   } else if (fkColumns != null) {
     b.append("FOREIGN KEY (")
         .append(PlainSelect.getStringList(fkColumns))
         .append(") REFERENCES ")
         .append(fkSourceTable)
         .append(" (")
         .append(PlainSelect.getStringList(fkSourceColumns))
         .append(")");
     if (isOnDeleteCascade()) {
       b.append(" ON DELETE CASCADE");
     } else if (isOnDeleteRestrict()) {
       b.append(" ON DELETE RESTRICT");
     } else if (isOnDeleteSetNull()) {
       b.append(" ON DELETE SET NULL");
     }
   } else if (fkIndex != null) {
     b.append(fkIndex);
   }
   return b.toString();
 }
  ProjectOperator(Operator op, ArrayList<SelectExpressionItem> p, Table table, boolean allColumns) {

    this.op = op;
    this.tuple = new Object[p.size()];
    this.toProject = p;
    this.table = table;
    this.schema = Utility.tables.get(table.getAlias());
    this.allColumns = allColumns;
  }
  /* (non-Javadoc)
   * @see edu.buffalo.cse562.Operator#readOneTuple()
   */
  public ScanOperatorPlain(Table table) {

    this.tableName = table.getName();
    this.tableAlias = table.getAlias();

    HashMap<String, ColumnDetail> intSchema = Main.tableMapping.get(this.tableName.toLowerCase());
    this.indexMaps = Main.indexTypeMaps.get(this.tableName.toLowerCase());
    if (intSchema == null) {
      intSchema = Main.tableMapping.get(this.tableName.toUpperCase());
      this.indexMaps = Main.indexTypeMaps.get(this.tableName.toUpperCase());
    }
    this.operatorTableSchema = this.initialiseOperatorTableSchema(intSchema);

    this.dataFile =
        FileSystems.getDefault()
            .getPath(ConfigManager.getDataDir(), tableName.toLowerCase() + ".dat");

    reset();
  }
 public FileScanOperator(
     Table tableName,
     String dirName,
     List<Column> tableMap2,
     Map<String, ArrayList<String>> tableColTypeMap) {
   this.dirName = dirName;
   this.tableMap = tableMap2;
   this.tableName = tableName;
   this.tableColTypeMap = tableColTypeMap;
   String basePath = dirName + File.separator + tableName.getName() + ".dat";
   if (!(new File(basePath).exists())) {
     tablefile = new File("").getAbsolutePath() + File.separator + basePath;
   } else {
     tablefile = basePath;
   }
   resetStream();
   this.bufferMaxSize = 1000;
   this.bufferPointer = -1;
   this.buffer = new ArrayList<Datum[]>(bufferMaxSize);
   this.isEnd = false;
 }
Beispiel #9
0
 public static String getSchemaName(Connector c, Table table) throws SQLException {
   return table.getSchemaName() != null ? table.getSchemaName() : getSchemaName(c);
 }
Beispiel #10
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;
  }
Beispiel #11
0
  protected boolean isAllowedTable(Table table, Set<String> allowedTableNames) {

    String tableName = table.getName();

    return isAllowedTable(tableName, allowedTableNames);
  }
 @Override
 public void visit(Table table) {
   TableScan tableScan = PlanFactory.getInstance().newTableScan(table.getName());
   relationProvider = PlanFactory.getInstance().newSelection();
   ((Selection) relationProvider).setInput(tableScan, getWhere(tableScan));
 }
 @Override
 public void visit(Table table) {
   tableName = table.getName();
 }