示例#1
0
  /**
   * Test case for ALTER [IGNORE] TABLE t1 EXCHANGE PARTITION p1 WITH TABLE t2 syntax
   *
   * @throws SQLException
   */
  public void testExchangePartition() throws Exception {
    if (versionMeetsMinimum(5, 6, 6)) {
      createTable(
          "testExchangePartition1",
          "(id int(11) NOT NULL AUTO_INCREMENT, year year(2) DEFAULT NULL,"
              + " modified timestamp NOT NULL, PRIMARY KEY (id)) ENGINE=InnoDB ROW_FORMAT=COMPACT PARTITION BY HASH (id) PARTITIONS 2");
      createTable("testExchangePartition2", "LIKE testExchangePartition1");

      this.stmt.executeUpdate("ALTER TABLE testExchangePartition2 REMOVE PARTITIONING");
      if (versionMeetsMinimum(5, 7, 4)) {
        this.stmt.executeUpdate(
            "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      } else {
        this.stmt.executeUpdate(
            "ALTER IGNORE TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      }

      if (versionMeetsMinimum(5, 7, 4)) {
        this.pstmt =
            this.conn.prepareStatement(
                "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      } else {
        this.pstmt =
            this.conn.prepareStatement(
                "ALTER IGNORE TABLE testExchangePartition1 "
                    + "EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
      }
      assertEquals(
          Util.isJdbc4()
              ? Class.forName("com.mysql.jdbc.JDBC4PreparedStatement")
              : com.mysql.jdbc.PreparedStatement.class,
          this.pstmt.getClass());
      this.pstmt.executeUpdate();

      Connection testConn = null;
      try {
        testConn = getConnectionWithProps("useServerPrepStmts=true,emulateUnsupportedPstmts=false");
        if (versionMeetsMinimum(5, 7, 4)) {
          this.pstmt =
              testConn.prepareStatement(
                  "ALTER TABLE testExchangePartition1 EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
        } else {
          this.pstmt =
              testConn.prepareStatement(
                  "ALTER IGNORE TABLE testExchangePartition1 "
                      + "EXCHANGE PARTITION p1 WITH TABLE testExchangePartition2");
        }
        assertEquals(
            Util.isJdbc4()
                ? Class.forName("com.mysql.jdbc.JDBC4ServerPreparedStatement")
                : com.mysql.jdbc.ServerPreparedStatement.class,
            this.pstmt.getClass());
        this.pstmt.executeUpdate();
      } finally {
        if (testConn != null) {
          testConn.close();
        }
      }
    }
  }
 static {
   BASELINE_TIMES.put("ResultSet.getInt()", new Double(0.00661));
   BASELINE_TIMES.put("ResultSet.getDouble()", new Double(0.00671));
   BASELINE_TIMES.put("ResultSet.getTime()", new Double(0.02033));
   BASELINE_TIMES.put("ResultSet.getTimestamp()", new Double(0.02363));
   BASELINE_TIMES.put("ResultSet.getDate()", new Double(0.02223));
   BASELINE_TIMES.put("ResultSet.getString()", new Double(0.00982));
   BASELINE_TIMES.put("ResultSet.getObject() on a string", new Double(0.00861));
   BASELINE_TIMES.put("Connection.prepareStatement()", new Double(0.18547));
   BASELINE_TIMES.put("single selects", new Double(46));
   BASELINE_TIMES.put("5 standalone queries", new Double(146));
   BASELINE_TIMES.put("total time all queries", new Double(190));
   if (com.mysql.jdbc.Util.isJdbc4()) {
     BASELINE_TIMES.put("PreparedStatement.setInt()", new Double(0.0014));
     BASELINE_TIMES.put("PreparedStatement.setTime()", new Double(0.0107));
     BASELINE_TIMES.put("PreparedStatement.setTimestamp()", new Double(0.0182));
     BASELINE_TIMES.put("PreparedStatement.setDate()", new Double(0.0819));
     BASELINE_TIMES.put("PreparedStatement.setString()", new Double(0.0081));
     BASELINE_TIMES.put("PreparedStatement.setObject() on a string", new Double(0.00793));
     BASELINE_TIMES.put("PreparedStatement.setDouble()", new Double(0.0246));
   } else {
     BASELINE_TIMES.put("PreparedStatement.setInt()", new Double(0.0011));
     BASELINE_TIMES.put("PreparedStatement.setTime()", new Double(0.0642));
     BASELINE_TIMES.put("PreparedStatement.setTimestamp()", new Double(0.03184));
     BASELINE_TIMES.put("PreparedStatement.setDate()", new Double(0.12248));
     BASELINE_TIMES.put("PreparedStatement.setString()", new Double(0.01512));
     BASELINE_TIMES.put("PreparedStatement.setObject() on a string", new Double(0.01923));
     BASELINE_TIMES.put("PreparedStatement.setDouble()", new Double(0.00671));
   }
 }
  public ResultSetInternalMethods postProcess(
      String sql,
      Statement interceptedStatement,
      ResultSetInternalMethods originalResultSet,
      Connection connection)
      throws SQLException {

    if (connection.versionMeetsMinimum(5, 0, 2)) {
      populateMapWithSessionStatusValues(connection, this.postExecuteValues);

      connection
          .getLog()
          .logInfo(
              "Server status change for statement:\n"
                  + Util.calculateDifferences(this.preExecuteValues, this.postExecuteValues));
    }

    return null; // we don't actually modify a result set
  }
  private void populateMapWithSessionStatusValues(Connection connection, Map toPopulate)
      throws SQLException {
    java.sql.Statement stmt = null;
    java.sql.ResultSet rs = null;

    try {
      toPopulate.clear();

      stmt = connection.createStatement();
      rs = stmt.executeQuery("SHOW SESSION STATUS");
      Util.resultSetToMap(toPopulate, rs);
    } finally {
      if (rs != null) {
        rs.close();
      }

      if (stmt != null) {
        stmt.close();
      }
    }
  }
  /**
   * Returns the ProfilerEventHandlerFactory that handles profiler events for the given connection.
   *
   * @param conn the connection to handle events for
   * @return the ProfilerEventHandlerFactory that handles profiler events
   */
  public static synchronized ProfilerEventHandler getInstance(ConnectionImpl conn)
      throws SQLException {
    ProfilerEventHandler handler = (ProfilerEventHandler) CONNECTIONS_TO_SINKS.get(conn);

    if (handler == null) {
      handler =
          (ProfilerEventHandler)
              Util.getInstance(
                  conn.getProfilerEventHandler(),
                  new Class[0],
                  new Object[0],
                  conn.getExceptionInterceptor());

      // we do it this way to not require
      // exposing the connection properties
      // for all who utilize it
      conn.initializeExtension(handler);

      CONNECTIONS_TO_SINKS.put(conn, handler);
    }

    return handler;
  }
示例#6
0
  public void testInsertCharStatement() throws Exception {
    try {
      "".getBytes("SJIS");
    } catch (UnsupportedEncodingException uee) {
      return;
    }

    // SJIS is fully supported only in Java 1.5.0_38 and above.
    if (versionMeetsMinimum(4, 1, 12) && Util.jvmMeetsMinimum(5, 38)) {
      Map<String, char[]> testDataMap = new HashMap<String, char[]>();

      List<String> charsetList = new ArrayList<String>();

      Map<String, Connection> connectionMap = new HashMap<String, Connection>();

      Map<String, Connection> connectionWithResultMap = new HashMap<String, Connection>();

      Map<String, Statement> statementMap = new HashMap<String, Statement>();

      Map<String, Statement> statementWithResultMap = new HashMap<String, Statement>();

      Map<String, String> javaToMysqlCharsetMap = new HashMap<String, String>();

      charsetList.add("SJIS");
      testDataMap.put("SJIS", SJIS_CHARS);
      javaToMysqlCharsetMap.put("SJIS", "sjis");

      charsetList.add("Shift_JIS");
      testDataMap.put("Shift_JIS", SJIS_CHARS);
      javaToMysqlCharsetMap.put("Shift_JIS", "sjis");

      charsetList.add("CP943");
      testDataMap.put("CP943", SJIS_CHARS);
      javaToMysqlCharsetMap.put("CP943", "sjis");

      if (versionMeetsMinimum(5, 0, 3)) {
        charsetList.add("WINDOWS-31J");
        testDataMap.put("WINDOWS-31J", CP932_CHARS);
        javaToMysqlCharsetMap.put("WINDOWS-31J", "cp932");

        charsetList.add("MS932");
        testDataMap.put("MS932", CP932_CHARS);
        javaToMysqlCharsetMap.put("MS932", "cp932");

        charsetList.add("EUC_JP");
        testDataMap.put("EUC_JP", UJIS_CHARS);
        // testDataHexMap.put("EUC_JP", UJIS_CHARS_HEX);
        javaToMysqlCharsetMap.put("EUC_JP", "ujis");

        charsetList.add("EUC_JP_Solaris");
        testDataMap.put("EUC_JP_Solaris", EUCJPMS_CHARS);
        // testDataHexMap.put("EUC_JP_Solaris", EUCJPMS_CHARS_HEX);
        javaToMysqlCharsetMap.put("EUC_JP_Solaris", "eucjpms");

      } else {
        charsetList.add("EUC_JP");
        testDataMap.put("EUC_JP", UJIS_CHARS);
        javaToMysqlCharsetMap.put("EUC_JP", "ujis");
      }

      for (String charset : charsetList) {
        Properties props = new Properties();

        props.put("useUnicode", "true");
        props.put("characterEncoding", charset);
        Connection conn2 = getConnectionWithProps(props);
        connectionMap.put(charset.toLowerCase(Locale.ENGLISH), conn2);
        statementMap.put(charset.toLowerCase(Locale.ENGLISH), conn2.createStatement());

        props.put("characterSetResult", charset);
        Connection connWithResult = getConnectionWithProps(props);
        connectionWithResultMap.put(charset, connWithResult);
        statementWithResultMap.put(charset, connWithResult.createStatement());
      }

      for (String charset : charsetList) {
        String mysqlCharset = javaToMysqlCharsetMap.get(charset);
        Statement stmt2 = statementMap.get(charset.toLowerCase(Locale.ENGLISH));
        String query1 = "DROP TABLE IF EXISTS t1";
        String query2 =
            "CREATE TABLE t1 (c1 int, c2 char(1)) DEFAULT CHARACTER SET = " + mysqlCharset;
        stmt2.executeUpdate(query1);
        stmt2.executeUpdate(query2);
        char[] testData = testDataMap.get(charset);
        for (int i = 0; i < testData.length; i++) {
          String query3 = "INSERT INTO t1 values(" + i + ", '" + testData[i] + "')";
          stmt2.executeUpdate(query3);
          String query4 = "SELECT c2 FROM t1 WHERE c1 = " + i;
          this.rs = stmt2.executeQuery(query4);
          this.rs.next();
          String value = this.rs.getString(1);

          assertEquals(
              "For character set " + charset + "/ " + mysqlCharset,
              String.valueOf(testData[i]),
              value);
        }
        String query5 = "DROP TABLE t1";
        stmt2.executeUpdate(query5);
      }
    }
  }