Exemplo n.º 1
0
  public TargetSchema(final SourceSchema schema, JdbcLinkObject conObject) {
    this.sourceSchema = schema;
    Log.debug("Creating JDBC schema");
    // Remember the settings.
    this.conObj = conObject;

    if (conObject != null) {
      Log.debug("Creating schema " + conObject.getDatabaseName());
      this.setKeyGuessing(conObject.isKeyGuessing());
      this.setDataLinkSchema(conObject.getSchemaName());
      this.setDataLinkDatabase(conObject.getDatabaseName());
    }
  }
Exemplo n.º 2
0
 /**
  * hardcoded for icgc update command line
  *
  * @param conObj
  * @return
  * @throws MartBuilderException
  */
 public List<String> getMainTables(JdbcLinkObject conObj) throws MartBuilderException {
   StringBuffer sb =
       new StringBuffer(
           "select table_name,column_name,column_key "
               + "from information_schema.columns where table_schema='"
               + conObj.getSchemaName()
               + "' and "
               + "table_name like '%__main' order by table_name");
   List<Map<String, String>> resultSet = ConnectionPool.Instance.query(conObj, sb.toString());
   Set<String> tmp = new HashSet<String>();
   for (Map<String, String> map : resultSet) {
     String mainTableName = (String) map.get("table_name");
     String tmpMartName = mainTableName.split("__")[0];
     tmp.add(tmpMartName);
   }
   List<String> result = new ArrayList<String>(tmp);
   return result;
 }
Exemplo n.º 3
0
  public Map<String, List<String>> getMartTablesInfo(JdbcLinkObject conObj, String dsName)
      throws MartBuilderException {
    Map<String, List<String>> tblColMap =
        new TreeMap<String, List<String>>(McUtils.BETTER_STRING_COMPARATOR); // see DCCTEST-491
    List<String> colList = new ArrayList<String>();
    StringBuffer sb =
        new StringBuffer(
            "select table_name,column_name,column_key "
                + "from information_schema.columns where table_schema='"
                + conObj.getDatabaseName()
                + "' and "
                + "table_name like '"
                + dsName
                + "%' order by "
                + "table_name, ordinal_position");
    String lastTableName = "";
    List<Map<String, String>> resultSet = ConnectionPool.Instance.query(conObj, sb.toString());

    for (Map<String, String> mapItem : resultSet) {
      String tableName = (String) mapItem.get("table_name");
      if (!(tableName.endsWith("__main") || tableName.endsWith("__dm"))) {
        continue;
      }
      // finish all columns in one table and move to the next, if previous table doesn't have a PK,
      // create using keyguessing
      if (!lastTableName.equals(tableName)) {
        if (!lastTableName.equals("")) {
          tblColMap.put(lastTableName, colList);
          colList = new ArrayList<String>();
        }
        // move to next table
        // clean flags
        lastTableName = tableName;
      }
      colList.add((String) mapItem.get("column_name"));
    }

    // sort column list
    Collections.sort(colList, McUtils.BETTER_STRING_COMPARATOR); // see DCCTEST-491

    if (!McUtils.isStringEmpty(lastTableName)) tblColMap.put(lastTableName, colList);

    return tblColMap;
  }
Exemplo n.º 4
0
  @Override
  public Set<String> getPartitionedTables(JdbcLinkObject conObj, String partitionBase)
      throws MartBuilderException {
    Set<String> tables = new TreeSet<String>(McUtils.BETTER_STRING_COMPARATOR); // see DCCTEST-491
    StringBuffer sb =
        new StringBuffer(
            "select table_name "
                + "from information_schema.columns where table_schema='"
                + conObj.getDatabaseName()
                + "' and "
                + "table_name like '"
                + partitionBase
                + "%'");

    List<Map<String, String>> resultSet = ConnectionPool.Instance.query(conObj, sb.toString());

    for (Map<String, String> mapItem : resultSet) {
      String tableName = (String) mapItem.get("table_name");
      tables.add(tableName);
    }

    return tables;
  }
Exemplo n.º 5
0
  public Connection getConnection() throws SQLException {
    // If we are already connected, test to see if we are
    // still connected. If not, reset our connection.
    if (this.connection != null && this.connection.isClosed())
      try {
        Log.debug("Closing dead JDBC connection");
        this.connection.close();
      } catch (final SQLException e) {
        // We don't care. Ignore it.
      } finally {
        this.connection = null;
      }

    // If we are not connected, we should attempt to (re)connect now.
    if (this.connection == null) {
      Log.debug("Establishing JDBC connection");
      // Start out with no driver at all.
      Class loadedDriverClass = null;

      // Try the system class loader instead.
      try {
        loadedDriverClass = Class.forName(this.conObj.getJdbcType().getDriverClassName());
      } catch (final ClassNotFoundException e) {
        final SQLException e2 = new SQLException();
        e2.initCause(e);
        throw e2;
      }

      // Check it really is an instance of Driver.
      if (!Driver.class.isAssignableFrom(loadedDriverClass))
        throw new ClassCastException(Resources.get("driverClassNotJDBCDriver"));

      // Connect!
      final Properties properties = new Properties();
      properties.setProperty("user", this.conObj.getUserName());
      if (!this.conObj.getPassword().equals(""))
        properties.setProperty("password", this.conObj.getPassword());
      properties.setProperty("nullCatalogMeansCurrent", "false");
      /*
       * this.connection = DriverManager.getConnection( overrideDataLinkSchema == null ? this.conObj.getJdbcUrl():
       * (this.conObj.getJdbcUrl()) .replaceAll(this.getDataLinkSchema(), overrideDataLinkSchema), properties);
       */

      this.connection =
          DriverManager.getConnection(
              this.conObj.getJdbcUrl(), conObj.getUserName(), conObj.getPassword());
      // Check the schema name.
      final DatabaseMetaData dmd = this.connection.getMetaData();
      final String catalog = this.connection.getCatalog();
      this.realSchemaName = this.getDataLinkSchema();
      ResultSet rs = dmd.getTables(catalog, this.realSchemaName, "%", null);
      if (!rs.next()) {
        rs = dmd.getTables(catalog, this.realSchemaName.toUpperCase(), "%", null);
        if (rs.next()) this.realSchemaName = this.realSchemaName.toUpperCase();
      }
      if (!rs.next()) {
        rs = dmd.getTables(catalog, this.realSchemaName.toLowerCase(), "%", null);
        if (rs.next()) this.realSchemaName = this.realSchemaName.toLowerCase();
      }
      rs.close();
    }

    // Return the connection.
    return this.connection;
  }