Java Code Examples for com.mysql.jdbc.StringUtils#split()
The following examples show how to use
com.mysql.jdbc.StringUtils#split() .
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 File: BaseTestCase.java From r-course with MIT License | 6 votes |
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 2
Source File: BaseTestCase.java From Komondor with GNU General Public License v3.0 | 6 votes |
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 3
Source File: MetadataTest.java From r-course with MIT License | 4 votes |
/** * Tests the implementation of Information Schema for column privileges. */ public void testGetColumnPrivilegesUsingInfoSchema() throws Exception { String dontRunPropertyName = "com.mysql.jdbc.testsuite.cantGrant"; if (!runTestIfSysPropDefined(dontRunPropertyName)) { if (versionMeetsMinimum(5, 0, 7)) { Properties props = new Properties(); props.put("useInformationSchema", "true"); Connection conn1 = null; Statement stmt1 = null; String userHostQuoted = null; boolean grantFailed = true; try { conn1 = getConnectionWithProps(props); stmt1 = conn1.createStatement(); createTable("t1", "(c1 int)"); this.rs = stmt1.executeQuery("SELECT USER()"); this.rs.next(); String user = this.rs.getString(1); List<String> userHost = StringUtils.split(user, "@", false); if (userHost.size() < 2) { fail("This test requires a JDBC URL with a user, and won't work with the anonymous user. " + "You can skip this test by setting the system property " + dontRunPropertyName); } userHostQuoted = "'" + userHost.get(0) + "'@'" + userHost.get(1) + "'"; try { stmt1.executeUpdate("GRANT update (c1) on t1 to " + userHostQuoted); grantFailed = false; } catch (SQLException sqlEx) { fail("This testcase needs to be run with a URL that allows the user to issue GRANTs " + " in the current database. You can skip this test by setting the system property \"" + dontRunPropertyName + "\"."); } if (!grantFailed) { DatabaseMetaData metaData = conn1.getMetaData(); this.rs = metaData.getColumnPrivileges(null, null, "t1", null); this.rs.next(); assertEquals("t1", this.rs.getString("TABLE_NAME")); assertEquals("c1", this.rs.getString("COLUMN_NAME")); assertEquals(userHostQuoted, this.rs.getString("GRANTEE")); assertEquals("UPDATE", this.rs.getString("PRIVILEGE")); } } finally { if (stmt1 != null) { if (!grantFailed) { stmt1.executeUpdate("REVOKE UPDATE (c1) ON t1 FROM " + userHostQuoted); } stmt1.close(); } if (conn1 != null) { conn1.close(); } } } } }
Example 4
Source File: StringUtilsTest.java From r-course with MIT License | 4 votes |
/** * Tests StringUtils.split() methods. */ public void testSplit() throws Exception { String testString = " abstract, (contents, table of \"['figure''s'],(tables\"), introduction , \"methods(), ()results\", ['discussion'']', conclusion] "; List<String> stringParts; // non existing split char, trim stringParts = StringUtils.split(testString, ";", true); assertEquals(1, stringParts.size()); assertEquals(testString.trim(), stringParts.get(0)); // non existing split char, don't trim stringParts = StringUtils.split(testString, ";", false); assertEquals(1, stringParts.size()); assertEquals(testString, stringParts.get(0)); // full split, trim stringParts = StringUtils.split(testString, ",", true); assertEquals(9, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents", stringParts.get(1)); assertEquals("table of \"['figure''s']", stringParts.get(2)); assertEquals("(tables\")", stringParts.get(3)); assertEquals("introduction", stringParts.get(4)); assertEquals("\"methods()", stringParts.get(5)); assertEquals("()results\"", stringParts.get(6)); assertEquals("['discussion'']'", stringParts.get(7)); assertEquals("conclusion]", stringParts.get(8)); // full split, don't trim stringParts = StringUtils.split(testString, ",", false); assertEquals(9, stringParts.size()); assertEquals(" abstract", stringParts.get(0)); assertEquals(" (contents", stringParts.get(1)); assertEquals(" table of \"['figure''s']", stringParts.get(2)); assertEquals("(tables\")", stringParts.get(3)); assertEquals(" introduction ", stringParts.get(4)); assertEquals(" \"methods()", stringParts.get(5)); assertEquals(" ()results\"", stringParts.get(6)); assertEquals(" ['discussion'']'", stringParts.get(7)); assertEquals(" conclusion] ", stringParts.get(8)); // most common markers, trim stringParts = StringUtils.split(testString, ",", "'\"", "'\"", true); assertEquals(7, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents", stringParts.get(1)); assertEquals("table of \"['figure''s'],(tables\")", stringParts.get(2)); assertEquals("introduction", stringParts.get(3)); assertEquals("\"methods(), ()results\"", stringParts.get(4)); assertEquals("['discussion'']'", stringParts.get(5)); assertEquals("conclusion]", stringParts.get(6)); // extended markers, trim stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", true); assertEquals(2, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents, table of \"['figure''s'],(tables\"), introduction , \"methods(), ()results\", ['discussion'']', conclusion]", stringParts.get(1)); // extended markers with overridable markers, trim stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", "'\"", true); assertEquals(5, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents, table of \"['figure''s'],(tables\")", stringParts.get(1)); assertEquals("introduction", stringParts.get(2)); assertEquals("\"methods(), ()results\"", stringParts.get(3)); assertEquals("['discussion'']', conclusion]", stringParts.get(4)); }
Example 5
Source File: MetadataTest.java From Komondor with GNU General Public License v3.0 | 4 votes |
/** * Tests the implementation of Information Schema for column privileges. */ public void testGetColumnPrivilegesUsingInfoSchema() throws Exception { String dontRunPropertyName = "com.mysql.jdbc.testsuite.cantGrant"; if (!runTestIfSysPropDefined(dontRunPropertyName)) { if (versionMeetsMinimum(5, 0, 7)) { Properties props = new Properties(); props.put("useInformationSchema", "true"); Connection conn1 = null; Statement stmt1 = null; String userHostQuoted = null; boolean grantFailed = true; try { conn1 = getConnectionWithProps(props); stmt1 = conn1.createStatement(); createTable("t1", "(c1 int)"); this.rs = stmt1.executeQuery("SELECT USER()"); this.rs.next(); String user = this.rs.getString(1); List<String> userHost = StringUtils.split(user, "@", false); if (userHost.size() < 2) { fail("This test requires a JDBC URL with a user, and won't work with the anonymous user. " + "You can skip this test by setting the system property " + dontRunPropertyName); } userHostQuoted = "'" + userHost.get(0) + "'@'" + userHost.get(1) + "'"; try { stmt1.executeUpdate("GRANT update (c1) on t1 to " + userHostQuoted); grantFailed = false; } catch (SQLException sqlEx) { fail("This testcase needs to be run with a URL that allows the user to issue GRANTs " + " in the current database. You can skip this test by setting the system property \"" + dontRunPropertyName + "\"."); } if (!grantFailed) { DatabaseMetaData metaData = conn1.getMetaData(); this.rs = metaData.getColumnPrivileges(null, null, "t1", null); this.rs.next(); assertEquals("t1", this.rs.getString("TABLE_NAME")); assertEquals("c1", this.rs.getString("COLUMN_NAME")); assertEquals(userHostQuoted, this.rs.getString("GRANTEE")); assertEquals("UPDATE", this.rs.getString("PRIVILEGE")); } } finally { if (stmt1 != null) { if (!grantFailed) { stmt1.executeUpdate("REVOKE UPDATE (c1) ON t1 FROM " + userHostQuoted); } stmt1.close(); } if (conn1 != null) { conn1.close(); } } } } }
Example 6
Source File: StringUtilsTest.java From Komondor with GNU General Public License v3.0 | 4 votes |
/** * Tests StringUtils.split() methods. */ public void testSplit() throws Exception { String testString = " abstract, (contents, table of \"['figure''s'],(tables\"), introduction , \"methods(), ()results\", ['discussion'']', conclusion] "; List<String> stringParts; // non existing split char, trim stringParts = StringUtils.split(testString, ";", true); assertEquals(1, stringParts.size()); assertEquals(testString.trim(), stringParts.get(0)); // non existing split char, don't trim stringParts = StringUtils.split(testString, ";", false); assertEquals(1, stringParts.size()); assertEquals(testString, stringParts.get(0)); // full split, trim stringParts = StringUtils.split(testString, ",", true); assertEquals(9, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents", stringParts.get(1)); assertEquals("table of \"['figure''s']", stringParts.get(2)); assertEquals("(tables\")", stringParts.get(3)); assertEquals("introduction", stringParts.get(4)); assertEquals("\"methods()", stringParts.get(5)); assertEquals("()results\"", stringParts.get(6)); assertEquals("['discussion'']'", stringParts.get(7)); assertEquals("conclusion]", stringParts.get(8)); // full split, don't trim stringParts = StringUtils.split(testString, ",", false); assertEquals(9, stringParts.size()); assertEquals(" abstract", stringParts.get(0)); assertEquals(" (contents", stringParts.get(1)); assertEquals(" table of \"['figure''s']", stringParts.get(2)); assertEquals("(tables\")", stringParts.get(3)); assertEquals(" introduction ", stringParts.get(4)); assertEquals(" \"methods()", stringParts.get(5)); assertEquals(" ()results\"", stringParts.get(6)); assertEquals(" ['discussion'']'", stringParts.get(7)); assertEquals(" conclusion] ", stringParts.get(8)); // most common markers, trim stringParts = StringUtils.split(testString, ",", "'\"", "'\"", true); assertEquals(7, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents", stringParts.get(1)); assertEquals("table of \"['figure''s'],(tables\")", stringParts.get(2)); assertEquals("introduction", stringParts.get(3)); assertEquals("\"methods(), ()results\"", stringParts.get(4)); assertEquals("['discussion'']'", stringParts.get(5)); assertEquals("conclusion]", stringParts.get(6)); // extended markers, trim stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", true); assertEquals(2, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents, table of \"['figure''s'],(tables\"), introduction , \"methods(), ()results\", ['discussion'']', conclusion]", stringParts.get(1)); // extended markers with overridable markers, trim stringParts = StringUtils.split(testString, ",", "'\"([{", "'\")]}", "'\"", true); assertEquals(5, stringParts.size()); assertEquals("abstract", stringParts.get(0)); assertEquals("(contents, table of \"['figure''s'],(tables\")", stringParts.get(1)); assertEquals("introduction", stringParts.get(2)); assertEquals("\"methods(), ()results\"", stringParts.get(3)); assertEquals("['discussion'']', conclusion]", stringParts.get(4)); }