[Isql-devevelopment] SF.net SVN: isql: [48] isql-core/trunk/src/org/isqlviewer/util
Brought to you by:
mkobold
From: <mk...@us...> - 2007-04-30 22:22:01
|
Revision: 48 http://svn.sourceforge.net/isql/?rev=48&view=rev Author: mkobold Date: 2007-04-30 15:22:00 -0700 (Mon, 30 Apr 2007) Log Message: ----------- * BasicUtilities.java ** Corrected the use of modifying the input parameter for creating a safe filename. * IsqlToolkit.java ** Updated system properties and updated system/toolkit initialization. * LocalMessages.java ** Corrected usage of not modifying input parameter references * NullResultSetViewer.java ** Refactored this class from an internal class file. * QueryExecutor.java ** Added support for variable substitution in a unified form. * StringTokenizer.java ** Removed quote support. ** Added method toArray() for all tokens in string as an array. Modified Paths: -------------- isql-core/trunk/src/org/isqlviewer/util/BasicUtilities.java isql-core/trunk/src/org/isqlviewer/util/IsqlToolkit.java isql-core/trunk/src/org/isqlviewer/util/LocalMessages.java isql-core/trunk/src/org/isqlviewer/util/QueryExecutor.java isql-core/trunk/src/org/isqlviewer/util/StringTokenizer.java Added Paths: ----------- isql-core/trunk/src/org/isqlviewer/util/NullResultSetViewer.java Modified: isql-core/trunk/src/org/isqlviewer/util/BasicUtilities.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/BasicUtilities.java 2007-04-30 22:15:13 UTC (rev 47) +++ isql-core/trunk/src/org/isqlviewer/util/BasicUtilities.java 2007-04-30 22:22:00 UTC (rev 48) @@ -153,8 +153,9 @@ * @param fqFilename original filename. * @return String an updated version that should be safe for most systems. */ - public static String createSafeFilename(String fqFilename) { + public static String createSafeFilename(final String fileName) { + String fqFilename = fileName; fqFilename = fqFilename.replace(File.pathSeparatorChar, '_'); fqFilename = fqFilename.replace(File.separatorChar, '_'); fqFilename = fqFilename.replace('*', '_'); @@ -238,7 +239,8 @@ * @see SAXParserFactory#setNamespaceAware(boolean) * @see SAXParserFactory#setValidating(boolean) */ - public static XMLReader createXMLReader(boolean namespaceAware, boolean validating) throws ParserConfigurationException { + public static XMLReader createXMLReader(boolean namespaceAware, boolean validating) + throws ParserConfigurationException { SAXParserFactory spf = SAXParserFactory.newInstance(); spf.setNamespaceAware(namespaceAware); Modified: isql-core/trunk/src/org/isqlviewer/util/IsqlToolkit.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/IsqlToolkit.java 2007-04-30 22:15:13 UTC (rev 47) +++ isql-core/trunk/src/org/isqlviewer/util/IsqlToolkit.java 2007-04-30 22:22:00 UTC (rev 48) @@ -79,38 +79,18 @@ */ public static final String PROPERTY_HOME = "isql.home"; /** - * System property for the fully qualified path for the looking for plugins. + * System property for defining the default location for log files. */ - public static final String PROPERTY_PLUGIN_HOME = "isql.home.plugins"; + public static final String PROPERTY_LOGGING_HOME = "isql.logging.home"; /** - * System property for the fully qualified path for the default script location. + * System property for the fully qualified path for the looking for plugins. */ - public static final String PROPERTY_SCRIPT_HOME = "isql.home.scripts"; + public static final String PROPERTY_PLUGIN_HOME = "isql.plugin.home"; /** - * System property for the path for to automatically load jar/zip/directories to classpath. - */ - public static final String PROPERTY_LIBRARY_HOME = "isql.home.library"; - /** * System property for the current version of iSQL-Viewer currently running. */ public static final String PROPERTY_VERSION = "isql.version"; /** - * System property for enabling debugging information throughout the iSQL-Viewer system. - */ - public static final String PROPERTY_DEBUG = "isql.debug"; - /** - * System property for enabling thread information to be displayed for messages. - */ - public static final String PROPERTY_DEBUG_THREADS = "isql.debug.threads"; - /** - * System property for determining if iSQL-Viewer is running within the Java Web Start environment. - */ - public static final String PROPERTY_JAVA_WEBSTART = "isql.jnlp"; - /** - * System property for determining if iSQL-Viewer is providing proxy authentication services. - */ - public static final String PROPERTY_PROXY_ENABLED = "isql.proxy.enabled"; - /** * System property flag to indicate that iSQL-Viewer is running embedded or is controlled by another application. */ public static final String PROPERTY_STANDALONE = "isql.stand-alone"; @@ -129,10 +109,9 @@ private static final String ServiceDtdResourcePath_3 = "/org/isqlviewer/resource/xml/service_3_x.dtd"; private static final String ENCRYPTION_ALGORITHIM = "DESede"; - private static File baseDirectory = null; - private static File scriptDirectory = null; - private static File pluginDirectory = null; - private static File libraryDirectory = null; + private static final File baseDirectory; + private static final File loggingDirectory; + private static final File pluginDirectory; private static final String DRIVER_DEFINITIONS_FILE = "driver.properties"; private static final String BOOKMARKS_FILE_NAME = "bookmarks.xml"; @@ -141,10 +120,51 @@ private static final Key localEncryptionKey; static { - entityResolver = new SaxResolver(); - entityResolver.register(BookmarkDtdPublicId, BookmarkDtdResourcePath, IsqlToolkit.class); - entityResolver.register(ServiceDtdPublicId_2, ServiceDtdResourcePath_2, IsqlToolkit.class); - entityResolver.register(ServiceDtdPublicId_3, ServiceDtdResourcePath_3, IsqlToolkit.class); + + Properties systemProperties = System.getProperties(); + boolean exists = false; + File location = null; + + systemProperties.put(PROPERTY_VERSION, getVersionInfo()); + exists = systemProperties.containsKey(PROPERTY_HOME); + if (!exists) { + String defaultValue = new File(System.getProperty("user.home"), ".iSQL-Viewer").getAbsolutePath(); + systemProperties.setProperty(PROPERTY_HOME, defaultValue); + } + location = new File(systemProperties.getProperty(PROPERTY_HOME)); + location.mkdirs(); + baseDirectory = location; + + exists = systemProperties.containsKey(PROPERTY_LOGGING_HOME); + if (!exists) { + String defaultValue = new File(System.getProperty(PROPERTY_HOME), "logs").getAbsolutePath(); + systemProperties.setProperty(PROPERTY_LOGGING_HOME, defaultValue); + } + location = new File(systemProperties.getProperty(PROPERTY_LOGGING_HOME)); + location.mkdirs(); + loggingDirectory = location; + + exists = systemProperties.containsKey(PROPERTY_PLUGIN_HOME); + if (!exists) { + String defaultValue = new File(System.getProperty(PROPERTY_HOME), "plugins").getAbsolutePath(); + systemProperties.setProperty(PROPERTY_PLUGIN_HOME, defaultValue); + } + location = new File(systemProperties.getProperty(PROPERTY_PLUGIN_HOME)); + location.mkdirs(); + pluginDirectory = location; + + exists = systemProperties.containsKey(PROPERTY_DEFAULTS_ROOT); + if (!exists) { + String defaultValue = "/org/isqlviewer/core/Preferences"; + systemProperties.setProperty(PROPERTY_DEFAULTS_ROOT, defaultValue); + } + + exists = systemProperties.containsKey(PROPERTY_STANDALONE); + if (!exists) { + String defaultValue = Boolean.FALSE.toString(); + systemProperties.setProperty(PROPERTY_STANDALONE, defaultValue); + } + Key existingKey = loadExistingPrivateKey(); if (existingKey == null) { try { @@ -157,14 +177,11 @@ } else { localEncryptionKey = existingKey; } - Properties systemProperties = System.getProperties(); - boolean exists = false; - exists = systemProperties.containsKey(PROPERTY_HOME); - if (!exists) { - String defaultValue = new File(System.getProperty("user.home"), ".iSQL-Viewer").getAbsolutePath(); - systemProperties.setProperty(PROPERTY_HOME, defaultValue); - } + entityResolver = new SaxResolver(); + entityResolver.register(BookmarkDtdPublicId, BookmarkDtdResourcePath, IsqlToolkit.class); + entityResolver.register(ServiceDtdPublicId_2, ServiceDtdResourcePath_2, IsqlToolkit.class); + entityResolver.register(ServiceDtdPublicId_3, ServiceDtdResourcePath_3, IsqlToolkit.class); } private IsqlToolkit() { @@ -193,62 +210,32 @@ */ public static synchronized File getBaseDirectory() { - if (baseDirectory == null) { - File defaultBase = new File(System.getProperty("user.home"), ".iSQL-Viewer"); - baseDirectory = new File(System.getProperty(PROPERTY_HOME, defaultBase.getAbsolutePath())); - if (!baseDirectory.exists()) { - baseDirectory.mkdirs(); - } - } return baseDirectory; } /** - * Gets the default location to look for scripts for the iSQL-Viewer program. + * Gets the default location to look for application plug-ins from. * <p> * - * @return file location to look for scripts. + * @return file location where plug-in components are loaded from. */ - public static synchronized File getScriptsDirectory() { + public static synchronized File getPluginDirectory() { - if (scriptDirectory == null) { - File defaultBase = new File(getBaseDirectory(), "scripts"); - scriptDirectory = new File(System.getProperty(PROPERTY_SCRIPT_HOME, defaultBase.getAbsolutePath())); - } - return scriptDirectory; + return pluginDirectory; } /** - * Gets the default runtime class-path for loading dynamic classes and resources from. + * Gets the default location to write log files to. * <p> * - * @return file location to scan for support classes and libraries. + * @return file location where log files are written to. */ - public static synchronized File getLibraryDirectory() { + public static synchronized File getLoggingDirectory() { - if (libraryDirectory == null) { - File defaultBase = new File(getBaseDirectory(), "lib"); - libraryDirectory = new File(System.getProperty(PROPERTY_LIBRARY_HOME, defaultBase.getAbsolutePath())); - } - return libraryDirectory; + return loggingDirectory; } /** - * Gets the default location to look for application plug-ins from. - * <p> - * - * @return file location where plug-in components are loaded from. - */ - public static synchronized File getPluginDirectory() { - - if (pluginDirectory == null) { - File defaultBase = new File(getBaseDirectory(), "plugins"); - pluginDirectory = new File(System.getProperty(PROPERTY_PLUGIN_HOME, defaultBase.getAbsolutePath())); - } - return pluginDirectory; - } - - /** * Gets the root node for all application preferences to reside from. * <p> * @@ -257,7 +244,7 @@ */ public static String getRootPreferencesNode() { - return System.getProperty(PROPERTY_DEFAULTS_ROOT, "/org/isqlviewer/core/Preferences"); + return System.getProperty(PROPERTY_DEFAULTS_ROOT); } /** Modified: isql-core/trunk/src/org/isqlviewer/util/LocalMessages.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/LocalMessages.java 2007-04-30 22:15:13 UTC (rev 47) +++ isql-core/trunk/src/org/isqlviewer/util/LocalMessages.java 2007-04-30 22:22:00 UTC (rev 48) @@ -226,14 +226,15 @@ } // this is a copy from the java.util.ResourceBundle. // - private String getFullBundleIdentifier(String baseName) { + private String getFullBundleIdentifier(final String baseName) { String localeSuffix = preferredLocale.toString(); + String bundleId = baseName; if (localeSuffix.length() > 0) { - baseName += "_" + localeSuffix; + bundleId += "_" + localeSuffix; } else if (preferredLocale.getVariant().length() > 0) { - baseName += "___" + preferredLocale.getVariant(); + bundleId += "___" + preferredLocale.getVariant(); } - return baseName; + return bundleId; } } Added: isql-core/trunk/src/org/isqlviewer/util/NullResultSetViewer.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/NullResultSetViewer.java (rev 0) +++ isql-core/trunk/src/org/isqlviewer/util/NullResultSetViewer.java 2007-04-30 22:22:00 UTC (rev 48) @@ -0,0 +1,91 @@ +/* + * Copyright 2000-2005 by Mark A. Kobold + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for + * the specific language governing rights and limitations under the License. + * + * The Original Code is iSQL-Viewer, A Mutli-Platform Database Tool. + * + * The Initial Developer of the Original Code is Markus A. Kobold. + * + * Portions created by Mark A. Kobold are Copyright (C) + * 2000-2005 Mark A. Kobold. All Rights Reserved. + * + * Contributor(s): + * Mark A. Kobold <mk...@is...>. + * + * Contributor(s): all the names of the contributors are added in the source + * code where applicable. + * + * If you didn't download this code from the following link, you should check + * if you aren't using an obsolete version: http://isql.sourceforge.net/ + */ +package org.isqlviewer.util; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; + +import org.isqlviewer.sql.ResultSetRenderer; + +class NullResultSetViewer implements ResultSetRenderer { + + public void handleSQLException(ResultSet set, SQLException e) { + + } + + public void handleStatementInterrupted(String stmtID) { + + } + + public void processGeneratedKeys(String stmtID, ResultSet keys, String nativeSQL) { + + } + + public long processResultSet(String stmtID, ResultSet set, String nativeSQL, int count) { + + return 0; + } + + public void processRowUpdates(String stmtID, int updateCount, String nativeSQL) { + + } + + public void recieveResultsetWarnings(ResultSet set, SQLWarning warnings) { + + } + + public void recieveStatementWarnings(Statement stmt, SQLWarning warnings) { + + } + + public void statementInitialized(String stmtID) { + + } + + public boolean supportsGeneratedKeys() { + + return false; + } + + public boolean supportsUpdateableResultSets() { + + return false; + } + + public boolean isCancelled() { + + return false; + } + + public String substituteVariable(String variableName) { + + return variableName; + } +} \ No newline at end of file Modified: isql-core/trunk/src/org/isqlviewer/util/QueryExecutor.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/QueryExecutor.java 2007-04-30 22:15:13 UTC (rev 47) +++ isql-core/trunk/src/org/isqlviewer/util/QueryExecutor.java 2007-04-30 22:22:00 UTC (rev 48) @@ -37,8 +37,14 @@ import java.sql.SQLWarning; import java.sql.Statement; import java.text.NumberFormat; +import java.text.ParseException; +import java.util.Date; import java.util.concurrent.TimeUnit; +import org.isqlviewer.JdbcCommandLogger; +import org.isqlviewer.history.CommandType; +import org.isqlviewer.history.HistoricalCommand; +import org.isqlviewer.sql.ConnectionProfile; import org.isqlviewer.sql.JdbcService; import org.isqlviewer.sql.JdbcUtilities; import org.isqlviewer.sql.ResultSetRenderer; @@ -53,6 +59,10 @@ */ public class QueryExecutor extends LoggableObject implements Runnable { + private static final String DELIM_START = "${"; + private static final char DELIM_STOP = '}'; + private static final int DELIM_START_LEN = 2; + private static final int DELIM_STOP_LEN = 1; private static final String RESOURCE_BUNDLE = "org.isqlviewer.util.ResourceBundle"; private static final LocalMessages messages = new LocalMessages(RESOURCE_BUNDLE); @@ -89,25 +99,53 @@ String localID = Long.toHexString(System.currentTimeMillis()); renderer.statementInitialized(localID); - StringTokenizer st = new StringTokenizer(statement.concat(";"), ";", false); + StringTokenizer st = new StringTokenizer(statement, ";", false); st.setQuotesEnabled(true); - try { - while (st.hasMoreTokens()) { - String query = st.nextToken().trim(); - if (query.length() == 0) { - continue; + + String[] statements = st.toArray(); + JdbcCommandLogger commandLogger = service.getCommandLogger(); + + HistoricalCommand executionHistory = new HistoricalCommand(); + executionHistory.setCommandText(""); + executionHistory.setQueryTime(new Date()); + executionHistory.setTransactionId(System.currentTimeMillis()); + executionHistory.setService(service.getName()); + executionHistory.setType(CommandType.BATCH_QUERY); + boolean logBatch = statements.length > 1; + for (int i = 0; i < statements.length; i++) { + String userQuery = statements[i].trim(); + if (userQuery.length() > 0) { + try { + String substitutedQuery = doVariableSubstitutions(userQuery); + String nativeSQL = getNativeSql(connection, substitutedQuery); + Date queryTime = new Date(); + doQuery(connection, localID, nativeSQL); + if (logBatch && commandLogger != null) { + HistoricalCommand subCommand = new HistoricalCommand(); + subCommand.setCommandText(userQuery); + subCommand.setQueryTime(queryTime); + subCommand.setService(service.getName()); + subCommand.setTransactionId(executionHistory.getTransactionId()); + getTypeForQuery(subCommand, userQuery); + executionHistory.addSubcommand(subCommand); + } else { + logCommandHistory(commandLogger, userQuery, queryTime); + } + } catch (ParseException e) { + error("ERR:", e); + } catch (SQLException sqle) { + Object[] parameters = { + sqle.getMessage(), Integer.toString(sqle.getErrorCode()), sqle.getSQLState()}; + error(messages.format("queryexecutor.sql_execption", parameters)); + renderer.handleSQLException(null, sqle); + } catch (Exception e) { + error("ERR:", e); } - String nativeSQL = echoStatementInfo(connection, query); - doQuery(connection, localID, nativeSQL); } - } catch (SQLException sqle) { - Object[] parameters = {sqle.getMessage(), Integer.toString(sqle.getErrorCode()), sqle.getSQLState()}; - error(messages.format("queryexecutor.sql_execption", parameters), sqle); - renderer.handleSQLException(null, sqle); - - } catch (Exception e) { - error("ERR:", e); } + if (commandLogger != null && logBatch) { + commandLogger.logCommand(executionHistory); + } } finally { info(messages.getMessage("queryexecutor.finished")); System.gc(); @@ -115,24 +153,69 @@ } + private void logCommandHistory(JdbcCommandLogger commandLogger, String userQuery, Date queryTime) { + + if (commandLogger != null) { + HistoricalCommand command = new HistoricalCommand(); + command.setCommandText(userQuery); + command.setQueryTime(queryTime); + command.setService(service.getName()); + getTypeForQuery(command, userQuery); + commandLogger.logCommand(command); + } + } + + private void getTypeForQuery(HistoricalCommand command, String userQuery) { + + StringBuilder builder = new StringBuilder(""); + for (int i = 0; i < userQuery.length(); i++) { + char c = userQuery.charAt(i); + if (Character.isWhitespace(c)) { + break; + } + builder.append(c); + } + + String firstWord = builder.toString().toUpperCase(); + if ("UPDATE".equals(firstWord)) { + command.setType(CommandType.UPDATE_QUERY); + } else if ("INSERT".equalsIgnoreCase(firstWord)) { + command.setType(CommandType.INSERT_QUERY); + } else if ("DELETE".equalsIgnoreCase(firstWord)) { + command.setType(CommandType.DELETE_QUERY); + } else if ("CREATE".equalsIgnoreCase(firstWord)) { + command.setType(CommandType.INSERT_QUERY); + } else if ("DROP".equalsIgnoreCase(firstWord)) { + command.setType(CommandType.DELETE_QUERY); + } else { + command.setType(CommandType.QUERY); + } + } + private void doQuery(Connection connection, String localID, String nativeSQL) throws SQLException { boolean results = false; + ConnectionProfile profile = service.getProfile(); DatabaseMetaData jdbcMetaData = connection.getMetaData(); Statement sqlStatement = connection.createStatement(); + MemoryMXBean memoryMBean = ManagementFactory.getMemoryMXBean(); ThreadMXBean threadMBean = ManagementFactory.getThreadMXBean(); long cpuTime = 0; long vmMemory = 0; boolean returnKeys = false; - boolean generateKeys = service.getProfile().isResultsetKeys(); + boolean generateKeys = profile.isResultsetKeys(); boolean supportsMultiResults = jdbcMetaData.supportsMultipleResultSets(); - String formattedSQL = StringUtilities.formatBreak(80, nativeSQL, "", false); + // if escape processing is enable it now otherwise leave with driver default // + if (!profile.isEscapeProcessing()) { + sqlStatement.setEscapeProcessing(profile.isEscapeProcessing()); + } + if (generateKeys) { if (jdbcMetaData.supportsGetGeneratedKeys()) { - info(messages.format("queryexecutor.generated_keys_query", formattedSQL)); + info(messages.format("queryexecutor.generated_keys_query", nativeSQL)); cpuTime = threadMBean.getCurrentThreadUserTime(); vmMemory = memoryMBean.getHeapMemoryUsage().getUsed(); results = sqlStatement.execute(nativeSQL, Statement.RETURN_GENERATED_KEYS); @@ -140,7 +223,7 @@ cpuTime = threadMBean.getCurrentThreadUserTime() - cpuTime; returnKeys = true; } else { - info(messages.format("queryexecutor.generated_keys_query_not_supported", formattedSQL)); + info(messages.format("queryexecutor.generated_keys_query_not_supported", nativeSQL)); cpuTime = threadMBean.getCurrentThreadUserTime(); vmMemory = memoryMBean.getHeapMemoryUsage().getUsed(); results = sqlStatement.execute(nativeSQL, Statement.NO_GENERATED_KEYS); @@ -148,7 +231,7 @@ cpuTime = threadMBean.getCurrentThreadUserTime() - cpuTime; } } else { - info(messages.format("queryexecutor.executing_query", formattedSQL)); + info(messages.format("queryexecutor.executing_query", nativeSQL)); cpuTime = threadMBean.getCurrentThreadUserTime(); vmMemory = memoryMBean.getHeapMemoryUsage().getUsed(); results = sqlStatement.execute(nativeSQL); @@ -156,8 +239,8 @@ cpuTime = threadMBean.getCurrentThreadUserTime() - cpuTime; } - info(messages.format("queryexecutor.execution_time", StringUtilities - .getFullHumanReadableTime(TimeUnit.NANOSECONDS.toMillis(cpuTime)))); + String execTime = StringUtilities.getFullHumanReadableTime(TimeUnit.NANOSECONDS.toMillis(cpuTime)); + info(messages.format("queryexecutor.execution_time", execTime)); info(messages.format("queryexecutor.execution_memory_profile", StringUtilities.getHumanReadableSize(vmMemory))); int rowsAffected = -1; if (!results) { @@ -273,7 +356,7 @@ } } - private String echoStatementInfo(Connection connection, String query) { + private String getNativeSql(Connection connection, String query) { try { return connection.nativeSQL((query == null ? "" : query)); @@ -282,59 +365,48 @@ } } - private static class NullResultSetViewer implements ResultSetRenderer { + private String doVariableSubstitutions(final String source) throws ParseException { - public void handleSQLException(ResultSet set, SQLException e) { + StringBuffer sbuf = new StringBuffer(); + int i = 0; + int j, k; + while (true) { + j = source.indexOf(DELIM_START, i); + if (j == -1) { + // no more variables + if (i == 0) { // this is a simple string + return source; + } + // add the tail string which contains no variables and return the result. + sbuf.append(source.substring(i, source.length())); + return sbuf.toString(); + } + sbuf.append(source.substring(i, j)); + k = source.indexOf(DELIM_STOP, j); + if (k == -1) { + throw new ParseException(messages.format("StringUtilities.bad_variable_format"), j); + } + j += DELIM_START_LEN; + String key = source.substring(j, k); + // first try in System properties + String replacement = renderer.substituteVariable(key); + // then try props parameter + if (replacement != null) { + // Do variable substitution on the replacement string + // such that we can solve "Hello ${x2}" as "Hello p1" + // the where the properties are + // x1=p1 + // x2=${x1} + String recursiveReplacement = doVariableSubstitutions(replacement); + sbuf.append(recursiveReplacement); + } else { + sbuf.append(DELIM_START); + sbuf.append(key); + sbuf.append(DELIM_STOP); + } + i = k + DELIM_STOP_LEN; } + } - public void handleStatementInterrupted(String stmtID) { - - } - - public void processGeneratedKeys(String stmtID, ResultSet keys, String nativeSQL) { - - } - - public long processResultSet(String stmtID, ResultSet set, String nativeSQL, int count) { - - return 0; - } - - public void processRowUpdates(String stmtID, int updateCount, String nativeSQL) { - - } - - public void recieveResultsetWarnings(ResultSet set, SQLWarning warnings) { - - } - - public void recieveStatementWarnings(Statement stmt, SQLWarning warnings) { - - } - - public void statementInitialized(String stmtID) { - - } - - public boolean supportsGeneratedKeys() { - - return false; - } - - public boolean supportsUpdateableResultSets() { - - return false; - } - - public boolean isCancelled() { - - return false; - } - - public String substituteVariable(String variableName) { - - return variableName; - } - } } Modified: isql-core/trunk/src/org/isqlviewer/util/StringTokenizer.java =================================================================== --- isql-core/trunk/src/org/isqlviewer/util/StringTokenizer.java 2007-04-30 22:15:13 UTC (rev 47) +++ isql-core/trunk/src/org/isqlviewer/util/StringTokenizer.java 2007-04-30 22:22:00 UTC (rev 48) @@ -27,6 +27,7 @@ */ package org.isqlviewer.util; +import java.util.ArrayList; import java.util.Enumeration; import java.util.NoSuchElementException; @@ -51,8 +52,6 @@ private String delimiters; private boolean retDelims; private boolean delimsChanged; - private char quoteChar = '\"'; - /** * maxDelimCodePoint stores the value of the delimiter character with the highest value. It is used to optimize the * detection of delimiter characters. It is unlikely to provide any optimization benefit in the hasSurrogates case @@ -171,7 +170,7 @@ boolean withinLiteral = false; while (position < maxPosition) { char c = str.charAt(position); - if (c == quoteChar && quotesEnabled) { + if (isQuotable(c) && quotesEnabled) { if (position > 0 && str.charAt(position - 1) != '\\') { // quote was not escaped // withinLiteral = !withinLiteral; @@ -191,6 +190,11 @@ return position; } + private boolean isQuotable(char character) { + + return character == '\'' || character == '\"'; + } + /** * Tests if there are more tokens available from this tokenizer's string. If this method returns <tt>true</tt>, * then a subsequent call to <tt>nextToken</tt> with no argument will successfully return a token. @@ -332,30 +336,22 @@ return quotesEnabled; } - /** - * Sets the quoting character. - * <p> - * This character will be used as defining a quoted string. such if a token exists within 2 instances of the - * character returned it will not be considered a token. - * <p> - * In a more generic sense this character can also define igornable boundaries with delimiters. - * - * @return character that determins quoted information. - */ - public synchronized char getQuoteChar() { + public String[] toArray() { - return quoteChar; - } + ArrayList<String> tokens = new ArrayList<String>(); + // reset internal variables so we get all tokens. + currentPosition = 0; + newPosition = -1; + delimsChanged = false; - /** - * Sets the quote character as the boundary character for ignoring delimiters within. - * <p> - * The quote character is only valid if and only if this instance has quotes enabled, which is by default false. - * - * @param quoteChar to set for setting ignorable parsing boundaries. - */ - public synchronized void setQuoteChar(char quoteChar) { + while (hasMoreTokens()) { + tokens.add(nextToken()); + } - this.quoteChar = quoteChar; + // reset internal variables so it can stil be used normally. + currentPosition = 0; + newPosition = -1; + delimsChanged = false; + return tokens.toArray(new String[tokens.size()]); } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |