Package me.ahoo.cosid.store.jdbc
Class JdbcStore
java.lang.Object
me.ahoo.cosid.store.jdbc.JdbcStore
- All Implemented Interfaces:
AutoCloseable,me.ahoo.cosid.store.Store
The JDBC store (06-stores.md ยง2.1): ranges and slot leases over a
DataSource, which should be pooled. Every
statement carries the store timeout as its queryTimeout. Closing the store does not close the data source.
The tables are those of the dialect's schema-*.sql; initSchema() creates them when missing, and
adds cosid_namespace.slot_offset to a table of 5.0.0-alpha.1. Without it, such a table still serves
namespaces of slot offset 0.
-
Constructor Summary
ConstructorsConstructorDescriptionJdbcStore(DataSource dataSource, JdbcDialect dialect, JdbcTables tables, Duration timeout) A store on a database of the given dialect.JdbcStore(DataSource dataSource, JdbcDialect dialect, JdbcTables tables, Duration timeout, FetchPlan fetchPlan) A store on a database of the given dialect, reserving ranges with the given plan. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMissingIndex(Connection connection, JdbcDialect dialect, JdbcTables tables) Adds the slot table's index on(namespace, last_owner_key)(R1-jdbc-01) when the table lacks it, as a table of 5.0.0-alpha.1 does;initSchemaruns it, and so does the migration tool on its target.voidclose()dialect()The dialect of the database.voidCreates the tables that do not exist (options.initSchema); existing tables are left as they are, except that acosid_namespaceof 5.0.0-alpha.1 gets theslot_offsetcolumn it lacks (JdbcDialect.addColumn(java.lang.String, java.lang.String, java.lang.String); its rows read 0, the column default).static JdbcStoreof(DataSource dataSource, Duration timeout) A store on the default tables, with the dialect detected from the database (JdbcDialects.detect(java.sql.Connection, java.lang.ClassLoader)).me.ahoo.cosid.segment.RangeStoreranges()me.ahoo.cosid.lease.SlotLeaseStoreslots()tables()The table names.
-
Constructor Details
-
JdbcStore
A store on a database of the given dialect.- Parameters:
dataSource- the data sourcedialect- the dialect of its databasetables- the table namestimeout- the timeout of each statement, rounded up to seconds; positive
-
JdbcStore
public JdbcStore(DataSource dataSource, JdbcDialect dialect, JdbcTables tables, Duration timeout, FetchPlan fetchPlan) A store on a database of the given dialect, reserving ranges with the given plan.- Parameters:
dataSource- the data sourcedialect- the dialect of its databasetables- the table namestimeout- the timeout of each statement, rounded up to seconds; positivefetchPlan- how a reserve reads the value it wrote (options.fetchPlan, R1-jdbc-06)
-
-
Method Details
-
of
A store on the default tables, with the dialect detected from the database (JdbcDialects.detect(java.sql.Connection, java.lang.ClassLoader)).- Parameters:
dataSource- the data sourcetimeout- the timeout of each statement; positive- Returns:
- the store
- Throws:
JdbcStoreException- if the database cannot be reachedIllegalArgumentException- if no dialect supports the database
-
dialect
The dialect of the database.- Returns:
- the dialect
-
tables
The table names.- Returns:
- the table names
-
initSchema
public void initSchema()Creates the tables that do not exist (options.initSchema); existing tables are left as they are, except that acosid_namespaceof 5.0.0-alpha.1 gets theslot_offsetcolumn it lacks (JdbcDialect.addColumn(java.lang.String, java.lang.String, java.lang.String); its rows read 0, the column default).- Throws:
JdbcStoreException- if a statement fails
-
addMissingIndex
public static void addMissingIndex(Connection connection, JdbcDialect dialect, JdbcTables tables) throws SQLException Adds the slot table's index on(namespace, last_owner_key)(R1-jdbc-01) when the table lacks it, as a table of 5.0.0-alpha.1 does;initSchemaruns it, and so does the migration tool on its target. Idempotent: when a concurrent caller created the index first, the failure is ignored.- Parameters:
connection- a connection that may create indexesdialect- the dialecttables- the tables- Throws:
SQLException- if creating the index fails and it still does not exist
-
ranges
public me.ahoo.cosid.segment.RangeStore ranges()- Specified by:
rangesin interfaceme.ahoo.cosid.store.Store
-
slots
public me.ahoo.cosid.lease.SlotLeaseStore slots()- Specified by:
slotsin interfaceme.ahoo.cosid.store.Store
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceme.ahoo.cosid.store.Store
-