提交 f31539cc authored 作者: Thomas Mueller Graf's avatar Thomas Mueller Graf

Javadocs

上级 d69c4432
...@@ -1913,6 +1913,13 @@ public class Parser { ...@@ -1913,6 +1913,13 @@ public class Parser {
} }
} }
/**
* Find out which of the table filters appears first in the "from" clause.
*
* @param o1 the first table filter
* @param o2 the second table filter
* @return -1 if o1 appears first, and 1 if o2 appears first
*/
static int compareTableFilters(TableFilter o1, TableFilter o2) { static int compareTableFilters(TableFilter o1, TableFilter o2) {
assert o1.getOrderInFrom() != o2.getOrderInFrom(); assert o1.getOrderInFrom() != o2.getOrderInFrom();
return o1.getOrderInFrom() > o2.getOrderInFrom() ? 1 : -1; return o1.getOrderInFrom() > o2.getOrderInFrom() ? 1 : -1;
......
...@@ -159,6 +159,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index { ...@@ -159,6 +159,7 @@ public abstract class BaseIndex extends SchemaObjectBase implements Index {
* @param filters all joined table filters * @param filters all joined table filters
* @param filter the current table filter index * @param filter the current table filter index
* @param sortOrder the sort order * @param sortOrder the sort order
* @param isScanIndex whether this is a "table scan" index
* @return the estimated cost * @return the estimated cost
*/ */
protected final long getCostRangeIndex(int[] masks, long rowCount, protected final long getCostRangeIndex(int[] masks, long rowCount,
......
...@@ -225,6 +225,14 @@ public class ViewIndex extends BaseIndex implements SpatialIndex { ...@@ -225,6 +225,14 @@ public class ViewIndex extends BaseIndex implements SpatialIndex {
return new ViewCursor(this, result, first, last); return new ViewCursor(this, result, first, last);
} }
/**
* Set the query parameters.
*
* @param session the session
* @param first the lower bound
* @param last the upper bound
* @param intersection the intersection
*/
public void setupQueryParameters(Session session, SearchRow first, SearchRow last, public void setupQueryParameters(Session session, SearchRow first, SearchRow last,
SearchRow intersection) { SearchRow intersection) {
ArrayList<Parameter> paramList = query.getParameters(); ArrayList<Parameter> paramList = query.getParameters();
......
...@@ -37,6 +37,10 @@ import org.h2.value.ValueLong; ...@@ -37,6 +37,10 @@ import org.h2.value.ValueLong;
* @author Sergi Vladykin * @author Sergi Vladykin
*/ */
public final class JoinBatch { public final class JoinBatch {
/**
* An empty cursor.
*/
static final Cursor EMPTY_CURSOR = new Cursor() { static final Cursor EMPTY_CURSOR = new Cursor() {
@Override @Override
public boolean previous() { public boolean previous() {
...@@ -64,11 +68,29 @@ public final class JoinBatch { ...@@ -64,11 +68,29 @@ public final class JoinBatch {
} }
}; };
/**
* An empty future cursor.
*/
static final Future<Cursor> EMPTY_FUTURE_CURSOR = new DoneFuture<Cursor>(EMPTY_CURSOR); static final Future<Cursor> EMPTY_FUTURE_CURSOR = new DoneFuture<Cursor>(EMPTY_CURSOR);
/**
* The top cursor.
*/
Future<Cursor> viewTopFutureCursor; Future<Cursor> viewTopFutureCursor;
/**
* The top filter.
*/
JoinFilter top; JoinFilter top;
/**
* The filters.
*/
JoinFilter[] filters; JoinFilter[] filters;
/**
* Whether this is a batched subquery.
*/
boolean batchedSubQuery; boolean batchedSubQuery;
private boolean started; private boolean started;
...@@ -125,6 +147,8 @@ public final class JoinBatch { ...@@ -125,6 +147,8 @@ public final class JoinBatch {
} }
/** /**
* Register the table filter and lookup batch.
*
* @param filter table filter * @param filter table filter
* @param lookupBatch lookup batch * @param lookupBatch lookup batch
*/ */
...@@ -135,8 +159,10 @@ public final class JoinBatch { ...@@ -135,8 +159,10 @@ public final class JoinBatch {
} }
/** /**
* Get the value for the given column.
*
* @param filterId table filter id * @param filterId table filter id
* @param column column * @param column the column
* @return column value for current row * @return column value for current row
*/ */
public Value getValue(int filterId, Column column) { public Value getValue(int filterId, Column column) {
......
...@@ -123,8 +123,8 @@ public class TableFilter implements ColumnResolver { ...@@ -123,8 +123,8 @@ public class TableFilter implements ColumnResolver {
* @param alias the alias name * @param alias the alias name
* @param rightsChecked true if rights are already checked * @param rightsChecked true if rights are already checked
* @param select the select statement * @param select the select statement
* @param orderInFrom Original order number of this table filter in FROM * @param orderInFrom original order number (index) of this table filter in
* clause. * FROM clause (0, 1, 2,...)
*/ */
public TableFilter(Session session, Table table, String alias, public TableFilter(Session session, Table table, String alias,
boolean rightsChecked, Select select, int orderInFrom) { boolean rightsChecked, Select select, int orderInFrom) {
...@@ -140,6 +140,12 @@ public class TableFilter implements ColumnResolver { ...@@ -140,6 +140,12 @@ public class TableFilter implements ColumnResolver {
this.orderInFrom = orderInFrom; this.orderInFrom = orderInFrom;
} }
/**
* Get the order number (index) of this table filter in the "from" clause of
* the query.
*
* @return the index (0, 1, 2,...)
*/
public int getOrderInFrom() { public int getOrderInFrom() {
return orderInFrom; return orderInFrom;
} }
...@@ -375,6 +381,8 @@ public class TableFilter implements ColumnResolver { ...@@ -375,6 +381,8 @@ public class TableFilter implements ColumnResolver {
* Attempt to initialize batched join. * Attempt to initialize batched join.
* *
* @param jb join batch if it is already created * @param jb join batch if it is already created
* @param filters the table filters
* @param filter the filter index (0, 1,...)
* @return join batch if query runs over index which supports batched * @return join batch if query runs over index which supports batched
* lookups, {@code null} otherwise * lookups, {@code null} otherwise
*/ */
...@@ -555,6 +563,13 @@ public class TableFilter implements ColumnResolver { ...@@ -555,6 +563,13 @@ public class TableFilter implements ColumnResolver {
// scanCount); // scanCount);
} }
/**
* Whether the current value of the condition is true, or there is no
* condition.
*
* @param condition the condition (null for no condition)
* @return true if yes
*/
boolean isOk(Expression condition) { boolean isOk(Expression condition) {
if (condition == null) { if (condition == null) {
return true; return true;
......
...@@ -414,6 +414,11 @@ public class TableView extends Table { ...@@ -414,6 +414,11 @@ public class TableView extends Table {
invalidate(); invalidate();
} }
/**
* Clear the cached indexes for all sessions.
*
* @param database the database
*/
public static void clearIndexCaches(Database database) { public static void clearIndexCaches(Database database) {
for (Session s : database.getSessions(true)) { for (Session s : database.getSessions(true)) {
s.clearViewIndexCache(); s.clearViewIndexCache();
......
...@@ -906,12 +906,17 @@ public class DateTimeUtils { ...@@ -906,12 +906,17 @@ public class DateTimeUtils {
} }
/** /**
* Adds the number of months to the date. If the resulting month's number of days is less than the original's day-of-month, the resulting * Adds the number of months to the date. If the resulting month's number of
* days is less than the original's day-of-month, the resulting
* day-of-months gets adjusted accordingly: * day-of-months gets adjusted accordingly:
* * <br>
* 30.04.2007 - 2 months = 28.02.2007 * 30.04.2007 - 2 months = 28.02.2007
*
* @param refDate the original date
* @param nrOfMonthsToAdd the number of months to add
* @return the new timestamp
*/ */
public static Timestamp addMonths(final Timestamp refDate, final int nrOfMonthsToAdd) { public static Timestamp addMonths(Timestamp refDate, int nrOfMonthsToAdd) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(refDate); calendar.setTime(refDate);
calendar.add(Calendar.MONTH, nrOfMonthsToAdd); calendar.add(Calendar.MONTH, nrOfMonthsToAdd);
......
...@@ -137,6 +137,12 @@ public class ToDateParser { ...@@ -137,6 +137,12 @@ public class ToDateParser {
return p; return p;
} }
/**
* Remove a token from a string.
*
* @param inputFragmentStr the input fragment
* @param formatFragment the format fragment
*/
void remove(String inputFragmentStr, String formatFragment) { void remove(String inputFragmentStr, String formatFragment) {
if (inputFragmentStr != null && inputStr.length() >= inputFragmentStr.length()) { if (inputFragmentStr != null && inputStr.length() >= inputFragmentStr.length()) {
inputStr = inputStr.substring(inputFragmentStr.length()); inputStr = inputStr.substring(inputFragmentStr.length());
...@@ -167,11 +173,25 @@ public class ToDateParser { ...@@ -167,11 +173,25 @@ public class ToDateParser {
return sb.toString(); return sb.toString();
} }
/**
* Parse a string as a timestamp with the given format.
*
* @param input the input
* @param format the format
* @return the timestamp
*/
public static Timestamp toTimestamp(String input, String format) { public static Timestamp toTimestamp(String input, String format) {
ToDateParser parser = getTimestampParser(input, format); ToDateParser parser = getTimestampParser(input, format);
return parser.getResultingTimestamp(); return parser.getResultingTimestamp();
} }
/**
* Parse a string as a date with the given format.
*
* @param input the input
* @param format the format
* @return the date as a timestamp
*/
public static Timestamp toDate(String input, String format) { public static Timestamp toDate(String input, String format) {
ToDateParser parser = getDateParser(input, format); ToDateParser parser = getDateParser(input, format);
return parser.getResultingTimestamp(); return parser.getResultingTimestamp();
......
...@@ -30,31 +30,95 @@ import org.h2.message.DbException; ...@@ -30,31 +30,95 @@ import org.h2.message.DbException;
* TO_DATE-format conventions and how to parse the corresponding data. * TO_DATE-format conventions and how to parse the corresponding data.
*/ */
class ToDateTokenizer { class ToDateTokenizer {
/**
* The pattern for a number.
*/
static final Pattern PATTERN_NUMBER = Pattern.compile("^([+-]?[0-9]+)"); static final Pattern PATTERN_NUMBER = Pattern.compile("^([+-]?[0-9]+)");
/**
* The pattern for for digits (typically a year).
*/
static final Pattern PATTERN_FOUR_DIGITS = Pattern.compile("^([+-]?[0-9]{4})"); static final Pattern PATTERN_FOUR_DIGITS = Pattern.compile("^([+-]?[0-9]{4})");
/**
* The pattern for three digits.
*/
static final Pattern PATTERN_THREE_DIGITS = Pattern.compile("^([+-]?[0-9]{3})"); static final Pattern PATTERN_THREE_DIGITS = Pattern.compile("^([+-]?[0-9]{3})");
/**
* The pattern for two digits.
*/
static final Pattern PATTERN_TWO_DIGITS = Pattern.compile("^([+-]?[0-9]{2})"); static final Pattern PATTERN_TWO_DIGITS = Pattern.compile("^([+-]?[0-9]{2})");
/**
* The pattern for one or two digits.
*/
static final Pattern PATTERN_TWO_DIGITS_OR_LESS = static final Pattern PATTERN_TWO_DIGITS_OR_LESS =
Pattern.compile("^([+-]?[0-9][0-9]?)"); Pattern.compile("^([+-]?[0-9][0-9]?)");
/**
* The pattern for one digit.
*/
static final Pattern PATTERN_ONE_DIGIT = static final Pattern PATTERN_ONE_DIGIT =
Pattern.compile("^([+-]?[0-9])"); Pattern.compile("^([+-]?[0-9])");
/**
* The pattern for a fraction (of a second for example).
*/
static final Pattern PATTERN_FF = static final Pattern PATTERN_FF =
Pattern.compile("^(FF[0-9]?)", Pattern.CASE_INSENSITIVE); Pattern.compile("^(FF[0-9]?)", Pattern.CASE_INSENSITIVE);
/**
* The pattern for "am" or "pm".
*/
static final Pattern PATTERN_AM_PM = static final Pattern PATTERN_AM_PM =
Pattern.compile("^(AM|A\\.M\\.|PM|P\\.M\\.)", Pattern.CASE_INSENSITIVE); Pattern.compile("^(AM|A\\.M\\.|PM|P\\.M\\.)", Pattern.CASE_INSENSITIVE);
/**
* The pattern for "bc" or "ad".
*/
static final Pattern PATTERN_BC_AD = static final Pattern PATTERN_BC_AD =
Pattern.compile("^(BC|B\\.C\\.|AD|A\\.D\\.)", Pattern.CASE_INSENSITIVE); Pattern.compile("^(BC|B\\.C\\.|AD|A\\.D\\.)", Pattern.CASE_INSENSITIVE);
/**
* The parslet for a year.
*/
static final YearParslet PARSLET_YEAR = new YearParslet(); static final YearParslet PARSLET_YEAR = new YearParslet();
/**
* The parslet for a month.
*/
static final MonthParslet PARSLET_MONTH = new MonthParslet(); static final MonthParslet PARSLET_MONTH = new MonthParslet();
/**
* The parslet for a day.
*/
static final DayParslet PARSLET_DAY = new DayParslet(); static final DayParslet PARSLET_DAY = new DayParslet();
/**
* The parslet for time.
*/
static final TimeParslet PARSLET_TIME = new TimeParslet(); static final TimeParslet PARSLET_TIME = new TimeParslet();
/**
* The number of milliseconds in a day.
*/
static final int MILLIS_IN_HOUR = 60 * 60 * 1000; static final int MILLIS_IN_HOUR = 60 * 60 * 1000;
/** /**
* Interface of the classes that can parse a specialized small bit of the * Interface of the classes that can parse a specialized small bit of the
* TO_DATE format-string * TO_DATE format-string.
*/ */
interface ToDateParslet { interface ToDateParslet {
/**
* Parse a date part.
*
* @param params the parameters that contains the string
* @param formatTokenEnum the format
* @param formatTokenStr the format string
*/
void parse(ToDateParser params, FormatTokenEnum formatTokenEnum, void parse(ToDateParser params, FormatTokenEnum formatTokenEnum,
String formatTokenStr); String formatTokenStr);
} }
...@@ -75,7 +139,7 @@ class ToDateTokenizer { ...@@ -75,7 +139,7 @@ class ToDateTokenizer {
case IYYY: case IYYY:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_FOUR_DIGITS, params, formatTokenEnum); PATTERN_FOUR_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
// Gregorian calendar does not have a year 0. // Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust // 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1); result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1);
...@@ -84,7 +148,7 @@ class ToDateTokenizer { ...@@ -84,7 +148,7 @@ class ToDateTokenizer {
case IYY: case IYY:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_THREE_DIGITS, params, formatTokenEnum); PATTERN_THREE_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
// Gregorian calendar does not have a year 0. // Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust // 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1); result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1);
...@@ -92,7 +156,7 @@ class ToDateTokenizer { ...@@ -92,7 +156,7 @@ class ToDateTokenizer {
case RRRR: case RRRR:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS, params, formatTokenEnum); PATTERN_TWO_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
dateNr += dateNr < 50 ? 2000 : 1900; dateNr += dateNr < 50 ? 2000 : 1900;
result.set(Calendar.YEAR, dateNr); result.set(Calendar.YEAR, dateNr);
break; break;
...@@ -101,7 +165,7 @@ class ToDateTokenizer { ...@@ -101,7 +165,7 @@ class ToDateTokenizer {
int cc = calendar.get(Calendar.YEAR) / 100; int cc = calendar.get(Calendar.YEAR) / 100;
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS, params, formatTokenEnum); PATTERN_TWO_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr) + cc * 100; dateNr = Integer.parseInt(inputFragmentStr) + cc * 100;
result.set(Calendar.YEAR, dateNr); result.set(Calendar.YEAR, dateNr);
break; break;
case EE /*NOT supported yet*/: case EE /*NOT supported yet*/:
...@@ -116,7 +180,7 @@ class ToDateTokenizer { ...@@ -116,7 +180,7 @@ class ToDateTokenizer {
case IY: case IY:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS, params, formatTokenEnum); PATTERN_TWO_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
// Gregorian calendar does not have a year 0. // Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust // 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1); result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1);
...@@ -125,14 +189,14 @@ class ToDateTokenizer { ...@@ -125,14 +189,14 @@ class ToDateTokenizer {
case CC: case CC:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS, params, formatTokenEnum); PATTERN_TWO_DIGITS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr) * 100; dateNr = Integer.parseInt(inputFragmentStr) * 100;
result.set(Calendar.YEAR, dateNr); result.set(Calendar.YEAR, dateNr);
break; break;
case Y: case Y:
case I: case I:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_ONE_DIGIT, params, formatTokenEnum); PATTERN_ONE_DIGIT, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
// Gregorian calendar does not have a year 0. // Gregorian calendar does not have a year 0.
// 0 = 0001 BC, -1 = 0002 BC, ... so we adjust // 0 = 0001 BC, -1 = 0002 BC, ... so we adjust
result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1); result.set(Calendar.YEAR, dateNr >= 0 ? dateNr : dateNr + 1);
...@@ -186,7 +250,7 @@ class ToDateTokenizer { ...@@ -186,7 +250,7 @@ class ToDateTokenizer {
// Note: In Calendar Month go from 0 - 11 // Note: In Calendar Month go from 0 - 11
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.MONTH, dateNr - 1); result.set(Calendar.MONTH, dateNr - 1);
break; break;
case RM: case RM:
...@@ -231,19 +295,19 @@ class ToDateTokenizer { ...@@ -231,19 +295,19 @@ class ToDateTokenizer {
case DDD: case DDD:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_NUMBER, params, formatTokenEnum); PATTERN_NUMBER, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.DAY_OF_YEAR, dateNr); result.set(Calendar.DAY_OF_YEAR, dateNr);
break; break;
case DD: case DD:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.DAY_OF_MONTH, dateNr); result.set(Calendar.DAY_OF_MONTH, dateNr);
break; break;
case D: case D:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_ONE_DIGIT, params, formatTokenEnum); PATTERN_ONE_DIGIT, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.DAY_OF_MONTH, dateNr); result.set(Calendar.DAY_OF_MONTH, dateNr);
break; break;
case DAY: case DAY:
...@@ -289,32 +353,32 @@ class ToDateTokenizer { ...@@ -289,32 +353,32 @@ class ToDateTokenizer {
case HH24: case HH24:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.HOUR_OF_DAY, dateNr); result.set(Calendar.HOUR_OF_DAY, dateNr);
break; break;
case HH12: case HH12:
case HH: case HH:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.HOUR, dateNr); result.set(Calendar.HOUR, dateNr);
break; break;
case MI: case MI:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.MINUTE, dateNr); result.set(Calendar.MINUTE, dateNr);
break; break;
case SS: case SS:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.SECOND, dateNr); result.set(Calendar.SECOND, dateNr);
break; break;
case SSSSS: case SSSSS:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_NUMBER, params, formatTokenEnum); PATTERN_NUMBER, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
result.set(Calendar.HOUR_OF_DAY, 0); result.set(Calendar.HOUR_OF_DAY, 0);
result.set(Calendar.MINUTE, 0); result.set(Calendar.MINUTE, 0);
result.set(Calendar.SECOND, dateNr); result.set(Calendar.SECOND, dateNr);
...@@ -341,7 +405,7 @@ class ToDateTokenizer { ...@@ -341,7 +405,7 @@ class ToDateTokenizer {
case TZH: case TZH:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
TimeZone tz = result.getTimeZone(); TimeZone tz = result.getTimeZone();
int offsetMillis = tz.getRawOffset(); int offsetMillis = tz.getRawOffset();
// purge min and sec // purge min and sec
...@@ -352,7 +416,7 @@ class ToDateTokenizer { ...@@ -352,7 +416,7 @@ class ToDateTokenizer {
case TZM: case TZM:
inputFragmentStr = matchStringOrThrow( inputFragmentStr = matchStringOrThrow(
PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum); PATTERN_TWO_DIGITS_OR_LESS, params, formatTokenEnum);
dateNr = parseInt(inputFragmentStr); dateNr = Integer.parseInt(inputFragmentStr);
tz = result.getTimeZone(); tz = result.getTimeZone();
offsetMillis = tz.getRawOffset(); offsetMillis = tz.getRawOffset();
// purge hour // purge hour
...@@ -390,16 +454,14 @@ class ToDateTokenizer { ...@@ -390,16 +454,14 @@ class ToDateTokenizer {
} }
} }
static int parseInt(String s) { /**
int result = 0; * Match the pattern, or if not possible throw an exception.
if (s.length() > 0 && s.charAt(0) == '+') { *
result = Integer.parseInt(s.substring(1)); * @param p the pattern
} else { * @param params the parameters with the input string
result = Integer.parseInt(s); * @param aEnum the pattern name
} * @return the matched value
return result; */
}
static String matchStringOrThrow(Pattern p, ToDateParser params, Enum<?> aEnum) { static String matchStringOrThrow(Pattern p, ToDateParser params, Enum<?> aEnum) {
String s = params.getInputStr(); String s = params.getInputStr();
Matcher matcher = p.matcher(s); Matcher matcher = p.matcher(s);
...@@ -409,6 +471,15 @@ class ToDateTokenizer { ...@@ -409,6 +471,15 @@ class ToDateTokenizer {
return matcher.group(1); return matcher.group(1);
} }
/**
* Set the given field in the calendar.
*
* @param c the calendar
* @param params the parameters with the input string
* @param field the field to set
* @param style the data type
* @return the matched value
*/
static String setByName(Calendar c, ToDateParser params, int field, int style) { static String setByName(Calendar c, ToDateParser params, int field, int style) {
String inputFragmentStr = null; String inputFragmentStr = null;
String s = params.getInputStr(); String s = params.getInputStr();
...@@ -430,6 +501,12 @@ class ToDateTokenizer { ...@@ -430,6 +501,12 @@ class ToDateTokenizer {
return inputFragmentStr; return inputFragmentStr;
} }
/**
* Throw a parse exception.
*
* @param params the parameters with the input string
* @param errorStr the error string
*/
static void throwException(ToDateParser params, String errorStr) { static void throwException(ToDateParser params, String errorStr) {
throw DbException.get( throw DbException.get(
ErrorCode.INVALID_TO_DATE_FORMAT, ErrorCode.INVALID_TO_DATE_FORMAT,
...@@ -440,7 +517,7 @@ class ToDateTokenizer { ...@@ -440,7 +517,7 @@ class ToDateTokenizer {
/** /**
* The format tokens. * The format tokens.
*/ */
static enum FormatTokenEnum { public static enum FormatTokenEnum {
// 4-digit year // 4-digit year
YYYY(PARSLET_YEAR), YYYY(PARSLET_YEAR),
// 4-digit year with sign (- = B.C.) // 4-digit year with sign (- = B.C.)
...@@ -525,11 +602,22 @@ class ToDateTokenizer { ...@@ -525,11 +602,22 @@ class ToDateTokenizer {
private final ToDateParslet toDateParslet; private final ToDateParslet toDateParslet;
private final Pattern patternToUse; private final Pattern patternToUse;
/**
* Construct a format token.
*
* @param toDateParslet the date parslet
* @param patternToUse the pattern
*/
FormatTokenEnum(ToDateParslet toDateParslet, Pattern patternToUse) { FormatTokenEnum(ToDateParslet toDateParslet, Pattern patternToUse) {
this.toDateParslet = toDateParslet; this.toDateParslet = toDateParslet;
this.patternToUse = patternToUse; this.patternToUse = patternToUse;
} }
/**
* Construct a format token.
*
* @param toDateParslet the date parslet
*/
FormatTokenEnum(ToDateParslet toDateParslet) { FormatTokenEnum(ToDateParslet toDateParslet) {
this.toDateParslet = toDateParslet; this.toDateParslet = toDateParslet;
patternToUse = Pattern.compile(format("^(%s)", name()), Pattern.CASE_INSENSITIVE); patternToUse = Pattern.compile(format("^(%s)", name()), Pattern.CASE_INSENSITIVE);
...@@ -539,6 +627,9 @@ class ToDateTokenizer { ...@@ -539,6 +627,9 @@ class ToDateTokenizer {
* Optimization: Only return a list of {@link FormatTokenEnum} that * Optimization: Only return a list of {@link FormatTokenEnum} that
* share the same 1st char using the 1st char of the 'to parse' * share the same 1st char using the 1st char of the 'to parse'
* formatStr. Or return empty list if no match. * formatStr. Or return empty list if no match.
*
* @param formatStr the format string
* @return the list of tokens
*/ */
static List<FormatTokenEnum> getTokensInQuestion(String formatStr) { static List<FormatTokenEnum> getTokensInQuestion(String formatStr) {
List<FormatTokenEnum> result = EMPTY_LIST; List<FormatTokenEnum> result = EMPTY_LIST;
...@@ -586,6 +677,9 @@ class ToDateTokenizer { ...@@ -586,6 +677,9 @@ class ToDateTokenizer {
/** /**
* Parse the format-string with passed token of {@link FormatTokenEnum}. * Parse the format-string with passed token of {@link FormatTokenEnum}.
* If token matches return true, otherwise false. * If token matches return true, otherwise false.
*
* @param params the parameters
* @return true if it matches
*/ */
boolean parseFormatStrWithToken(ToDateParser params) { boolean parseFormatStrWithToken(ToDateParser params) {
Matcher matcher = patternToUse.matcher(params.getFormatStr()); Matcher matcher = patternToUse.matcher(params.getFormatStr());
......
...@@ -96,7 +96,9 @@ public final class ValueTimestampUtc extends Value { ...@@ -96,7 +96,9 @@ public final class ValueTimestampUtc extends Value {
/** /**
* Time in nanoseconds since 1 Jan 1970 i.e. similar format to * Time in nanoseconds since 1 Jan 1970 i.e. similar format to
* System.currentTimeMillis() * System.currentTimeMillis().
*
* @return the number of milliseconds
*/ */
public long getUtcDateTimeNanos() { public long getUtcDateTimeNanos() {
return utcDateTimeNanos; return utcDateTimeNanos;
...@@ -105,11 +107,18 @@ public final class ValueTimestampUtc extends Value { ...@@ -105,11 +107,18 @@ public final class ValueTimestampUtc extends Value {
/** /**
* Time in milliseconds since 1 Jan 1970 i.e. same format as * Time in milliseconds since 1 Jan 1970 i.e. same format as
* System.currentTimeMillis() * System.currentTimeMillis()
*
* @return the number of milliseconds
*/ */
public long getUtcDateTimeMillis() { public long getUtcDateTimeMillis() {
return utcDateTimeNanos / 1000 / 1000; return utcDateTimeNanos / 1000 / 1000;
} }
/**
* Get the number of nanoseconds since the last full millisecond.
*
* @return the number of nanoseconds
*/
int getNanosSinceLastMillis() { int getNanosSinceLastMillis() {
return (int) (utcDateTimeNanos % (1000 * 1000)); return (int) (utcDateTimeNanos % (1000 * 1000));
} }
......
...@@ -21,6 +21,9 @@ import javax.tools.Diagnostic; ...@@ -21,6 +21,9 @@ import javax.tools.Diagnostic;
*/ */
public class TestAnnotationProcessor extends AbstractProcessor { public class TestAnnotationProcessor extends AbstractProcessor {
/**
* The message key.
*/
public static final String MESSAGES_KEY = public static final String MESSAGES_KEY =
TestAnnotationProcessor.class.getName() + "-messages"; TestAnnotationProcessor.class.getName() + "-messages";
......
...@@ -1414,23 +1414,31 @@ public class TestFunctions extends TestBase implements AggregateFunction { ...@@ -1414,23 +1414,31 @@ public class TestFunctions extends TestBase implements AggregateFunction {
Timestamp expected; Timestamp expected;
// 01-Aug-03 + 3 months = 01-Nov-03 // 01-Aug-03 + 3 months = 01-Nov-03
date = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-01").getTime()); date = new Timestamp(
expected = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-11-01").getTime()); new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-01").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-11-01").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 3)); assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 3));
// 31-Jan-03 + 1 month = 28-Feb-2003 // 31-Jan-03 + 1 month = 28-Feb-2003
date = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-01-31").getTime()); date = new Timestamp(
expected = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-02-28").getTime()); new SimpleDateFormat("yyyy-MM-dd").parse("2003-01-31").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-02-28").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 1)); assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), 1));
// 21-Aug-2003 - 3 months = 21-May-2003 // 21-Aug-2003 - 3 months = 21-May-2003
date = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-21").getTime()); date = new Timestamp(
expected = new Timestamp(new SimpleDateFormat("yyyy-MM-dd").parse("2003-05-21").getTime()); new SimpleDateFormat("yyyy-MM-dd").parse("2003-08-21").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd").parse("2003-05-21").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3)); assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3));
// 21-Aug-2003 00:00:00:333 - 3 months = 21-May-2003 00:00:00:333 // 21-Aug-2003 00:00:00:333 - 3 months = 21-May-2003 00:00:00:333
date = new Timestamp(new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-08-21 333").getTime()); date = new Timestamp(
expected = new Timestamp(new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-05-21 333").getTime()); new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-08-21 333").getTime());
expected = new Timestamp(
new SimpleDateFormat("yyyy-MM-dd SSS").parse("2003-05-21 333").getTime());
assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3)); assertEquals(expected, DateTimeUtils.addMonths(new Timestamp(date.getTime()), -3));
} }
......
...@@ -49,6 +49,9 @@ public class TestRowFactory extends TestBase { ...@@ -49,6 +49,9 @@ public class TestRowFactory extends TestBase {
*/ */
public static class MyTestRowFactory extends RowFactory { public static class MyTestRowFactory extends RowFactory {
/**
* A simple counter.
*/
static final AtomicInteger COUNTER = new AtomicInteger(); static final AtomicInteger COUNTER = new AtomicInteger();
@Override @Override
......
...@@ -684,6 +684,12 @@ public class TestTableEngines extends TestBase { ...@@ -684,6 +684,12 @@ public class TestTableEngines extends TestBase {
} }
} }
/**
* A static assertion method.
*
* @param condition the condition
* @param message the error message
*/
static void assert0(boolean condition, String message) { static void assert0(boolean condition, String message) {
if (!condition) { if (!condition) {
throw new AssertionError(message); throw new AssertionError(message);
......
...@@ -52,7 +52,7 @@ public class TestView extends TestBase { ...@@ -52,7 +52,7 @@ public class TestView extends TestBase {
deleteDb("view"); deleteDb("view");
} }
public void testSubQueryViewIndexCache() throws SQLException { private void testSubQueryViewIndexCache() throws SQLException {
if (config.networked) { if (config.networked) {
return; return;
} }
......
...@@ -1055,7 +1055,8 @@ public class TestPreparedStatement extends TestBase { ...@@ -1055,7 +1055,8 @@ public class TestPreparedStatement extends TestBase {
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE SEQUENCE SEQ"); stat.execute("CREATE SEQUENCE SEQ");
stat.execute("CREATE TABLE TEST(ID INT)"); stat.execute("CREATE TABLE TEST(ID INT)");
PreparedStatement prep = conn.prepareStatement("INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)"); PreparedStatement prep = conn.prepareStatement(
"INSERT INTO TEST VALUES(NEXT VALUE FOR SEQ)");
prep.addBatch(); prep.addBatch();
prep.addBatch(); prep.addBatch();
prep.addBatch(); prep.addBatch();
......
...@@ -122,6 +122,12 @@ public class TestMvcc4 extends TestBase { ...@@ -122,6 +122,12 @@ public class TestMvcc4 extends TestBase {
setup.close(); setup.close();
} }
/**
* Wait for the given thread to block on synchronizing on the database
* object.
*
* @param t the thread
*/
static void waitForThreadToBlockOnDB(Thread t) { static void waitForThreadToBlockOnDB(Thread t) {
while (true) { while (true) {
// TODO must not use getAllStackTraces, as the method names are // TODO must not use getAllStackTraces, as the method names are
......
...@@ -783,3 +783,4 @@ diagnostic filer stamp turn going cancellation fetched produced incurring ...@@ -783,3 +783,4 @@ diagnostic filer stamp turn going cancellation fetched produced incurring
interpreter batching fewer runners imperial correspond nine purge meridian interpreter batching fewer runners imperial correspond nine purge meridian
calendars moscow messager lookups unhandled buddha parslet calendars moscow messager lookups unhandled buddha parslet
tzh roc xii tzm viii myydd mar vii tzh roc xii tzm viii myydd mar vii
cristan branda fabien adam bio gomes mahon steven aug meijer lisboa todescato
...@@ -484,7 +484,8 @@ public class Doclet { ...@@ -484,7 +484,8 @@ public class Doclet {
&& method.parameters().length == 0 && method.parameters().length == 0
&& returnType != null && returnType != null
&& returnType.toString().equals("boolean"); && returnType.toString().equals("boolean");
if (!setterOrGetter) { boolean enumValueMethod = name.equals("values") || name.equals("valueOf");
if (!setterOrGetter && !enumValueMethod) {
addError("Undocumented method " + " (" addError("Undocumented method " + " ("
+ getLink(clazz, method.position().line()) + ") " + getLink(clazz, method.position().line()) + ") "
+ clazz + "." + name + " " + raw); + clazz + "." + name + " " + raw);
......
...@@ -530,7 +530,7 @@ public class ArchiveTool { ...@@ -530,7 +530,7 @@ public class ArchiveTool {
dataOut.flush(); dataOut.flush();
} }
static long openSegments(List<Long> segmentStart, TreeSet<ChunkStream> segmentIn, private static long openSegments(List<Long> segmentStart, TreeSet<ChunkStream> segmentIn,
String tempFileName, boolean readKey) throws IOException { String tempFileName, boolean readKey) throws IOException {
long inPos = 0; long inPos = 0;
int bufferTotal = 64 * 1024 * 1024; int bufferTotal = 64 * 1024 * 1024;
...@@ -549,7 +549,7 @@ public class ArchiveTool { ...@@ -549,7 +549,7 @@ public class ArchiveTool {
return inPos; return inPos;
} }
static Iterator<Chunk> merge(final TreeSet<ChunkStream> segmentIn, final Log log) { private static Iterator<Chunk> merge(final TreeSet<ChunkStream> segmentIn, final Log log) {
return new Iterator<Chunk>() { return new Iterator<Chunk>() {
@Override @Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论