Class ServiceSessionControl
- All Implemented Interfaces:
AutoCloseable
- Since:
- 3.4
- Author:
- nicklas
-
Nested Class Summary
Modifier and TypeClassDescription(package private) static class
Flushes the given session before the transaction is committed.(package private) static class
Our own keyring containing the only permission:Permission.ACT_AS_ANOTHER_USER
.class
Used for creating a configuration that is the basis for building a session factory.Nested classes/interfaces inherited from class net.sf.basedb.core.SessionControl
SessionControl.MainContext, SessionControl.UnverifiedDeviceInfo
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionCreate a session factory for the given configuration.createSessionFactoryConfiguration
(String appId, String schema, int schemaVersion, ClassLoader classLoader) Create an object that can be used for collecting configuration options and other settings that are needed to create session factories for services.(package private) String
newSession
(SessionBuilder<?> builder, DbControl dc) Create a new Hibernate session for the given session factory that is piggy-backed on the given DbControl transaction.(package private) boolean
schemaExists
(String catalog, String schema) Methods inherited from class net.sf.basedb.core.SessionControl
clearDbControlCache, close, deleteContext, deleteCurrentContexts, getActiveProjectId, getActiveProjectName, getActiveProjectPermissions, getActiveRoles, getAllCurrentContexts, getAllPermissions, getAllPermissions, getAllRoles, getAuthenticationMethod, getClientDefaultSetting, getClientId, getClientName, getContext, getContextNames, getContextNames, getCurrentClientId, getCurrentClientName, getCurrentContext, getCurrentContext, getCurrentContext, getCurrentContext, getCurrentExternalClientId, getCurrentSessionId, getCurrentSubcontext, getDefaultTransactionName, getDeviceId, getDeviceName, getExternalClientId, getFriends, getGroups, getId, getInactiveRoles, getItemKeyId, getItemKeys, getItemKeys, getJobId, getJobName, getJobSessionControl, getLastAccess, getLocale, getLocation, getLoggedInUserId, getLoggedInUserLogin, getLoggedInUserName, getNamedContexts, getPluginId, getPluginName, getPluginPermissions, getPluginSessionControl, getProjectKeyId, getProjectKeys, getProjectKeys, getProjectPermission, getProjects, getRemoteId, getRolePermissions, getRoles, getSessionSetting, getSharedPermissions, getUnverifiedDeviceInfo, getUserClientSetting, getUserDefaultSetting, hasPermission, hasSystemPermission, impersonateLogin, impersonateLogin, isAllowedToUseClient, isClosed, isDenied, isFriendOf, isImpersonated, isLoggedIn, isMemberOf, isMemberOf, isMemberOf, isRoleInactive, loadContext, loadContext, login, login, logout, newDbControl, newDbControl, reloadPermissions, reloadSettings, saveCurrentContextAs, saveCurrentContextAs, setActiveProject, setCurrentClient, setCurrentSubcontext, setRoleInactive, setSessionSetting, setUserClientSetting, setUserDefaultSetting, updateLastAccess, verifyDevice, verifyUserInternal
-
Field Details
-
log
-
-
Constructor Details
-
ServiceSessionControl
ServiceSessionControl()
-
-
Method Details
-
createSessionFactoryConfiguration
public ServiceSessionControl.SessionFactoryConfiguration createSessionFactoryConfiguration(String appId, String schema, int schemaVersion, ClassLoader classLoader) Create an object that can be used for collecting configuration options and other settings that are needed to create session factories for services.An application id, schema and schema version is required. This information is used by BASE to check the currently installed schema version and only update the database if there is a change. Note that the schema version must always increase from one version to the next.
A class loader is needed so that Hibernate can load the classes from extension classes.
It is possible to use
ServiceSessionControl.SessionFactoryConfiguration.getInstallMode()
andServiceSessionControl.SessionFactoryConfiguration.getInstalledSchemaVersion()
to check the current status of the database.Use
ServiceSessionControl.SessionFactoryConfiguration.getRegistryBuilder()
to get a Hibernate object for setting things that are typically configured inhibernate.cfg.xml
. Typically,StandardServiceRegistryBuilder.applySetting(String, Object)
is the main method to use for this.Use
ServiceSessionControl.SessionFactoryConfiguration.getMetadataSources()
to get a Hibernate object for adding mapped entity classes. Typically,MetadataSources.addAnnotatedClass(Class)
is the main method to use for this. Note that once the metadata sources object has been created it is not possible to modify the registry settings.Also note that by default the configured session factory need to be "piggy-backed" on a BASE
DbControl
transaction. Create Hibernate sessions withnewSession(org.hibernate.SessionBuilder, DbControl)
.If you want to use connections/transactions that are independent from BASE call
ServiceSessionControl.SessionFactoryConfiguration.setUseSeparateConnections(boolean)
but make sure you also get connection pooling configured. You can still use "piggy-backed" connections.- Parameters:
appId
- The ID of the extensions (which should be unique)schema
- The schema name the extension wants to use for it's database tablesschemaVersion
- The version of the current schema. If this is different from the database scheme it will automatically be updated whenbuildSessionFactory(SessionFactoryConfiguration)
is called.classLoader
- A class loader is needed for Hibernate to be able to locate the classes. Use the classloader returned fromClass.getClassLoader()
using the class from one of the classes in the extension
-
getCatalog
String getCatalog() -
schemaExists
-
buildSessionFactory
Create a session factory for the given configuration. This method will add connection information from the base.config file automatically to the configuration object. Note that sessions can't Classes that have been defined in the configuration should be without a schema definition and will then be put into the specified schema automatically. If the given schema and tables doesn't exists they will be created automatically, otherwise an UPDATE action is performed to modify an existing installation.- Parameters:
config
- A configuration instance containing information needed to build the session factory- Returns:
- A session factory instance
-
newSession
Create a new Hibernate session for the given session factory that is piggy-backed on the given DbControl transaction. Note that the life-cycle of the returned session is managed by the DbControl. There is no need to flush or close the session since this is done automatically and may cause exceptions if done when not needed.- Parameters:
builder
- A session builder (eg. SessionFactory.withOptions())dc
- An open DbControl
-