Author: tomdz Date: Sun Mar 9 08:40:47 2008 New Revision: 635262 URL: http://svn.apache.org/viewvc?rev=635262&view=rev Log: Implementation of DDLUTILS-198: Replace Jakarta ORO regular expressions with Java 1.4 regular expressions
Removed: db/ddlutils/trunk/lib/jakarta-oro-2.0.8.jar Modified: db/ddlutils/trunk/.classpath db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/DateConverter.java db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/TimeConverter.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8ModelReader.java db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseModelReader.java db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java Modified: db/ddlutils/trunk/.classpath URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/.classpath?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/.classpath (original) +++ db/ddlutils/trunk/.classpath Sun Mar 9 08:40:47 2008 @@ -10,7 +10,6 @@ <classpathentry exported="true" kind="lib" path="lib/commons-beanutils-1.7.0.jar"/> <classpathentry exported="true" kind="lib" path="lib/commons-lang-2.1.jar"/> <classpathentry exported="true" kind="lib" path="lib/commons-codec-1.3.jar"/> - <classpathentry exported="true" kind="lib" path="lib/jakarta-oro-2.0.8.jar"/> <classpathentry kind="lib" path="lib/build-only/ant-1.6.5.jar"/> <classpathentry kind="lib" path="lib/build-only/junit-3.8.2.jar"/> <classpathentry kind="lib" path="lib/stax-api-1.0.1.jar"/> Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/DateConverter.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/DateConverter.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/DateConverter.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/DateConverter.java Sun Mar 9 08:40:47 2008 @@ -22,14 +22,11 @@ import java.sql.Date; import java.sql.Types; import java.util.Calendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.MatchResult; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Converts between [EMAIL PROTECTED] java.sql.Date} and [EMAIL PROTECTED] java.lang.String} using the standard @@ -49,13 +46,11 @@ */ public DateConverter() { - PatternCompiler compiler = new Perl5Compiler(); - try { - _datePattern = compiler.compile("(\\d{2,4})(?:\\-(\\d{2}))?(?:\\-(\\d{2}))?.*"); + _datePattern = Pattern.compile("(\\d{2,4})(?:\\-(\\d{2}))?(?:\\-(\\d{2}))?.*"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -77,26 +72,25 @@ { // we're not using [EMAIL PROTECTED] java.sql.Date#valueOf(String)} as this method is too strict // it only parses the full spec "yyyy-mm-dd" - Perl5Matcher matcher = new Perl5Matcher(); - int year = 1970; - int month = 1; - int day = 1; + Matcher matcher = _datePattern.matcher(textRep); + int year = 1970; + int month = 1; + int day = 1; - if (matcher.matches(textRep, _datePattern)) + if (matcher.matches()) { - MatchResult match = matcher.getMatch(); - int numGroups = match.groups(); + int numGroups = matcher.groupCount(); try { - year = Integer.parseInt(match.group(1)); - if ((numGroups > 2) && (match.group(2) != null)) + year = Integer.parseInt(matcher.group(1)); + if ((numGroups >= 2) && (matcher.group(2) != null)) { - month = Integer.parseInt(match.group(2)); + month = Integer.parseInt(matcher.group(2)); } - if ((numGroups > 3) && (match.group(3) != null)) + if ((numGroups >= 3) && (matcher.group(3) != null)) { - day = Integer.parseInt(match.group(3)); + day = Integer.parseInt(matcher.group(3)); } } catch (NumberFormatException ex) Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/TimeConverter.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/TimeConverter.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/TimeConverter.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/io/converters/TimeConverter.java Sun Mar 9 08:40:47 2008 @@ -22,14 +22,11 @@ import java.sql.Time; import java.sql.Types; import java.util.Calendar; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.MatchResult; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Converts between [EMAIL PROTECTED] java.sql.Time} and [EMAIL PROTECTED] java.lang.String} using the standard @@ -49,13 +46,11 @@ */ public TimeConverter() { - PatternCompiler compiler = new Perl5Compiler(); - try { - _timePattern = compiler.compile("(?:\\d{4}\\-\\d{2}\\-\\d{2}\\s)?(\\d{2})(?::(\\d{2}))?(?::(\\d{2}))?(?:\\..*)?"); + _timePattern = Pattern.compile("(?:\\d{4}\\-\\d{2}\\-\\d{2}\\s)?(\\d{2})(?::(\\d{2}))?(?::(\\d{2}))?(?:\\..*)?"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -77,26 +72,25 @@ { // we're not using [EMAIL PROTECTED] java.sql.Time#valueOf(String)} as this method is too strict // it only parses the full spec "hh:mm:ss" - Perl5Matcher matcher = new Perl5Matcher(); - int hours = 0; - int minutes = 0; - int seconds = 0; + Matcher matcher = _timePattern.matcher(textRep); + int hours = 0; + int minutes = 0; + int seconds = 0; - if (matcher.matches(textRep, _timePattern)) + if (matcher.matches()) { - MatchResult match = matcher.getMatch(); - int numGroups = match.groups(); + int numGroups = matcher.groupCount(); try { - hours = Integer.parseInt(match.group(1)); - if ((numGroups > 2) && (match.group(2) != null)) + hours = Integer.parseInt(matcher.group(1)); + if ((numGroups >= 2) && (matcher.group(2) != null)) { - minutes = Integer.parseInt(match.group(2)); + minutes = Integer.parseInt(matcher.group(2)); } - if ((numGroups > 3) && (match.group(3) != null)) + if ((numGroups >= 3) && (matcher.group(3) != null)) { - seconds = Integer.parseInt(match.group(3)); + seconds = Integer.parseInt(matcher.group(3)); } } catch (NumberFormatException ex) Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/db2/Db2ModelReader.java Sun Mar 9 08:40:47 2008 @@ -25,6 +25,9 @@ import java.sql.Types; import java.util.HashSet; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.Platform; @@ -34,12 +37,6 @@ import org.apache.ddlutils.model.TypeMap; import org.apache.ddlutils.platform.DatabaseMetaDataWrapper; import org.apache.ddlutils.platform.JdbcModelReader; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.PatternMatcher; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Reads a database model from a Db2 UDB database. @@ -66,14 +63,12 @@ setDefaultCatalogPattern(null); setDefaultSchemaPattern(null); - PatternCompiler compiler = new Perl5Compiler(); - try { - _db2TimePattern = compiler.compile("'(\\d{2}).(\\d{2}).(\\d{2})'"); - _db2TimestampPattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})\\-(\\d{2}).(\\d{2}).(\\d{2})(\\.\\d{1,8})?'"); + _db2TimePattern = Pattern.compile("'(\\d{2}).(\\d{2}).(\\d{2})'"); + _db2TimestampPattern = Pattern.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})\\-(\\d{2}).(\\d{2}).(\\d{2})(\\.\\d{1,8})?'"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -115,22 +110,22 @@ { if (column.getTypeCode() == Types.TIME) { - PatternMatcher matcher = new Perl5Matcher(); + Matcher matcher = _db2TimePattern.matcher(column.getDefaultValue()); // Db2 returns "HH24.MI.SS" - if (matcher.matches(column.getDefaultValue(), _db2TimePattern)) + if (matcher.matches()) { StringBuffer newDefault = new StringBuffer(); newDefault.append("'"); // the hour - newDefault.append(matcher.getMatch().group(1)); + newDefault.append(matcher.group(1)); newDefault.append(":"); // the minute - newDefault.append(matcher.getMatch().group(2)); + newDefault.append(matcher.group(2)); newDefault.append(":"); // the second - newDefault.append(matcher.getMatch().group(3)); + newDefault.append(matcher.group(3)); newDefault.append("'"); column.setDefaultValue(newDefault.toString()); @@ -138,29 +133,29 @@ } else if (column.getTypeCode() == Types.TIMESTAMP) { - PatternMatcher matcher = new Perl5Matcher(); + Matcher matcher = _db2TimestampPattern.matcher(column.getDefaultValue()); // Db2 returns "YYYY-MM-DD-HH24.MI.SS.FF" - if (matcher.matches(column.getDefaultValue(), _db2TimestampPattern)) + if (matcher.matches()) { StringBuffer newDefault = new StringBuffer(); newDefault.append("'"); // group 1 is the date which has the correct format - newDefault.append(matcher.getMatch().group(1)); + newDefault.append(matcher.group(1)); newDefault.append(" "); // the hour - newDefault.append(matcher.getMatch().group(2)); + newDefault.append(matcher.group(2)); newDefault.append(":"); // the minute - newDefault.append(matcher.getMatch().group(3)); + newDefault.append(matcher.group(3)); newDefault.append(":"); // the second - newDefault.append(matcher.getMatch().group(4)); + newDefault.append(matcher.group(4)); // optionally, the fraction - if ((matcher.getMatch().groups() > 4) && (matcher.getMatch().group(4) != null)) + if ((matcher.groupCount() >= 5) && (matcher.group(5) != null)) { - newDefault.append(matcher.getMatch().group(5)); + newDefault.append(matcher.group(5)); } newDefault.append("'"); Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/mssql/MSSqlModelReader.java Sun Mar 9 08:40:47 2008 @@ -26,6 +26,9 @@ import java.sql.Timestamp; import java.sql.Types; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.Platform; @@ -35,12 +38,6 @@ import org.apache.ddlutils.model.TypeMap; import org.apache.ddlutils.platform.DatabaseMetaDataWrapper; import org.apache.ddlutils.platform.JdbcModelReader; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.PatternMatcher; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Reads a database model from a Microsoft Sql Server database. @@ -68,14 +65,12 @@ setDefaultSchemaPattern(null); setDefaultTablePattern("%"); - PatternCompiler compiler = new Perl5Compiler(); - try { - _isoDatePattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'"); - _isoTimePattern = compiler.compile("'(\\d{2}:\\d{2}:\\d{2})'"); + _isoDatePattern = Pattern.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'"); + _isoTimePattern = Pattern.compile("'(\\d{2}:\\d{2}:\\d{2})'"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -189,16 +184,21 @@ { // Sql Server maintains the default values for DATE/TIME jdbc types, so we have to // migrate the default value to TIMESTAMP - PatternMatcher matcher = new Perl5Matcher(); - Timestamp timestamp = null; + Matcher matcher = _isoDatePattern.matcher(defaultValue); + Timestamp timestamp = null; - if (matcher.matches(defaultValue, _isoDatePattern)) + if (matcher.matches()) { - timestamp = new Timestamp(Date.valueOf(matcher.getMatch().group(1)).getTime()); + timestamp = new Timestamp(Date.valueOf(matcher.group(1)).getTime()); } - else if (matcher.matches(defaultValue, _isoTimePattern)) + else { - timestamp = new Timestamp(Time.valueOf(matcher.getMatch().group(1)).getTime()); + matcher = _isoTimePattern.matcher(defaultValue); + + if (matcher.matches()) + { + timestamp = new Timestamp(Time.valueOf(matcher.group(1)).getTime()); + } } if (timestamp != null) { Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8Builder.java Sun Mar 9 08:40:47 2008 @@ -22,6 +22,8 @@ import java.io.IOException; import java.sql.Types; import java.util.Map; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.Platform; @@ -33,11 +35,6 @@ import org.apache.ddlutils.model.TypeMap; import org.apache.ddlutils.platform.SqlBuilder; import org.apache.ddlutils.util.StringUtilsExt; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * The SQL Builder for Oracle. @@ -63,15 +60,13 @@ super(platform); addEscapedCharSequence("'", "''"); - PatternCompiler compiler = new Perl5Compiler(); - try { - _isoDatePattern = compiler.compile("\\d{4}\\-\\d{2}\\-\\d{2}"); - _isoTimePattern = compiler.compile("\\d{2}:\\d{2}:\\d{2}"); - _isoTimestampPattern = compiler.compile("\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}[\\.\\d{1,8}]?"); + _isoDatePattern = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2}"); + _isoTimePattern = Pattern.compile("\\d{2}:\\d{2}:\\d{2}"); + _isoTimestampPattern = Pattern.compile("\\d{4}\\-\\d{2}\\-\\d{2} \\d{2}:\\d{2}:\\d{2}[\\.\\d{1,8}]?"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -294,21 +289,21 @@ // and thus the user has to ensure that it is correct else if (column.getTypeCode() == Types.DATE) { - if (new Perl5Matcher().matches(column.getDefaultValue(), _isoDatePattern)) + if (_isoDatePattern.matcher(column.getDefaultValue()).matches()) { return "TO_DATE('"+column.getDefaultValue()+"', 'YYYY-MM-DD')"; } } else if (column.getTypeCode() == Types.TIME) { - if (new Perl5Matcher().matches(column.getDefaultValue(), _isoTimePattern)) + if (_isoTimePattern.matcher(column.getDefaultValue()).matches()) { return "TO_DATE('"+column.getDefaultValue()+"', 'HH24:MI:SS')"; } } else if (column.getTypeCode() == Types.TIMESTAMP) { - if (new Perl5Matcher().matches(column.getDefaultValue(), _isoTimestampPattern)) + if (_isoTimestampPattern.matcher(column.getDefaultValue()).matches()) { return "TO_DATE('"+column.getDefaultValue()+"', 'YYYY-MM-DD HH24:MI:SS')"; } Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8ModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8ModelReader.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8ModelReader.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/oracle/Oracle8ModelReader.java Sun Mar 9 08:40:47 2008 @@ -30,6 +30,9 @@ import java.util.Collection; import java.util.HashMap; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.commons.collections.map.ListOrderedMap; import org.apache.ddlutils.DdlUtilsException; @@ -39,12 +42,6 @@ import org.apache.ddlutils.model.TypeMap; import org.apache.ddlutils.platform.DatabaseMetaDataWrapper; import org.apache.ddlutils.platform.JdbcModelReader; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.PatternMatcher; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Reads a database model from an Oracle 8 database. @@ -72,15 +69,13 @@ setDefaultSchemaPattern(null); setDefaultTablePattern("%"); - PatternCompiler compiler = new Perl5Compiler(); - try { - _oracleIsoDatePattern = compiler.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD'\\)"); - _oracleIsoTimePattern = compiler.compile("TO_DATE\\('([^']*)'\\, 'HH24:MI:SS'\\)"); - _oracleIsoTimestampPattern = compiler.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD HH24:MI:SS'\\)"); + _oracleIsoDatePattern = Pattern.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD'\\)"); + _oracleIsoTimePattern = Pattern.compile("TO_DATE\\('([^']*)'\\, 'HH24:MI:SS'\\)"); + _oracleIsoTimestampPattern = Pattern.compile("TO_DATE\\('([^']*)'\\, 'YYYY\\-MM\\-DD HH24:MI:SS'\\)"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -189,26 +184,34 @@ // we also reverse the ISO-format adaptation, and adjust the default value to timestamp if (column.getDefaultValue() != null) { - PatternMatcher matcher = new Perl5Matcher(); - Timestamp timestamp = null; + Matcher matcher = _oracleIsoTimestampPattern.matcher(column.getDefaultValue()); + Timestamp timestamp = null; - if (matcher.matches(column.getDefaultValue(), _oracleIsoTimestampPattern)) + if (matcher.matches()) { - String timestampVal = matcher.getMatch().group(1); + String timestampVal = matcher.group(1); timestamp = Timestamp.valueOf(timestampVal); } - else if (matcher.matches(column.getDefaultValue(), _oracleIsoDatePattern)) + else { - String dateVal = matcher.getMatch().group(1); - - timestamp = new Timestamp(Date.valueOf(dateVal).getTime()); - } - else if (matcher.matches(column.getDefaultValue(), _oracleIsoTimePattern)) - { - String timeVal = matcher.getMatch().group(1); - - timestamp = new Timestamp(Time.valueOf(timeVal).getTime()); + matcher = _oracleIsoDatePattern.matcher(column.getDefaultValue()); + if (matcher.matches()) + { + String dateVal = matcher.group(1); + + timestamp = new Timestamp(Date.valueOf(dateVal).getTime()); + } + else + { + matcher = _oracleIsoTimePattern.matcher(column.getDefaultValue()); + if (matcher.matches()) + { + String timeVal = matcher.group(1); + + timestamp = new Timestamp(Time.valueOf(timeVal).getTime()); + } + } } if (timestamp != null) { @@ -306,7 +309,7 @@ "a.TABLE_NAME=? AND a.GENERATED=? AND a.TABLE_TYPE=? AND a.TABLE_NAME=b.TABLE_NAME AND a.INDEX_NAME=b.INDEX_NAME AND " + "a.INDEX_NAME NOT IN (SELECT DISTINCT c.CONSTRAINT_NAME FROM USER_CONSTRAINTS c WHERE c.CONSTRAINT_TYPE=? AND c.TABLE_NAME=a.TABLE_NAME)"; final String queryWithSchema = - query.substring(query.length() - 1) + " AND c.OWNER LIKE ?) AND a.TABLE_OWNER LIKE ?"; + query.substring(0, query.length() - 1) + " AND c.OWNER LIKE ?) AND a.TABLE_OWNER LIKE ?"; Map indices = new ListOrderedMap(); PreparedStatement stmt = null; Modified: db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseModelReader.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseModelReader.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseModelReader.java (original) +++ db/ddlutils/trunk/src/java/org/apache/ddlutils/platform/sybase/SybaseModelReader.java Sun Mar 9 08:40:47 2008 @@ -29,6 +29,9 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; import org.apache.ddlutils.DdlUtilsException; import org.apache.ddlutils.Platform; @@ -40,12 +43,6 @@ import org.apache.ddlutils.model.TypeMap; import org.apache.ddlutils.platform.DatabaseMetaDataWrapper; import org.apache.ddlutils.platform.JdbcModelReader; -import org.apache.oro.text.regex.MalformedPatternException; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternCompiler; -import org.apache.oro.text.regex.PatternMatcher; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Reads a database model from a Sybase database. @@ -71,14 +68,12 @@ setDefaultSchemaPattern(null); setDefaultTablePattern("%"); - PatternCompiler compiler = new Perl5Compiler(); - try { - _isoDatePattern = compiler.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'"); - _isoTimePattern = compiler.compile("'(\\d{2}:\\d{2}:\\d{2})'"); + _isoDatePattern = Pattern.compile("'(\\d{4}\\-\\d{2}\\-\\d{2})'"); + _isoTimePattern = Pattern.compile("'(\\d{2}:\\d{2}:\\d{2})'"); } - catch (MalformedPatternException ex) + catch (PatternSyntaxException ex) { throw new DdlUtilsException(ex); } @@ -117,17 +112,21 @@ { // Sybase maintains the default values for DATE/TIME jdbc types, so we have to // migrate the default value to TIMESTAMP - PatternMatcher matcher = new Perl5Matcher(); - Timestamp timestamp = null; + Matcher matcher = _isoDatePattern.matcher(column.getDefaultValue()); + Timestamp timestamp = null; - if (matcher.matches(column.getDefaultValue(), _isoDatePattern)) - { - timestamp = new Timestamp(Date.valueOf(matcher.getMatch().group(1)).getTime()); - } - else if (matcher.matches(column.getDefaultValue(), _isoTimePattern)) + if (matcher.matches()) { - timestamp = new Timestamp(Time.valueOf(matcher.getMatch().group(1)).getTime()); + timestamp = new Timestamp(Date.valueOf(matcher.group(1)).getTime()); } + else + { + matcher = _isoTimePattern.matcher(column.getDefaultValue()); + if (matcher.matches()) + { + timestamp = new Timestamp(Time.valueOf(matcher.group(1)).getTime()); + } + } if (timestamp != null) { column.setDefaultValue(timestamp.toString()); Modified: db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java URL: http://svn.apache.org/viewvc/db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java?rev=635262&r1=635261&r2=635262&view=diff ============================================================================== --- db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java (original) +++ db/ddlutils/trunk/src/test/org/apache/ddlutils/platform/TestMSSqlPlatform.java Sun Mar 9 08:40:47 2008 @@ -19,14 +19,11 @@ * under the License. */ +import java.util.regex.Matcher; +import java.util.regex.Pattern; + import org.apache.ddlutils.TestPlatformBase; import org.apache.ddlutils.platform.mssql.MSSqlPlatform; -import org.apache.oro.text.regex.MatchResult; -import org.apache.oro.text.regex.Pattern; -import org.apache.oro.text.regex.PatternMatcher; -import org.apache.oro.text.regex.PatternMatcherInput; -import org.apache.oro.text.regex.Perl5Compiler; -import org.apache.oro.text.regex.Perl5Matcher; /** * Tests the Microsoft SQL Server platform. @@ -52,15 +49,15 @@ // Since we have no way of knowing the auto-generated variables in the SQL, // we simply try to extract it from the SQL - Pattern declarePattern = new Perl5Compiler().compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); - PatternMatcher matcher = new Perl5Matcher(); - String tableNameVar = "tablename"; - String constraintNameVar = "constraintname"; + Pattern declarePattern = Pattern.compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); + Matcher matcher = declarePattern.matcher(sql); + String tableNameVar = "tablename"; + String constraintNameVar = "constraintname"; - if (matcher.contains(sql, declarePattern)) + if (matcher.find()) { - tableNameVar = matcher.getMatch().group(1); - constraintNameVar = matcher.getMatch().group(2); + tableNameVar = matcher.group(1); + constraintNameVar = matcher.group(2); } assertEqualsIgnoringWhitespaces( "SET quoted_identifier on;\n"+ @@ -130,15 +127,15 @@ // Since we have no way of knowing the auto-generated variables in the SQL, // we simply try to extract it from the SQL - Pattern declarePattern = new Perl5Compiler().compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); - PatternMatcher matcher = new Perl5Matcher(); - String tableNameVar = "tablename"; - String constraintNameVar = "constraintname"; + Pattern declarePattern = Pattern.compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); + Matcher matcher = declarePattern.matcher(sql); + String tableNameVar = "tablename"; + String constraintNameVar = "constraintname"; - if (matcher.contains(sql, declarePattern)) + if (matcher.find()) { - tableNameVar = matcher.getMatch().group(1); - constraintNameVar = matcher.getMatch().group(2); + tableNameVar = matcher.group(1); + constraintNameVar = matcher.group(2); } // Note that this is not valid SQL as a table can have only one identity column at most assertEqualsIgnoringWhitespaces( @@ -184,19 +181,17 @@ // Since we have no way of knowing the auto-generated variables in the SQL, // we simply try to extract it from the SQL - Pattern declarePattern = new Perl5Compiler().compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); - PatternMatcherInput input = new PatternMatcherInput(sql); - PatternMatcher matcher = new Perl5Matcher(); - String[] tableNameVars = { "tablename", "tablename", "tablename" }; - String[] constraintNameVars = { "constraintname", "constraintname", "constraintname" }; + Pattern declarePattern = Pattern.compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); + Matcher matcher = declarePattern.matcher(sql); + int startPos = 0; + String[] tableNameVars = { "tablename", "tablename", "tablename" }; + String[] constraintNameVars = { "constraintname", "constraintname", "constraintname" }; - for (int idx = 0; (idx < 3) && matcher.contains(input, declarePattern); idx++) + for (int idx = 0; (idx < 3) && matcher.find(startPos); idx++) { - MatchResult result = matcher.getMatch(); - - tableNameVars[idx] = result.group(1); - constraintNameVars[idx] = result.group(2); - input.setCurrentOffset(result.endOffset(2)); + tableNameVars[idx] = matcher.group(1); + constraintNameVars[idx] = matcher.group(2); + startPos = matcher.end(); } assertEqualsIgnoringWhitespaces( "SET quoted_identifier on;\n"+ @@ -301,15 +296,15 @@ // Since we have no way of knowing the auto-generated variables in the SQL, // we simply try to extract it from the SQL - Pattern declarePattern = new Perl5Compiler().compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); - PatternMatcher matcher = new Perl5Matcher(); - String tableNameVar = "tablename"; - String constraintNameVar = "constraintname"; + Pattern declarePattern = Pattern.compile("DECLARE @([\\S]+) [EMAIL PROTECTED]@([\\S]+)"); + Matcher matcher = declarePattern.matcher(sql); + String tableNameVar = "tablename"; + String constraintNameVar = "constraintname"; - if (matcher.contains(sql, declarePattern)) + if (matcher.find()) { - tableNameVar = matcher.getMatch().group(1); - constraintNameVar = matcher.getMatch().group(2); + tableNameVar = matcher.group(1); + constraintNameVar = matcher.group(2); } assertEqualsIgnoringWhitespaces( "SET quoted_identifier on;\n"+