public ArrayList<FaqCategories> select() throws SQLException {
    try {
      connection = ConnectionFactory.getInstance().getConnection();
      cs = connection.prepareCall("{Call faq_categories_FindAll}");
      resultSet = cs.executeQuery();

      ArrayList<FaqCategories> list = new ArrayList<FaqCategories>();
      while (resultSet.next()) {
        FaqCategories faqc =
            new FaqCategories(
                resultSet.getInt("idFAQ_Categories"),
                resultSet.getInt("idLanguage"),
                resultSet.getString("categoy_name"),
                resultSet.getString("category_description"));
        list.add(faqc);
      }
      return list;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
      if (cs != null) {
        cs.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
  public FaqCategories selectById(int id) throws SQLException {
    try {
      connection = ConnectionFactory.getInstance().getConnection();
      cs = connection.prepareCall("{call faq_categories_FindByPK(?)}");

      cs.setInt(1, id);

      resultSet = cs.executeQuery();
      FaqCategories faqc = null;
      while (resultSet.next()) {
        faqc =
            new FaqCategories(
                resultSet.getInt("idFAQ_Categories"),
                resultSet.getInt("idLanguage"),
                resultSet.getString("category_name"),
                resultSet.getString("category_description"));
      }
      return faqc;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
      if (cs != null) {
        cs.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
 static {
   // determine good/bad nodes:
   final ConnectionFactory cf = ConnectionFactory.getInstance();
   cf.testAllNodes();
   // set not to automatically try reconnects (auto-retries prevent ConnectionException tests from
   // working):
   final DefaultConnectionPolicy cp = ((DefaultConnectionPolicy) cf.getConnectionPolicy());
   cp.setMaxRetries(0);
   scalarisNode = cp.selectNode().toString();
 }
  @GET
  @Path("/getworkflows")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getWork() {
    DBCursor obj = null;
    try {
      DB db = ConnectionFactory.getInstance().getConnection();
      DBCollection coll = db.getCollection("mail");
      obj = coll.find();
      System.out.println(obj);
    } catch (UnknownHostException ex) {
      Logger.getLogger(MongoResource.class.getName()).log(Level.SEVERE, null, ex);
    }

    return Response.status(Response.Status.OK).entity(obj.toArray()).build();
  }
  public boolean delete(int idFaqc) throws SQLException {
    try {
      connection = ConnectionFactory.getInstance().getConnection();
      cs = connection.prepareCall("{Call faq_categories_Delete(?)}");

      cs.setInt(1, idFaqc);

      cs.execute();
      return true;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
      if (cs != null) {
        cs.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
  public void insert(FaqCategories faqc) throws SQLException {
    try {

      connection = ConnectionFactory.getInstance().getConnection();
      cs = connection.prepareCall("{Call faq_categories_insert(?,?,?)}");

      cs.setInt(1, faqc.getIdLanguage());
      cs.setString(2, faqc.getCategoryName());
      cs.setString(3, faqc.getCategoryDescription());

      cs.execute();
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
      if (cs != null) {
        cs.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
Beispiel #7
0
  public Map<String, List<String>> querySchema(DBConfig config) {
    Map<String, List<String>> map = new HashMap<String, List<String>>();
    List<String> schemaList = config.getSchemaList();
    Connection conn = null;
    DatabaseMetaData databaseMetaData = null;
    try {
      conn = ConnectionFactory.getInstance().getConnection(config);
      databaseMetaData = conn.getMetaData();
    } catch (Exception e) {
      e.printStackTrace();
      return map;
    }

    for (String schema : schemaList) {
      List<String> tableList = new ArrayList<String>();
      try {
        String localSchema = schema;
        if (databaseMetaData.storesLowerCaseIdentifiers()) {
          localSchema = localSchema == null ? null : localSchema.toLowerCase();
        } else if (databaseMetaData.storesUpperCaseIdentifiers()) {
          localSchema = localSchema == null ? null : localSchema.toUpperCase();
        }

        ResultSet rs = databaseMetaData.getTables(null, localSchema, null, null);
        while (rs.next()) {
          String tableName = rs.getString("TABLE_NAME");
          tableList.add(tableName);
          // System.out.println(tableName);
        }
        map.put(schema, tableList);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }

    return map;
  }
  public ArrayList<FaqCategories> view(String lang) throws SQLException {
    try {
      connection = ConnectionFactory.getInstance().getConnection();
      cs = connection.prepareCall("{call faq_categories_view(?)}");

      cs.setString(1, lang);

      resultSet = cs.executeQuery();

      ArrayList<FaqCategories> list = new ArrayList<FaqCategories>();
      while (resultSet.next()) {
        FaqAdapter faqadp = new FaqAdapter();
        ArrayList<Faq> fqlist = faqadp.view(lang, resultSet.getInt("idFAQ_Categories"));

        FaqCategories faqc =
            new FaqCategories(
                resultSet.getInt("idFAQ_Categories"),
                resultSet.getInt("idLanguage"),
                resultSet.getString("category_name"),
                resultSet.getString("category_description"),
                fqlist);
        list.add(faqc);
      }
      return list;
    } finally {
      if (resultSet != null) {
        resultSet.close();
      }
      if (cs != null) {
        cs.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
Beispiel #9
0
  /**
   * Queries the command line options for an action to perform.
   *
   * <pre>
   * <code>
   * > java -jar scalaris.jar -help
   * usage: scalaris [Options]
   *  -b,--minibench                   run mini benchmark
   *  -d,--delete <key> <[timeout]>    delete an item (default timeout: 2000ms)
   *                                   WARNING: This function can lead to
   *                                   inconsistent data (e.g. deleted items
   *                                   can re-appear). Also when re-creating an
   *                                   item the version before the delete can
   *                                   re-appear.
   *  -g,--getsubscribers <topic>      get subscribers of a topic
   *  -h,--help                        print this message
   *  -lh,--localhost                  gets the local host's name as known to
   *                                   Java (for debugging purposes)
   *  -p,--publish <topic> <message>   publish a new message for the given
   *                                   topic
   *  -r,--read <key>                  read an item
   *  -s,--subscribe <topic> <url>     subscribe to a topic
   *  -u,--unsubscribe <topic> <url>   unsubscribe from a topic
   *  -v,--verbose                     print verbose information, e.g. the
   *                                   properties read
   *  -w,--write <key> <value>         write an item
   * </code>
   * </pre>
   *
   * @param args command line arguments
   */
  public static void main(String[] args) {
    boolean verbose = false;
    CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    Options options = getOptions();
    try {
      line = parser.parse(options, args);
    } catch (ParseException e) {
      printException("Parsing failed", e, false);
    }

    if (line.hasOption("verbose")) {
      verbose = true;
      ConnectionFactory.getInstance().printProperties();
    }

    if (line.hasOption("minibench")) {
      Benchmark.minibench();
    } else if (line.hasOption("r")) { // read
      String key = line.getOptionValue("read");
      checkArguments(key, options, "r");
      try {
        Scalaris sc = new Scalaris();
        String value = sc.read(key);
        System.out.println("read(" + key + ") == " + value);
      } catch (ConnectionException e) {
        printException("read failed with connection error", e, verbose);
      } catch (TimeoutException e) {
        printException("read failed with timeout", e, verbose);
      } catch (NotFoundException e) {
        printException("read failed with not found", e, verbose);
      } catch (UnknownException e) {
        printException("read failed with unknown", e, verbose);
      }
    } else if (line.hasOption("w")) { // write
      String[] optionValues = line.getOptionValues("write");
      checkArguments(optionValues, 2, options, "w");
      String key = optionValues[0];
      String value = optionValues[1];
      try {
        Scalaris sc = new Scalaris();
        sc.write(key, value);
        System.out.println("write(" + key + ", " + value + ")");
      } catch (ConnectionException e) {
        printException("write failed with connection error", e, verbose);
      } catch (TimeoutException e) {
        printException("write failed with timeout", e, verbose);
      } catch (UnknownException e) {
        printException("write failed with unknown", e, verbose);
      }
    } else if (line.hasOption("p")) { // publish
      String[] optionValues = line.getOptionValues("publish");
      checkArguments(optionValues, 2, options, "p");
      String topic = optionValues[0];
      String content = optionValues[1];
      if (content == null) {
        // parsing methods of commons.cli only checks the first argument :(
        printException(
            "Parsing failed", new ParseException("missing content for option p"), verbose);
      }
      try {
        Scalaris sc = new Scalaris();
        sc.publish(topic, content);
        System.out.println("publish(" + topic + ", " + content + ")");
      } catch (ConnectionException e) {
        printException("publish failed with connection error", e, verbose);
      }
    } else if (line.hasOption("s")) { // subscribe
      String[] optionValues = line.getOptionValues("subscribe");
      checkArguments(optionValues, 2, options, "s");
      String topic = optionValues[0];
      String url = optionValues[1];
      try {
        Scalaris sc = new Scalaris();
        sc.subscribe(topic, url);
        System.out.println("subscribe(" + topic + ", " + url + ")");
      } catch (ConnectionException e) {
        printException("subscribe failed with connection error", e, verbose);
      } catch (TimeoutException e) {
        printException("subscribe failed with timeout", e, verbose);
      } catch (UnknownException e) {
        printException("subscribe failed with unknown", e, verbose);
      }
    } else if (line.hasOption("u")) { // unsubscribe
      String[] optionValues = line.getOptionValues("unsubscribe");
      checkArguments(optionValues, 2, options, "u");
      String topic = optionValues[0];
      String url = optionValues[1];
      try {
        Scalaris sc = new Scalaris();
        sc.unsubscribe(topic, url);
        System.out.println("unsubscribe(" + topic + ", " + url + ")");
      } catch (ConnectionException e) {
        printException("unsubscribe failed with connection error", e, verbose);
      } catch (TimeoutException e) {
        printException("unsubscribe failed with timeout", e, verbose);
      } catch (NotFoundException e) {
        printException("unsubscribe failed with not found", e, verbose);
      } catch (UnknownException e) {
        printException("unsubscribe failed with unknown", e, verbose);
      }
    } else if (line.hasOption("g")) { // getsubscribers
      String topic = line.getOptionValue("getsubscribers");
      checkArguments(topic, options, "g");
      try {
        Scalaris sc = new Scalaris();
        ArrayList<String> subscribers = sc.getSubscribers(topic);
        System.out.println("getSubscribers(" + topic + ") == " + subscribers);
      } catch (ConnectionException e) {
        printException("getSubscribers failed with connection error", e, verbose);
      } catch (UnknownException e) {
        printException("getSubscribers failed with unknown error", e, verbose);
      }
    } else if (line.hasOption("d")) { // delete
      String[] optionValues = line.getOptionValues("delete");
      checkArguments(optionValues, 1, options, "d");
      String key = optionValues[0];
      int timeout = 2000;
      if (optionValues.length >= 2) {
        try {
          timeout = Integer.parseInt(optionValues[1]);
        } catch (Exception e) {
          printException(
              "Parsing failed",
              new ParseException(
                  "wrong type for timeout parameter of option d"
                      + " (parameters: <"
                      + options.getOption("d").getArgName()
                      + ">)"),
              verbose);
        }
      }
      try {
        Scalaris sc = new Scalaris();
        sc.delete(key, timeout);
        DeleteResult deleteResult = sc.getLastDeleteResult();
        System.out.println(
            "delete("
                + key
                + ", "
                + timeout
                + "): "
                + deleteResult.ok
                + " ok, "
                + deleteResult.locks_set
                + " locks_set, "
                + deleteResult.undef
                + " undef");
      } catch (ConnectionException e) {
        printException("delete failed with connection error", e, verbose);
      } catch (TimeoutException e) {
        printException("delete failed with timeout", e, verbose);
      } catch (NodeNotFoundException e) {
        printException("delete failed with node not found", e, verbose);
      } catch (UnknownException e) {
        printException("delete failed with unknown error", e, verbose);
      }
    } else if (line.hasOption("lh")) { // get local host name
      System.out.println(ConnectionFactory.getLocalhostName());
    } else {
      // print help if no other option was given
      //		if (line.hasOption("help")) {
      HelpFormatter formatter = new HelpFormatter();
      formatter.printHelp("scalaris [Options]", getOptions());
    }
  }
Beispiel #10
0
  /**
   * Queries the command line options for an action to perform.
   *
   * <pre>
   * <code>
   * > java -jar scalaris.jar --help
   * usage: scalaris [Options]
   *  -h,--help                                   print this message
   *  -v,--verbose                                print verbose information,
   *                                              e.g. the properties read
   *  -lh,--localhost                             gets the local host's name as
   *                                              known to Java (for debugging
   *                                              purposes)
   *  -b,--minibench <[ops]> <[tpn]> <[benchs]>   run selected mini
   *                                              benchmark(s) [1|...|18|all]
   *                                              (default: all benchmarks, 500
   *                                              operations, 10 threads per
   *                                              Scalaris node)
   *  -m,--monitor <node>                         print monitoring information
   *  -r,--read <key>                             read an item
   *  -w,--write <key> <value>                    write an item
   *     --test-and-set <key> <old> <new>         atomic test and set, i.e.
   *                                              write <key> to <new> if the
   *                                              current value is <old>
   *  -d,--delete <key> <[timeout]>               delete an item (default
   *                                              timeout: 2000ms)
   *                                              WARNING: This function can
   *                                              lead to inconsistent data
   *                                              (e.g. deleted items can
   *                                              re-appear). Also when
   *                                              re-creating an item the
   *                                              version before the delete can
   *                                              re-appear.
   *  -jmx,--jmxservice <node>                    starts a service exposing
   *                                              Scalaris monitoring values
   *                                              via JMX
   * </code>
   * </pre>
   *
   * In order to override node and cookie to use for a connection, specify the
   * <tt>scalaris.node</tt> or <tt>scalaris.cookie</tt> system properties. Their values will be used
   * instead of the values defined in the config file!
   *
   * @param args command line arguments
   */
  public static void main(final String[] args) {
    boolean verbose = false;
    final CommandLineParser parser = new GnuParser();
    CommandLine line = null;
    final Options options = getOptions();
    try {
      line = parser.parse(options, args);
    } catch (final ParseException e) {
      printException("Parsing failed", e, false);
      return; // will not be reached since printException exits
    }

    if (line.hasOption("verbose")) {
      verbose = true;
      ConnectionFactory.getInstance().printProperties();
    }

    if (line.hasOption("minibench")) {
      final String[] optionValues = line.getOptionValues("minibench");
      int nrOperations = 500;
      int threadsPerNode = 10;
      final HashSet<Integer> benchmarks = new HashSet<Integer>(10);
      boolean all = false;
      if (optionValues != null) {
        checkArguments(optionValues, 0, options, "b");
        if (optionValues.length >= 1) {
          nrOperations = Integer.parseInt(optionValues[0]);
        }
        if (optionValues.length >= 2) {
          threadsPerNode = Integer.parseInt(optionValues[1]);
        }
        if (optionValues.length >= 3) {
          for (int i = 2; i < Math.min(20, optionValues.length); ++i) {
            final String benchmarks_str = optionValues[i];
            if (benchmarks_str.equals("all")) {
              all = true;
            } else {
              benchmarks.add(Integer.parseInt(benchmarks_str));
            }
          }
        }
      } else {
        all = true;
      }
      if (all) {
        for (int i = 1; i <= 18; ++i) {
          benchmarks.add(i);
        }
      }
      Benchmark.minibench(nrOperations, threadsPerNode, benchmarks);
    } else if (line.hasOption("r")) { // read
      final String key = line.getOptionValue("read");
      checkArguments(key, options, "r");
      try {
        final TransactionSingleOp sc = new TransactionSingleOp();
        final String value = sc.read(key).value().toString();
        System.out.println("read(" + key + ") == " + value);
      } catch (final ConnectionException e) {
        printException("read failed with connection error", e, verbose);
      } catch (final NotFoundException e) {
        printException("read failed with not found", e, verbose);
      } catch (final UnknownException e) {
        printException("read failed with unknown", e, verbose);
      }
    } else if (line.hasOption("w")) { // write
      final String[] optionValues = line.getOptionValues("write");
      checkArguments(optionValues, 2, options, "w");
      final String key = optionValues[0];
      final String value = optionValues[1];
      try {
        final TransactionSingleOp sc = new TransactionSingleOp();
        sc.write(key, value);
        System.out.println("write(" + key + ", " + value + "): ok");
      } catch (final ConnectionException e) {
        printException("write failed with connection error", e, verbose);
      } catch (final AbortException e) {
        printException("write failed with abort", e, verbose);
      } catch (final UnknownException e) {
        printException("write failed with unknown", e, verbose);
      }
    } else if (line.hasOption("test-and-set")) { // test_and_set
      final String[] optionValues = line.getOptionValues("test-and-set");
      checkArguments(optionValues, 3, options, "test-and-set");
      final String key = optionValues[0];
      final String oldValue = optionValues[1];
      final String newValue = optionValues[2];
      try {
        final TransactionSingleOp sc = new TransactionSingleOp();
        sc.testAndSet(key, oldValue, newValue);
        System.out.println("testAndSet(" + key + ", " + oldValue + ", " + newValue + "): ok");
      } catch (final ConnectionException e) {
        printException("testAndSet failed with connection error", e, verbose);
      } catch (final AbortException e) {
        printException("testAndSet failed with abort", e, verbose);
      } catch (final UnknownException e) {
        printException("testAndSet failed with unknown", e, verbose);
      } catch (final NotFoundException e) {
        printException("testAndSet failed with not found", e, verbose);
      } catch (final KeyChangedException e) {
        printException(
            "testAndSet failed with key changed (current value: "
                + e.getOldValue().toString()
                + ")",
            e,
            verbose);
      }
    } else if (line.hasOption("d")) { // delete
      final String[] optionValues = line.getOptionValues("delete");
      checkArguments(optionValues, 1, options, "d");
      final String key = optionValues[0];
      int timeout = 2000;
      if (optionValues.length >= 2) {
        try {
          timeout = Integer.parseInt(optionValues[1]);
        } catch (final Exception e) {
          printException(
              "Parsing failed",
              new ParseException(
                  "wrong type for timeout parameter of option d"
                      + " (parameters: <"
                      + options.getOption("d").getArgName()
                      + ">)"),
              verbose);
        }
      }
      try {
        final ReplicatedDHT sc = new ReplicatedDHT();
        final DeleteResult deleteResult = sc.delete(key, timeout);
        System.out.println(
            "delete("
                + key
                + ", "
                + timeout
                + "): "
                + deleteResult.ok
                + " ok, "
                + deleteResult.locks_set
                + " locks_set, "
                + deleteResult.undef
                + " undef");
      } catch (final ConnectionException e) {
        printException("delete failed with connection error", e, verbose);
      } catch (final TimeoutException e) {
        printException("delete failed with timeout", e, verbose);
      } catch (final UnknownException e) {
        printException("delete failed with unknown error", e, verbose);
      }
    } else if (line.hasOption("lh")) { // get local host name
      System.out.println(ConnectionFactory.getLocalhostName());
    } else if (line.hasOption("monitor")) { // print monitoring data
      final String node = line.getOptionValue("monitor");
      checkArguments(node, options, "monitor");
      try {
        final Monitor monitor = new Monitor(node);
        final GetNodeInfoResult nodeInfo = monitor.getNodeInfo();
        final GetNodePerformanceResult nodePerf = monitor.getNodePerformance();
        final GetServiceInfoResult srvInfo = monitor.getServiceInfo();
        final GetServicePerformanceResult srvPerf = monitor.getServicePerformance();

        final Double nodePerfCurLatAvg = Monitor.getCurrentPerfValue(nodePerf.latencyAvg);
        final Double nodePerfCurLatStddev = Monitor.getCurrentPerfValue(nodePerf.latencyStddev);
        final Double srvPerfCurLatAvg = Monitor.getCurrentPerfValue(srvPerf.latencyAvg);
        final Double srcPerfCurLatStddev = Monitor.getCurrentPerfValue(srvPerf.latencyStddev);

        final DecimalFormat df = new DecimalFormat("0.##");
        System.out.println("== Node Info ==");
        System.out.println("Scalaris version: " + nodeInfo.scalarisVersion);
        System.out.println("Erlang   version: " + nodeInfo.erlangVersion);
        System.out.println("# of DHT nodes  : " + nodeInfo.dhtNodes);
        System.out.println("== Service Info (from mgmt_server) ==");
        System.out.println("Total # of nodes: " + srvInfo.nodes);
        System.out.println("Total load      : " + srvInfo.totalLoad);
        System.out.println("== Node Performance ==");
        System.out.println(
            "Current latency : "
                + (nodePerfCurLatAvg == null ? "n/a" : df.format(nodePerfCurLatAvg)));
        System.out.println(
            "Current stddev  : "
                + (nodePerfCurLatStddev == null ? "n/a" : df.format(nodePerfCurLatStddev)));
        System.out.println("== Service Performance ==");
        System.out.println(
            "Current latency : "
                + (srvPerfCurLatAvg == null ? "n/a" : df.format(srvPerfCurLatAvg)));
        System.out.println(
            "Current stddev  : "
                + (srcPerfCurLatStddev == null ? "n/a" : df.format(srcPerfCurLatStddev)));
      } catch (final ConnectionException e) {
        printException("monitor failed with connection error", e, verbose);
      } catch (final UnknownException e) {
        printException("monitor failed with unknown error", e, verbose);
      }
    } else if (line.hasOption("jmx")) { // start JMX monitoring service
      final String node = line.getOptionValue("jmx");
      checkArguments(node, options, "jmx");
      startJmxService(node, verbose);
    } else {
      // print help if no other option was given
      //        if (line.hasOption("help")) {
      final HelpFormatter formatter = new HelpFormatter();
      formatter.setOptionComparator(
          new Comparator<Option>() {
            private int optionToInt(final Option option) {
              if (option.getLongOpt().equals("help")) {
                return 1;
              } else if (option.getLongOpt().equals("verbose")) {
                return 2;
              } else if (option.getLongOpt().equals("localhost")) {
                return 3;
              } else if (option.getLongOpt().equals("minibench")) {
                return 4;
              } else if (option.getLongOpt().equals("monitor")) {
                return 5;
              } else if (option.getLongOpt().equals("read")) {
                return 6;
              } else if (option.getLongOpt().equals("write")) {
                return 7;
              } else if (option.getLongOpt().equals("test-and-set")) {
                return 8;
              } else if (option.getLongOpt().equals("add-del-on-list")) {
                return 9;
              } else if (option.getLongOpt().equals("add-on-nr")) {
                return 10;
              } else if (option.getLongOpt().equals("delete")) {
                return 11;
              } else if (option.getLongOpt().equals("jmxservice")) {
                return 12;
              } else {
                return 13;
              }
            }

            public int compare(final Option arg0, final Option arg1) {
              final int arg0_i = optionToInt(arg0);
              final int arg1_i = optionToInt(arg1);
              if (arg0_i < arg1_i) {
                return -1;
              } else if (arg0_i == arg1_i) {
                return 0;
              } else {
                return 1;
              }
            }
          });
      formatter.printHelp("scalaris [Options]", getOptions());
      if (!line.hasOption("help")) {
        System.exit(1);
      }
    }
  }
Beispiel #11
0
  public List<Table> queryFields(DBConfig config) {
    List<Table> tableInfoList = new ArrayList<Table>();
    Connection conn = null;
    try {
      List<TableConfiguration> tableList = (List<TableConfiguration>) config.getTableList();
      if (tableList == null || tableList.size() <= 0) return tableInfoList;

      conn = ConnectionFactory.getInstance().getConnection(config);
      DatabaseMetaData databaseMetaData = conn.getMetaData();
      for (TableConfiguration table : tableList) {
        Table tableInfo = new Table();

        String localCatalog = table.getCatalog();
        String localSchema = table.getSchema();
        String localTableName = table.getTableName();
        if (databaseMetaData.storesLowerCaseIdentifiers()) {
          localCatalog = localCatalog == null ? null : localCatalog.toLowerCase();
          localSchema = localSchema == null ? null : localSchema.toLowerCase();
          localTableName = localTableName == null ? null : localTableName.toLowerCase();
        } else if (databaseMetaData.storesUpperCaseIdentifiers()) {
          localCatalog = localCatalog == null ? null : localCatalog.toUpperCase();
          localSchema = localSchema == null ? null : localSchema.toUpperCase();
          localTableName = localTableName == null ? null : localTableName.toUpperCase();
        }

        Statement stmt = conn.createStatement();
        ResultSet tableRs = stmt.executeQuery("SHOW CREATE TABLE " + localTableName);
        if (tableRs != null && tableRs.next()) {
          String create = tableRs.getString(2);
          String comment = parse(create);
          tableInfo.setComment(comment);
        }

        ResultSet rs = databaseMetaData.getColumns(localCatalog, localSchema, localTableName, null);
        tableInfo.setSerialVersionUID(System.nanoTime() + "L");
        while (rs.next()) {
          tableInfo.setCatalog(rs.getString("TABLE_CAT"));
          tableInfo.setSchema(rs.getString("TABLE_SCHEM"));
          tableInfo.setName(rs.getString("TABLE_NAME"));
          tableInfo.setCode(rs.getString("TABLE_NAME"));

          Column introspectedColumn = new Column();
          introspectedColumn.setTableAlias(table.getTableName());
          introspectedColumn.setName(rs.getString("COLUMN_NAME"));
          introspectedColumn.setJdbcType(rs.getInt("DATA_TYPE"));
          introspectedColumn.setDataType(
              JdbcTypeNameTranslator.getJdbcTypeName(rs.getInt("DATA_TYPE"))); // $NON-NLS-1$
          introspectedColumn.setLength(rs.getInt("COLUMN_SIZE")); // $NON-NLS-1$
          introspectedColumn.setCode(rs.getString("COLUMN_NAME"));
          /*introspectedColumn.setActualColumnName(rs
          .getString("COLUMN_NAME"));*/
          //$NON-NLS-1$
          introspectedColumn.setNullable(
              rs.getInt("NULLABLE") == DatabaseMetaData.columnNullable); // $NON-NLS-1$
          introspectedColumn.setScale(rs.getInt("DECIMAL_DIGITS")); // $NON-NLS-1$
          introspectedColumn.setComment(rs.getString("REMARKS"));

          tableInfo.addColumn(introspectedColumn);

          PropertyBean pb = new PropertyBean();

          pb.setName(convertFirstUpper(getFieldName(rs.getString("COLUMN_NAME"))));
          pb.setType(JdbcType2Java.calculateJavaType(introspectedColumn));
          String importType = JdbcType2Java.importJavaType(introspectedColumn);
          if (importType != null && !importType.equals("")) {
            if (importType.indexOf("java.lang") < 0
                && !tableInfo.getImportList().contains(importType))
              tableInfo.getImportList().add(importType);
          }
          tableInfo.getPropertyBeanList().add(pb);
        }
        closeResultSet(rs);

        rs = databaseMetaData.getPrimaryKeys(localCatalog, localSchema, localTableName);
        while (rs.next()) {
          tableInfo.addPrimaryKeyColumn(rs.getString("COLUMN_NAME"));
        }
        closeResultSet(rs);
        tableInfoList.add(tableInfo);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return tableInfoList;
  }
Beispiel #12
0
 /**
  * Constructor, uses the default connection returned by {@link
  * ConnectionFactory#createConnection()}.
  *
  * @throws ConnectionException if the connection fails
  */
 public Transaction() throws ConnectionException {
   connection = ConnectionFactory.getInstance().createConnection();
 }