Java Code Examples for com.mysql.jdbc.StringUtils

The following examples show how to use com.mysql.jdbc.StringUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: crud-intellij-plugin   Source File: DbHelper.java    License: Apache License 2.0 6 votes vote down vote up
public List<String> getDatabases() {
    Connection conn = getConnection();
    try {
        DatabaseMetaData metaData = conn.getMetaData();
        ResultSet catalogs = metaData.getCatalogs();
        List<String> rs = new ArrayList<>();
        while (catalogs.next()) {
            String db = catalogs.getString("TABLE_CAT");
            if (org.apache.commons.lang3.StringUtils.equalsIgnoreCase(db, "information_schema")) {
                continue;
            }
            rs.add(db);
        }
        return rs;
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        closeConnection(conn);
    }
}
 
Example 2
Source Project: crud-intellij-plugin   Source File: DbHelper.java    License: Apache License 2.0 6 votes vote down vote up
private List<Column> getAllColumn(String tableName) {
    Connection conn = getConnection(db);
    try {
        DatabaseMetaData metaData = conn.getMetaData();
        ResultSet primaryKeys = metaData.getPrimaryKeys(null, null, tableName);
        String primaryKey = null;
        while (primaryKeys.next()) {
            primaryKey = primaryKeys.getString("COLUMN_NAME");
        }
        ResultSet rs = metaData.getColumns(null, null, tableName, null);
        List<Column> ls = new ArrayList<>();
        while (rs.next()) {
            String columnName = rs.getString("COLUMN_NAME");
            Column column = new Column(rs.getString("REMARKS"), columnName, rs.getInt("DATA_TYPE"));
            if (!StringUtils.isNullOrEmpty(primaryKey) && columnName.equals(primaryKey)) {
                column.setId(true);
            }
            ls.add(column);
        }
        return ls;
    } catch (SQLException e) {
        throw new RuntimeException(e.getMessage(), e);
    } finally {
        closeConnection(conn);
    }
}
 
Example 3
Source Project: SugarOnRest   Source File: Utils.java    License: MIT License 6 votes vote down vote up
/**
 * Gets integer value from string data.
 *
 * @param value The value to convert.
 * @return The converted string value.
 */
private static int getInteger(String value) {

    if (StringUtils.isNullOrEmpty(value)) {
        return 0;
    }

    if (value.equalsIgnoreCase("null")) {
        return 0;
    }

    try {
        return Integer.parseInt(value);
    }
    catch (Exception exception) {

    }

    return Integer.MAX_VALUE;
}
 
Example 4
Source Project: r-course   Source File: ConnectionTest.java    License: MIT License 6 votes vote down vote up
public void testUseOldUTF8Behavior() throws Exception {

        Properties props = new Properties();
        props.setProperty("useOldUTF8Behavior", "true");
        props.setProperty("useUnicode", "true");
        props.setProperty("characterEncoding", "UTF-8");
        props.setProperty("logFactory", "com.mysql.jdbc.log.StandardLogger");
        props.setProperty("profileSQL", "true");
        StandardLogger.startLoggingToBuffer();

        try {
            getConnectionWithProps(props);

            assertTrue(StringUtils.indexOfIgnoreCase(StandardLogger.getBuffer().toString(), "SET NAMES utf8") == -1);
        } finally {
            StandardLogger.dropBuffer();
        }
    }
 
Example 5
Source Project: fastdfs-zyc   Source File: TestModuleAction.java    License: GNU General Public License v2.0 6 votes vote down vote up
@RequestMapping("/testDownLoad")
public ModelAndView testDownLoad(String pageNum, String pageSize,String keyForSearch) {
    ModelAndView mv = new ModelAndView("testModule/downLoadTest.jsp");
    List<Fdfs_file> list = testModuleService.getAllFileListByPage(pageNum, pageSize,keyForSearch);
    int countDownLoadFile = testModuleService.getCountDownLoadFile(keyForSearch);
    mv.addObject("testFileCount", countDownLoadFile);
    if(!StringUtils.isNullOrEmpty(keyForSearch)){
        mv.addObject("pageNum", "1");
    }else{
        mv.addObject("pageNum", pageNum);
    }
    mv.addObject("pageSize", pageSize);
    mv.addObject("testFileList", list);
    mv.addObject("keySearch",keyForSearch);
    return mv;
}
 
Example 6
Source Project: r-course   Source File: StringRegressionTest.java    License: MIT License 6 votes vote down vote up
/**
 * Tests character conversion bug.
 * 
 * @throws Exception
 *             if there is an internal error (which is a bug).
 */
public void testAsciiCharConversion() throws Exception {
    byte[] buf = new byte[10];
    buf[0] = (byte) '?';
    buf[1] = (byte) 'S';
    buf[2] = (byte) 't';
    buf[3] = (byte) 'a';
    buf[4] = (byte) 't';
    buf[5] = (byte) 'e';
    buf[6] = (byte) '-';
    buf[7] = (byte) 'b';
    buf[8] = (byte) 'o';
    buf[9] = (byte) 't';

    String testString = "?State-bot";
    String convertedString = StringUtils.toAsciiString(buf);

    for (int i = 0; i < convertedString.length(); i++) {
        System.out.println((byte) convertedString.charAt(i));
    }

    assertTrue("Converted string != test string", testString.equals(convertedString));
}
 
Example 7
private static String getTarget(String hugoSymbol, EvidenceType evidenceType, String alteration, String tumorType, String treatment) {
    List<String> items = new ArrayList<>();
    if (!StringUtils.isNullOrEmpty(hugoSymbol)) {
        items.add(hugoSymbol);
    }
    if (evidenceType != null) {
        items.add(evidenceType.name());
    }
    if (!StringUtils.isNullOrEmpty(alteration)) {
        items.add(alteration);
    }
    if (!StringUtils.isNullOrEmpty(tumorType)) {
        items.add(tumorType);
    }
    if (!StringUtils.isNullOrEmpty(treatment)) {
        items.add(treatment);
    }
    return String.join(" / ", items);
}
 
Example 8
Source Project: r-course   Source File: MysqlClearPasswordPlugin.java    License: MIT License 6 votes vote down vote up
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {
    toServer.clear();

    Buffer bresp;
    try {
        String encoding = this.connection.versionMeetsMinimum(5, 7, 6) ? this.connection.getPasswordCharacterEncoding() : "UTF-8";
        bresp = new Buffer(StringUtils.getBytes(this.password != null ? this.password : "", encoding));
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("MysqlClearPasswordPlugin.1", new Object[] { this.connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }

    bresp.setPosition(bresp.getBufLength());
    int oldBufLength = bresp.getBufLength();

    bresp.writeByte((byte) 0);

    bresp.setBufLength(oldBufLength + 1);
    bresp.setPosition(0);

    toServer.add(bresp);
    return true;
}
 
Example 9
Source Project: r-course   Source File: MysqlXAConnection.java    License: MIT License 6 votes vote down vote up
private static void appendXid(StringBuilder builder, Xid xid) {
    byte[] gtrid = xid.getGlobalTransactionId();
    byte[] btrid = xid.getBranchQualifier();

    if (gtrid != null) {
        StringUtils.appendAsHex(builder, gtrid);
    }

    builder.append(',');
    if (btrid != null) {
        StringUtils.appendAsHex(builder, btrid);
    }

    builder.append(',');
    StringUtils.appendAsHex(builder, xid.getFormatId());
}
 
Example 10
Source Project: Komondor   Source File: ConnectionTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void testUseOldUTF8Behavior() throws Exception {

        Properties props = new Properties();
        props.setProperty("useOldUTF8Behavior", "true");
        props.setProperty("useUnicode", "true");
        props.setProperty("characterEncoding", "UTF-8");
        props.setProperty("logFactory", "com.mysql.jdbc.log.StandardLogger");
        props.setProperty("profileSQL", "true");
        StandardLogger.startLoggingToBuffer();

        try {
            getConnectionWithProps(props);

            assertTrue(StringUtils.indexOfIgnoreCase(StandardLogger.getBuffer().toString(), "SET NAMES utf8") == -1);
        } finally {
            StandardLogger.dropBuffer();
        }
    }
 
Example 11
@Override
@Transactional(propagation = Propagation.REQUIRED)
public List<WarningData> findWarning(WarningData wd,PageInfo pageInfo) throws IOException, MyException {
    //To change body of implemented methods use File | Settings | File Templates.
    List<WarningData> warningDatas = new ArrayList<WarningData>();
    Session session = getSession();
    StringBuilder queryString = new StringBuilder("from WarningData as wd ");
    if(!StringUtils.isNullOrEmpty(wd.getWdIpAddr())){
        queryString.append("where wd.wdIpAddr like '%"+wd.getWdIpAddr()+"%'");
    }
    Query query = session.createQuery(queryString.toString());
    pageInfo.setTotalCount(query.list().size());
    query.setMaxResults(pageInfo.getNumPerPage());
    query.setFirstResult((pageInfo.getPageNum()-1)*pageInfo.getNumPerPage());
    warningDatas = query.list();
    return warningDatas;
}
 
Example 12
/**
 * Tests character conversion bug.
 * 
 * @throws Exception
 *             if there is an internal error (which is a bug).
 */
public void testAsciiCharConversion() throws Exception {
    byte[] buf = new byte[10];
    buf[0] = (byte) '?';
    buf[1] = (byte) 'S';
    buf[2] = (byte) 't';
    buf[3] = (byte) 'a';
    buf[4] = (byte) 't';
    buf[5] = (byte) 'e';
    buf[6] = (byte) '-';
    buf[7] = (byte) 'b';
    buf[8] = (byte) 'o';
    buf[9] = (byte) 't';

    String testString = "?State-bot";
    String convertedString = StringUtils.toAsciiString(buf);

    for (int i = 0; i < convertedString.length(); i++) {
        System.out.println((byte) convertedString.charAt(i));
    }

    assertTrue("Converted string != test string", testString.equals(convertedString));
}
 
Example 13
Source Project: Komondor   Source File: BaseTestCase.java    License: GNU General Public License v3.0 6 votes vote down vote up
protected Connection getConnectionWithProps(String url, String propsList) throws SQLException {
    Properties props = new Properties();

    if (propsList != null) {
        List<String> keyValuePairs = StringUtils.split(propsList, ",", false);

        for (String kvp : keyValuePairs) {
            List<String> splitUp = StringUtils.split(kvp, "=", false);
            StringBuilder value = new StringBuilder();

            for (int i = 1; i < splitUp.size(); i++) {
                if (i != 1) {
                    value.append("=");
                }

                value.append(splitUp.get(i));

            }

            props.setProperty(splitUp.get(0).toString().trim(), value.toString());
        }
    }

    return getConnectionWithProps(url, props);
}
 
Example 14
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {
    toServer.clear();

    Buffer bresp = null;

    String pwd = this.password;

    if (fromServer == null || pwd == null || pwd.length() == 0) {
        bresp = new Buffer(new byte[0]);
    } else {
        bresp = new Buffer(
                StringUtils.getBytes(Util.newCrypt(pwd, fromServer.readString().substring(0, 8), this.connection.getPasswordCharacterEncoding())));

        bresp.setPosition(bresp.getBufLength());
        int oldBufLength = bresp.getBufLength();

        bresp.writeByte((byte) 0);

        bresp.setBufLength(oldBufLength + 1);
        bresp.setPosition(0);
    }
    toServer.add(bresp);

    return true;
}
 
Example 15
public boolean nextAuthenticationStep(Buffer fromServer, List<Buffer> toServer) throws SQLException {
    toServer.clear();

    Buffer bresp;
    try {
        String encoding = this.connection.versionMeetsMinimum(5, 7, 6) ? this.connection.getPasswordCharacterEncoding() : "UTF-8";
        bresp = new Buffer(StringUtils.getBytes(this.password != null ? this.password : "", encoding));
    } catch (UnsupportedEncodingException e) {
        throw SQLError.createSQLException(Messages.getString("MysqlClearPasswordPlugin.1", new Object[] { this.connection.getPasswordCharacterEncoding() }),
                SQLError.SQL_STATE_GENERAL_ERROR, null);
    }

    bresp.setPosition(bresp.getBufLength());
    int oldBufLength = bresp.getBufLength();

    bresp.writeByte((byte) 0);

    bresp.setBufLength(oldBufLength + 1);
    bresp.setPosition(0);

    toServer.add(bresp);
    return true;
}
 
Example 16
private Boolean isEmptyEvidence(Evidence queryEvidence) {
    EvidenceType evidenceType = queryEvidence.getEvidenceType();
    String knownEffect = queryEvidence.getKnownEffect();
    String description = queryEvidence.getDescription();
    LevelOfEvidence level = queryEvidence.getLevelOfEvidence();
    Set<Treatment> treatments = queryEvidence.getTreatments();
    if (description != null) {
        description = description.trim();
    }
    Boolean isEmpty = false;
    if (evidenceType.equals(EvidenceType.ONCOGENIC) || evidenceType.equals(EvidenceType.MUTATION_EFFECT)) {
        if (StringUtils.isNullOrEmpty(knownEffect) && StringUtils.isNullOrEmpty(description)) isEmpty = true;
    } else if (EvidenceTypeUtils.getTreatmentEvidenceTypes().contains(evidenceType)) {
        if (treatments == null && StringUtils.isNullOrEmpty(description)) isEmpty = true;
    } else if (evidenceType.equals(EvidenceType.DIAGNOSTIC_IMPLICATION) || evidenceType.equals(EvidenceType.PROGNOSTIC_IMPLICATION)) {
        if (level == null && StringUtils.isNullOrEmpty(description)) isEmpty = true;
    } else if (StringUtils.isNullOrEmpty(description)) {
        isEmpty = true;
    }
    return isEmpty;
}
 
Example 17
@Bean
public Docket publicApi() {
    String swaggerDescription = PropertiesUtils.getProperties(SWAGGER_DESCRIPTION);
    String finalDescription = StringUtils.isNullOrEmpty(swaggerDescription) ? SWAGGER_DEFAULT_DESCRIPTION : swaggerDescription;
    return new Docket(DocumentationType.SWAGGER_2)
        .groupName("Public APIs")
        .select()
        .apis(RequestHandlerSelectors.withMethodAnnotation(PublicApi.class))
        .build()
        .apiInfo(new ApiInfo(
            "OncoKB APIs",
            finalDescription,
            PUBLIC_API_VERSION,
            "https://www.oncokb.org/terms",
            new Contact("OncoKB", "https://www.oncokb.org", "[email protected]"),
            "Terms of Use",
            "https://www.oncokb.org/terms"
        ))
        .useDefaultResponseMessages(false);
}
 
Example 18
@Override
@Transactional(propagation = Propagation.REQUIRED)
public List<WarningUser> findWarUser(WarningUser wu,PageInfo pageInfo) throws IOException, MyException {
    //To change body of implemented methods use File | Settings | File Templates.
    List<WarningUser> warningUsers = new ArrayList<WarningUser>();
    Session session = getSession();
    StringBuilder queryString = new StringBuilder("from WarningUser as w ");
    if(!StringUtils.isNullOrEmpty(wu.getName())){
        queryString.append("where w.name like '%"+wu.getName()+"%'");
    }
    Query query = session.createQuery(queryString.toString());
    pageInfo.setTotalCount(query.list().size());
    query.setMaxResults(pageInfo.getNumPerPage());
    query.setFirstResult((pageInfo.getPageNum()-1)*pageInfo.getNumPerPage());
    warningUsers = query.list();
    return warningUsers;
}
 
Example 19
Source Project: das   Source File: DbUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static List<AbstractParameterHost> getSelectFieldHosts(Long db_id, String sql,
                                                              DalResultSetExtractor<List<AbstractParameterHost>> extractor) throws Exception {
    List<AbstractParameterHost> list = null;
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    List<Parameter> parameters = new ArrayList<>();
    String testSql = sql;
    int whereIndex = StringUtils.indexOfIgnoreCase(testSql, "where");
    if (whereIndex > 0) {
        testSql = sql.substring(0, whereIndex);
    }
    if (isMySqlServer(db_id)) {
        testSql = testSql + " limit 1";
    } else {
        testSql = testSql.replace("select", "select top(1)");
    }
    try {
        connection = DataSourceUtil.getConnection(db_id);
        preparedStatement = statementCreator.createPreparedStatement(connection, testSql, parameters, Hints.hints());
        resultSet = preparedStatement.executeQuery();
        list = extractor.extract(resultSet);
    } catch (Throwable e) {
        throw e;
    } finally {
        DbUtil.close(resultSet);
        DbUtil.close(preparedStatement);
        DbUtil.close(connection);
    }
    return list;
}
 
Example 20
Source Project: fastdfs-zyc   Source File: WarningAction.java    License: GNU General Public License v2.0 5 votes vote down vote up
@RequestMapping("/warningEdit")
public ModelAndView warningEdit(String id) throws IOException, MyException {
    ModelAndView mv = new ModelAndView("warning/warningEdit.jsp");
    if (!StringUtils.isNullOrEmpty(id)) {
        WarningData wd = warningService.findById(id);
        mv.addObject("id", wd.getId());
        mv.addObject("wdIpAddr", wd.getWdIpAddr());
        mv.addObject("wdFreeMB", wd.getWdFreeMB());
        mv.addObject("wdCpu", wd.getWdCpu());
        mv.addObject("wdMem", wd.getWdMem());
    }

    return mv;
}
 
Example 21
Source Project: civcraft   Source File: RandomEvent.java    License: GNU General Public License v2.0 5 votes vote down vote up
private void loadSavedMessages(String input) {
	String[] messages = input.split(",");
	
	for (String encodedMessage : messages) {
		String message = StringUtils.toAsciiString(Base64Coder.decode(encodedMessage));
		this.savedMessages.add(message);
	}
}
 
Example 22
Source Project: SugarOnRest   Source File: Main.java    License: MIT License 5 votes vote down vote up
private static String ensureBaseFolderExist(String[] args) throws Exception {
    String baseFolder = "";

    if (args.length > 0 ){
        baseFolder = args[0];
    }

    if (StringUtils.isNullOrEmpty(baseFolder)) {
        baseFolder =  System.getProperty("user.dir");
    }

    return ensureFolderExist(baseFolder, "");
}
 
Example 23
Source Project: SugarOnRest   Source File: Utils.java    License: MIT License 5 votes vote down vote up
/**
 * Make get property name prettier.
 *
 * @param name Value to convert.
 * @return Name in Pascal case
 * @throws Exception
 */
public static String toPascalCase(String name) throws Exception {
    if (StringUtils.isNullOrEmpty(name)) {
        return name;
    }

    String pascalCase = "";
    char newChar;
    boolean toUpper = false;
    char[] charArray = name.toCharArray();
    for (int ctr = 0; ctr <= charArray.length - 1; ctr++)
    {
        if (ctr == 0)
        {
            newChar = Character.toUpperCase(charArray[ctr]);
            pascalCase = Character.toString(newChar);
            continue;
        }

        if (charArray[ctr] == '_')
        {
            toUpper = true;
            continue;
        }

        if (toUpper)
        {
            newChar = Character.toUpperCase(charArray[ctr]);
            pascalCase += Character.toString(newChar);
            toUpper = false;
            continue;
        }

        pascalCase += Character.toString(charArray[ctr]);
    }

    return pascalCase;
}
 
Example 24
Source Project: SPADE   Source File: ScaffoldProfiler.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static void populateScaffold()
{
    String query = "SELECT hash, childVertexHash, parentVertexHash FROM edge;";
    try
    {
        ResultSet result = sqlStorage.executeQuery(query);
        AbstractEdge incomingEdge;

        while (result.next())
        {
            String edgeHash = result.getString(1);
            String childVertexHash = result.getString(2);
            String parentVertexHash = result.getString(3);
            AbstractVertex childVertex = new Vertex();
            childVertex.addAnnotation("hash", childVertexHash);
            AbstractVertex parentVertex = new Vertex();
            parentVertex.addAnnotation("hash", parentVertexHash);
            incomingEdge = new Edge(childVertex, parentVertex);
            incomingEdge.addAnnotation("hash", edgeHash);
            System.out.println(incomingEdge);
            System.exit(0);
            if(!(StringUtils.isNullOrEmpty(childVertexHash) || StringUtils.isNullOrEmpty(parentVertexHash)))
            {
                scaffold.insertEntry(incomingEdge);
            }
        }
    }
    catch (SQLException ex)
    {
        System.out.println("Edge set querying unsuccessful!");
    }

}
 
Example 25
Source Project: SugarOnRest   Source File: Utils.java    License: MIT License 5 votes vote down vote up
/**
 * Is column a primary key?
 *
 * @param value The value from sql query.
 * @return True or false.
 */
public static boolean getIsVPrimaryKey(String value) {

    if (StringUtils.isNullOrEmpty(value)) {
        return false;
    }

    if (value.equalsIgnoreCase("PRI")) {
        return true;
    }

    return false;
}
 
Example 26
Source Project: SugarOnRest   Source File: Utils.java    License: MIT License 5 votes vote down vote up
/**
 * Returns empty string if string value is null.
 *
 * @param value The value to convert.
 * @return The converted string value.
 */
private static String getEmptyIfNull(String value) {

    if (StringUtils.isNullOrEmpty(value)) {
        return "";
    }

    return value;
}
 
Example 27
Source Project: r-course   Source File: StringUtilsTest.java    License: MIT License 5 votes vote down vote up
/**
 * Tests StringUtil.indexOfQuoteDoubleAware() method
 * 
 * @throws Exception
 */
public void testIndexOfQuoteDoubleAware() throws Exception {
    final String[] searchInDoubledQt = new String[] { "A 'strange' \"STRONG\" `SsStRiNg` to be searched in",
            "A ''strange'' \"\"STRONG\"\" ``SsStRiNg`` to be searched in" };

    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(null, null, 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(null, "'", 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", null, 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", "", 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware("abc", "bcd", 0));
    assertEquals(0, StringUtils.indexOfQuoteDoubleAware("abc", "abc", 0));

    int qtPos = 0;
    assertEquals(2, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", 0));
    assertEquals(10, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", qtPos + 1));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "'", qtPos + 1));
    assertEquals(12, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", 0));
    assertEquals(19, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", qtPos + 1));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "\"", qtPos + 1));
    assertEquals(21, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", 0));
    assertEquals(30, qtPos = StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", qtPos + 1));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[0], "`", qtPos + 1));

    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "'", 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "\"", 0));
    assertEquals(-1, StringUtils.indexOfQuoteDoubleAware(searchInDoubledQt[1], "`", 0));
}
 
Example 28
Source Project: r-course   Source File: SyntaxRegressionTest.java    License: MIT License 5 votes vote down vote up
/**
 * WL#7696 - InnoDB: Transparent page compression.
 * 
 * Tests COMPRESSION clause in CREATE|ALTER TABLE syntax.
 * 
 * table_option: (...) | COMPRESSION [=] {'ZLIB'|'LZ4'|'NONE'}
 */
public void testTableCompression() throws Exception {
    if (!versionMeetsMinimum(5, 7, 8)) {
        return;
    }

    // Create table with 'zlib' compression.
    createTable("testTableCompression", "(c VARCHAR(15000)) COMPRESSION='ZLIB'");

    this.rs = this.stmt.executeQuery("show create table testTableCompression");
    assertTrue(this.rs.next());
    assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='ZLIB'") >= 0);

    // Alter table compression to 'lz4'.
    this.stmt.execute("ALTER TABLE testTableCompression COMPRESSION='LZ4'");

    this.rs = this.stmt.executeQuery("show create table testTableCompression");
    assertTrue(this.rs.next());
    assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='LZ4'") >= 0);

    // Alter table compression to 'none'.
    this.stmt.execute("ALTER TABLE testTableCompression COMPRESSION='NONE'");

    this.rs = this.stmt.executeQuery("show create table testTableCompression");
    assertTrue(this.rs.next());
    assertTrue(StringUtils.indexOfIgnoreCase(this.rs.getString(2), "COMPRESSION='NONE'") >= 0);
}
 
Example 29
Source Project: r-course   Source File: MetaDataRegressionTest.java    License: MIT License 5 votes vote down vote up
private void testBug65871_testCatalogs(Connection conn1) throws Exception {
    testBug65871_testCatalog("db1`testbug65871", StringUtils.quoteIdentifier("db1`testbug65871", ((ConnectionProperties) conn1).getPedantic()), conn1);

    testBug65871_testCatalog("db2`testbug65871", StringUtils.quoteIdentifier("db2`testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()),
            conn1);

    testBug65871_testCatalog("`db3`testbug65871`", StringUtils.quoteIdentifier("`db3`testbug65871`", "\"", ((ConnectionProperties) conn1).getPedantic()),
            conn1);
}
 
Example 30
Source Project: r-course   Source File: MetaDataRegressionTest.java    License: MIT License 5 votes vote down vote up
private void testBug65871_testCatalog(String unquotedDbName, String quotedDbName, Connection conn1) throws Exception {

        Statement st1 = null;

        try {
            st1 = conn1.createStatement();

            // 1. catalog
            st1.executeUpdate("DROP DATABASE IF EXISTS " + quotedDbName);
            st1.executeUpdate("CREATE DATABASE " + quotedDbName);
            this.rs = st1.executeQuery("show databases like '" + unquotedDbName + "'");
            if (this.rs.next()) {
                assertEquals(unquotedDbName, this.rs.getString(1));
            } else {
                fail("Database " + unquotedDbName + " (quoted " + quotedDbName + ") not found.");
            }

            testBug65871_testTable(unquotedDbName, quotedDbName, "table1`testbug65871",
                    StringUtils.quoteIdentifier("table1`testbug65871", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);

            testBug65871_testTable(unquotedDbName, quotedDbName, "table2`testbug65871",
                    StringUtils.quoteIdentifier("table2`testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);

            testBug65871_testTable(unquotedDbName, quotedDbName, "table3\"testbug65871",
                    StringUtils.quoteIdentifier("table3\"testbug65871", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);

            testBug65871_testTable(unquotedDbName, quotedDbName, "`table4`testbug65871`",
                    StringUtils.quoteIdentifier("`table4`testbug65871`", "\"", ((ConnectionProperties) conn1).getPedantic()), conn1, st1);

        } finally {
            if (st1 != null) {
                st1.executeUpdate("DROP DATABASE IF EXISTS " + quotedDbName);
                st1.close();
            }
        }

    }