Interface CatalogStoreFactory
- All Superinterfaces:
Factory
Factory for more information.
This factory is specifically designed for the Flink SQL gateway scenario, where different catalog stores need to be created for different sessions.
If the CatalogStore is implemented using JDBC, this factory can be used to create a JDBC connection pool in the open method. This connection pool can then be reused for subsequent catalog store creations.
The following examples implementation of CatalogStoreFactory using jdbc.
public class JdbcCatalogStore implements CatalogStore {
private JdbcConnectionPool jdbcConnectionPool;
public JdbcCatalogStore(JdbcConnectionPool jdbcConnectionPool) {
this.jdbcConnectionPool = jdbcConnectionPool;
}
...
}
public class JdbcCatalogStoreFactory implements CatalogStoreFactory {
private JdbcConnectionPool jdbcConnectionPool;
@Override
public CatalogStore createCatalogStore(Context context) {
return new JdbcCatalogStore(jdbcConnectionPool);
}
@Override
public void open(Context context) throws CatalogException {
// initialize the thread pool using options from context
jdbcConnectionPool = initializeJdbcConnectionPool(context);
}
@Override
public void close() {
// release the connection thread pool.
releaseConnectionPool(jdbcConnectionPool);
}
...
}
The usage of the Flink SQL gateway is as follows. It's just an example and may not be the final implementation.
// initialize CatalogStoreFactory when initialize the SessionManager
public class SessionManagerImpl implements SessionManager {
public SessionManagerImpl(DefaultContext defaultContext) {
this.catalogStoreFactory = createCatalogStore();
}
@Override
public void start() {
// initialize the CatalogStoreFactory
this.catalogStoreFactory(buildCatalogStoreContext());
}
@Override
public synchronized Session openSession(SessionEnvironment environment) {
// Create a new catalog store for this session.
CatalogStore catalogStore = this.catalogStoreFactory.createCatalogStore(buildCatalogStoreContext());
// Create a new CatalogManager using catalog store.
}
@Override
public void stop() {
// Close the CatalogStoreFactory when stopping the SessionManager.
this.catalogStoreFactory.close();
}
}
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceContext provided when a catalog store is created. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the CatalogStoreFactory.Creates aCatalogStoreinstance from context information.voidopen(CatalogStoreFactory.Context context) Initialize the CatalogStoreFactory.Methods inherited from interface org.apache.flink.table.factories.Factory
factoryIdentifier, optionalOptions, requiredOptions
-
Method Details
-
createCatalogStore
CatalogStore createCatalogStore()Creates aCatalogStoreinstance from context information. -
open
Initialize the CatalogStoreFactory.For the use case of Flink SQL gateway, the open method will be called when starting SessionManager. It initializes common resources, such as a connection pool, for various catalog stores.
- Throws:
CatalogException
-
close
Close the CatalogStoreFactory.For the use case of Flink SQL gateway, the close method will be called when closing SessionManager. It releases common resources, such as connection pool, after closing all catalog stores.
- Throws:
CatalogException
-