Package com.google.cloud.spanner.watcher
Enum TimebasedShardProvider.Interval
- java.lang.Object
-
- java.lang.Enum<TimebasedShardProvider.Interval>
-
- com.google.cloud.spanner.watcher.TimebasedShardProvider.Interval
-
- All Implemented Interfaces:
Serializable,Comparable<TimebasedShardProvider.Interval>
- Enclosing class:
- TimebasedShardProvider
public static enum TimebasedShardProvider.Interval extends Enum<TimebasedShardProvider.Interval>
-
-
Enum Constant Summary
Enum Constants Enum Constant Description DAYCreates a shard for each unique date.DAY_OF_MONTHCreates a cyclic shard for each day of month (1-31).DAY_OF_WEEKCreates a cyclic shard for each weekday (1-7).DAY_OF_YEARCreates a cyclic shard for each day of year (1-366).HOUR_OF_DAYCreates a cyclic shard for each hour of a day (0-23).MINUTE_OF_HOURMINUTE_OF_HOURis mainly intended for testing purposes.MONTHCreates a shard for each month and year.WEEKCreates a shard for each week and year.WEEK_OF_YEARCreates a cyclic shard for each week of year (1-53).YEARCreates a shard for each year.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description TimebasedShardProvider.TimebasedShardIdgetCurrentShardId(com.google.cloud.spanner.ReadContext readContext)Fetches the current shard id from the database.StringgetShardIdExpression()Returns the SQL expression that calculates the current shard id.booleanisCyclic()Returns true if this interval is cyclic, i.e.static TimebasedShardProvider.IntervalvalueOf(String name)Returns the enum constant of this type with the specified name.static TimebasedShardProvider.Interval[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
-
-
Enum Constant Detail
-
DAY
public static final TimebasedShardProvider.Interval DAY
Creates a shard for each unique date.
-
WEEK
public static final TimebasedShardProvider.Interval WEEK
Creates a shard for each week and year.
-
MONTH
public static final TimebasedShardProvider.Interval MONTH
Creates a shard for each month and year.
-
YEAR
public static final TimebasedShardProvider.Interval YEAR
Creates a shard for each year.
-
MINUTE_OF_HOUR
public static final TimebasedShardProvider.Interval MINUTE_OF_HOUR
MINUTE_OF_HOURis mainly intended for testing purposes. Creates a cyclic shard for each minute of an hour (0-59). UsingMINUTE_OF_HOURmeans that the shard value will change very frequently, and transactions that run longer than 1 minute will potentially receive the wrong shard value.
-
HOUR_OF_DAY
public static final TimebasedShardProvider.Interval HOUR_OF_DAY
Creates a cyclic shard for each hour of a day (0-23).
-
DAY_OF_WEEK
public static final TimebasedShardProvider.Interval DAY_OF_WEEK
Creates a cyclic shard for each weekday (1-7).
-
DAY_OF_MONTH
public static final TimebasedShardProvider.Interval DAY_OF_MONTH
Creates a cyclic shard for each day of month (1-31).
-
WEEK_OF_YEAR
public static final TimebasedShardProvider.Interval WEEK_OF_YEAR
Creates a cyclic shard for each week of year (1-53).
-
DAY_OF_YEAR
public static final TimebasedShardProvider.Interval DAY_OF_YEAR
Creates a cyclic shard for each day of year (1-366).
-
-
Method Detail
-
values
public static TimebasedShardProvider.Interval[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (TimebasedShardProvider.Interval c : TimebasedShardProvider.Interval.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static TimebasedShardProvider.Interval valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
getCurrentShardId
public TimebasedShardProvider.TimebasedShardId getCurrentShardId(com.google.cloud.spanner.ReadContext readContext)
Fetches the current shard id from the database. It is the responsibility of all clients that write data to tables that are being watched that the correct shard id is written to the table. Failure to do so will cause the change to be missed by Spanner Change Watchers. The shard id will remain constant during the complete interval that has been chosen. It is therefore possible for clients to cache the current shard id value, as long as the client renews the shard id once the interval has passed. The shard is calculated in UTC, which means that for example a shard id based onDAYwill change at the moment that the current system time in UTC changes 23:59 to 00:00.
-
getShardIdExpression
public String getShardIdExpression()
Returns the SQL expression that calculates the current shard id. This expression can be included in DML statements to automatically set the current shard id. SeeSamples#watchTableWithTimebasedShardProviderExample(String, String, String, String)for an example on how to use this.
-
isCyclic
public boolean isCyclic()
Returns true if this interval is cyclic, i.e. the same shard id will be generated at later moment again.DAY_OF_WEEK,DAY_OF_MONTHandDAY_OF_YEARare examples of cyclic intervals.
-
-