Пример #1
0
  public Function getFunction(String name) {
    Assert.notNull(name, "function name can not be null");
    String message = "Get database(MySql) function information error!";
    String schema = getSchemaName();

    Function p =
        JDBCUtils.query(
            dbm,
            GET_FUNCTION_SQL,
            message,
            new ResultSetExtractor<Function>() {

              public Function extractData(ResultSet rs) throws SQLException {
                Function p = null;
                while (rs.next()) {
                  String name = rs.getString("name");
                  String definition = rs.getString("definition");
                  if (p == null) {
                    p = new Function();
                    p.setName(name);
                  }
                  p.appendStr(definition);
                }
                return p;
              }
            },
            name,
            schema);

    return p;
  }
Пример #2
0
  public Map<String, Function> getFunctions() {
    String message = "Get database(mysql)  function information error!";
    String schema = getSchemaName();

    Map<String, Function> functions =
        JDBCUtils.query(
            dbm,
            GET_FUNCTIONS_SQL,
            message,
            new ResultSetExtractor<Map<String, Function>>() {

              public Map<String, Function> extractData(ResultSet rs) throws SQLException {
                Map<String, Function> functions = new HashMap<String, Function>();
                while (rs.next()) {
                  Function p = new Function();
                  String name = rs.getString("name");
                  String definition = rs.getString("definition");
                  p.setName(name);
                  p.appendStr(definition);
                  functions.put(name, p);
                }
                return functions;
              }
            },
            schema);

    return functions;
  }
Пример #3
0
  public Map<String, Procedure> getProcedures() {
    String message = "Get database(mysql)  definition information error!";

    Map<String, Procedure> procedures =
        JDBCUtils.query(
            dbm,
            GET_PROCEDURES_SQL,
            message,
            new ResultSetExtractor<Map<String, Procedure>>() {

              public Map<String, Procedure> extractData(ResultSet rs) throws SQLException {
                Map<String, Procedure> procedures = new HashMap<String, Procedure>();
                while (rs.next()) {
                  Procedure p = new Procedure();
                  String name = rs.getString("name");
                  String definition = rs.getString("definition");
                  p.setName(name);
                  p.appendStr(definition);
                  procedures.put(name, p);
                }
                return procedures;
              }
            });

    return procedures;
  }
Пример #4
0
  public Procedure getProcedure(String procedureName) {
    Assert.notNull(procedureName, "procedure name can not be null");
    String message = "Get database(MySql)  procedure information error!";
    String schema = getSchemaName();

    Procedure p =
        JDBCUtils.query(
            dbm,
            GET_PROCEDURE_SQL,
            message,
            new ResultSetExtractor<Procedure>() {

              public Procedure extractData(ResultSet rs) throws SQLException {
                Procedure p = null;
                while (rs.next()) {
                  String name = rs.getString("name");
                  String definition = rs.getString("definition");
                  if (p == null) {
                    p = new Procedure();
                    p.setName(rs.getString("name"));
                  }
                  p.appendStr(definition);
                }
                return p;
              }
            },
            procedureName,
            schema);

    return p;
  }
Пример #5
0
  protected Map<String, Trigger> crawleTriggers(String tableName, SchemaInfo schemaInfo) {
    String message = "Get database(My sql)  " + tableName + "'s triggers information error!";
    String schema;
    if (schemaInfo == null || schemaInfo.getCatalogName() == null) {
      schema = getSchemaName();
    } else {
      schema = schemaInfo.getCatalogName();
    }
    Map<String, Trigger> triggers =
        JDBCUtils.query(
            dbm,
            GET_TRIGGERS_BYTABLE_SQL,
            message,
            new ResultSetExtractor<Map<String, Trigger>>() {

              public Map<String, Trigger> extractData(ResultSet rs) throws SQLException {
                Map<String, Trigger> triggers = new HashMap<String, Trigger>();
                while (rs.next()) {
                  String definer = rs.getString("definer");
                  String trigger_schema = rs.getString("trigger_schema");
                  String trigger_name = rs.getString("trigger_name");
                  String action_timing = rs.getString("action_timing");
                  String table = rs.getString("event_object_table");
                  String action_orientation = rs.getString("action_orientation");
                  String action_statement = rs.getString("action_statement");
                  Trigger trigger = new Trigger();
                  trigger.appendStr("CREATE DEFINER = " + definer + "\n");
                  trigger.appendStr(
                      "\tTrigger "
                          + Utility.quote(trigger_schema)
                          + "."
                          + Utility.quote(trigger_name)
                          + "\n");
                  trigger.appendStr("\t" + action_timing + " on " + Utility.quote(table) + "\n");
                  trigger.appendStr("\tFor each " + action_orientation + "\n");
                  trigger.appendStr(action_statement);
                  trigger.setName(trigger_name);
                  trigger.setTableName(table);

                  triggers.put(trigger_name, trigger);
                }
                return triggers;
              }
            },
            schema,
            tableName);
    return triggers;
  }
Пример #6
0
  public Trigger getTrigger(String triggerName) {
    Assert.notNull(triggerName, "triggerName can not be null");
    String message = "Get database(Oracle) " + triggerName + "'s definition information error!";
    String schema = getSchemaName();
    Trigger trigger =
        JDBCUtils.query(
            dbm,
            GET_TRIGGER_SQL,
            message,
            new ResultSetExtractor<Trigger>() {

              public Trigger extractData(ResultSet rs) throws SQLException {
                Trigger trigger = null;
                while (rs.next()) {
                  String definer = rs.getString("definer");
                  String trigger_schema = rs.getString("trigger_schema");
                  String trigger_name = rs.getString("trigger_name");
                  String action_timing = rs.getString("action_timing");
                  String table = rs.getString("event_object_table");
                  String action_orientation = rs.getString("action_orientation");
                  String action_statement = rs.getString("action_statement");
                  trigger = new Trigger();
                  trigger.appendStr("CREATE DEFINER = " + definer + "\n");
                  trigger.appendStr(
                      "\tTrigger "
                          + Utility.quote(trigger_schema)
                          + "."
                          + Utility.quote(trigger_name)
                          + "\n");
                  trigger.appendStr("\t" + action_timing + " on " + Utility.quote(table) + "\n");
                  trigger.appendStr("\tFor each " + action_orientation + "\n");
                  trigger.appendStr(action_statement);
                  trigger.setName(trigger_name);
                  trigger.setTableName(table);
                }
                return trigger;
              }
            },
            schema,
            triggerName);
    return trigger;
  }
Пример #7
0
  public Set<String> getTriggerNames() {
    String message = "Get database(My sql) current user's trigger names";
    Set<String> names =
        JDBCUtils.query(
            dbm,
            GET_TRIGGERNAMES_SQL,
            message,
            new ResultSetExtractor<Set<String>>() {

              public Set<String> extractData(ResultSet rs) throws SQLException {
                Set<String> names = new HashSet<String>();
                while (rs.next()) {
                  String name = rs.getString("name");
                  names.add(name);
                }
                return names;
              }
            });
    return names;
  }
Пример #8
0
  /*
   * MySql only Primary key ,Foreign Key and Unique.
   *
   * (non-Javadoc)
   *
   * @see
   * com.cgs.db.meta.retriever.AbstractMetaCrawler#crawlConstraint(java.lang
   * .String, com.cgs.db.meta.schema.SchemaInfo)
   */
  protected Map<String, Constraint> crawlConstraint(String tableName, SchemaInfo schemaInfo) {
    String message = "Get database(MySql) " + tableName + "'s constraint information error!";
    Connection con;
    String schema;
    try {
      con = dbm.getConnection();
      if (schemaInfo == null) {
        schema = con.getCatalog();
      } else {
        schema = schemaInfo.getCatalogName();
      }
    } catch (SQLException e) {
      throw new DatabaseMetaGetMetaException("Get database(mysql) cataglog name error!", e);
    }

    Map<String, Constraint> constraints =
        JDBCUtils.query(
            dbm,
            GET_CONSTRAINT_SQL,
            message,
            new ResultSetExtractor<Map<String, Constraint>>() {

              public Map<String, Constraint> extractData(ResultSet rs) throws SQLException {
                Map<String, Constraint> constraints = new HashMap<String, Constraint>();
                while (rs.next()) {
                  String name = rs.getString("name");
                  String columnName = rs.getString("columnName");
                  Constraint c = new Constraint();
                  c.setName(name);
                  c.setDefinition(columnName + " IS UNIQUE");
                  c.setTableConstraintType(TableConstraintType.unique);
                  constraints.put(name, c);
                }
                return constraints;
              }
            },
            schema,
            tableName);
    return constraints;
  }
Пример #9
0
  public Set<String> getFunctionNames() {
    String message = "Get database(My sql) current user's function names";
    String schema = getSchemaName();
    Set<String> names =
        JDBCUtils.query(
            dbm,
            GET_FUNCTIONNAME_SQL,
            message,
            new ResultSetExtractor<Set<String>>() {

              public Set<String> extractData(ResultSet rs) throws SQLException {
                Set<String> names = new HashSet<String>();
                while (rs.next()) {
                  String name = rs.getString("name");
                  names.add(name);
                }
                return names;
              }
            },
            schema);
    return names;
  }