@SuppressWarnings({"unchecked", "UnusedParameters"}) private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) { final Properties properties = activationContext.getConfiguration().getProperties(); if ( ! ConfigurationHelper.getBoolean( BeanValidationIntegrator.APPLY_CONSTRAINTS, properties, true ) ){ LOG.debug( "Skipping application of relational constraints from legacy Hibernate Validator" ); return; } final Set<ValidationMode> modes = activationContext.getValidationModes(); if ( ! ( modes.contains( ValidationMode.DDL ) || modes.contains( ValidationMode.AUTO ) ) ) { return; } applyRelationalConstraints( factory, activationContext.getConfiguration().createMappings().getClasses().values(), properties, activationContext.getServiceRegistry().getService( JdbcServices.class ).getDialect() ); }
public SchemaExport(ServiceRegistry serviceRegistry, Configuration configuration) { this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( serviceRegistry.getService( ConnectionProvider.class ) ); this.sqlStatementLogger = serviceRegistry.getService( JdbcServices.class ).getSqlStatementLogger(); this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); this.sqlExceptionHelper = serviceRegistry.getService( JdbcServices.class ).getSqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, configuration.getProperties(), DEFAULT_IMPORT_FILE ); final Dialect dialect = serviceRegistry.getService( JdbcServices.class ).getDialect(); this.dropSQL = configuration.generateDropSchemaScript( dialect ); this.createSQL = configuration.generateSchemaCreationScript( dialect ); }
public SchemaExport(MetadataImplementor metadata) { ServiceRegistry serviceRegistry = metadata.getServiceRegistry(); this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( serviceRegistry.getService( ConnectionProvider.class ) ); JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); this.sqlStatementLogger = jdbcServices.getSqlStatementLogger(); this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper(); this.importFiles = ConfigurationHelper.getString( AvailableSettings.HBM2DDL_IMPORT_FILES, serviceRegistry.getService( ConfigurationService.class ).getSettings(), DEFAULT_IMPORT_FILE ); final Dialect dialect = jdbcServices.getDialect(); this.dropSQL = metadata.getDatabase().generateDropSchemaScript( dialect ); this.createSQL = metadata.getDatabase().generateSchemaCreationScript( dialect ); }
/** * Constructs a LogicalConnectionImpl * * @param userSuppliedConnection The user-supplied connection * @param connectionReleaseMode The connection release mode to use * @param jdbcServices JdbcServices * @param jdbcConnectionAccess JDBC Connection access */ public LogicalConnectionImpl( Connection userSuppliedConnection, ConnectionReleaseMode connectionReleaseMode, JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess) { this( connectionReleaseMode, jdbcServices, jdbcConnectionAccess, (userSuppliedConnection != null), false, new ArrayList<ConnectionObserver>() ); this.physicalConnection = userSuppliedConnection; }
/** * Constructs a LogicalConnectionImpl. This for used from deserialization */ private LogicalConnectionImpl( ConnectionReleaseMode connectionReleaseMode, JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, boolean isUserSuppliedConnection, boolean isClosed, List<ConnectionObserver> observers) { this.connectionReleaseMode = determineConnectionReleaseMode( jdbcConnectionAccess, isUserSuppliedConnection, connectionReleaseMode ); this.jdbcServices = jdbcServices; this.jdbcConnectionAccess = jdbcConnectionAccess; this.observers = observers; this.isUserSuppliedConnection = isUserSuppliedConnection; this.isClosed = isClosed; }
@Override public void execute(Connection connection) { try { Statement statement = connection.createStatement(); try { statement.executeUpdate( persister.getTemporaryIdTableDDL() ); persister.getFactory() .getServiceRegistry() .getService( JdbcServices.class ) .getSqlExceptionHelper() .handleAndClearWarnings( statement, CREATION_WARNING_HANDLER ); } finally { try { statement.close(); } catch( Throwable ignore ) { // ignore } } } catch( Exception e ) { log.debug( "unable to create temporary id table [" + e.getMessage() + "]" ); } }
public SchemaUpdate(ServiceRegistry serviceRegistry, Configuration cfg) throws HibernateException { this.configuration = cfg; final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); this.dialect = jdbcServices.getDialect(); this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() ); this.sqlExceptionHelper = new SqlExceptionHelper(); this.sqlStatementLogger = jdbcServices.getSqlStatementLogger(); this.formatter = ( sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE ).getFormatter(); }
protected JDBCException convertSqlException(String message, SQLException e) { // if JdbcServices#getSqlExceptionHelper is available, use it... final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); if ( jdbcServices != null && jdbcServices.getSqlExceptionHelper() != null ) { return jdbcServices.getSqlExceptionHelper().convert( e, message, null ); } // likely we are still in the process of initializing the ServiceRegistry, so use the simplified // SQLException conversion return simpleConverterAccess.getValue().convert( e, message, null ); }
/** * Constructs a ResultSetReturnImpl * * @param jdbcCoordinator The JdbcCoordinator */ public ResultSetReturnImpl(JdbcCoordinator jdbcCoordinator) { this.jdbcCoordinator = jdbcCoordinator; final JdbcServices jdbcServices = jdbcCoordinator.getTransactionCoordinator().getTransactionContext() .getTransactionEnvironment() .getJdbcServices(); this.dialect = jdbcServices.getDialect(); this.sqlStatementLogger = jdbcServices.getSqlStatementLogger(); this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper(); }
protected AbstractBatchImpl(BatchKey key, JdbcCoordinator jdbcCoordinator) { if ( key == null ) { throw new IllegalArgumentException( "batch key cannot be null" ); } if ( jdbcCoordinator == null ) { throw new IllegalArgumentException( "JDBC coordinator cannot be null" ); } this.key = key; this.jdbcCoordinator = jdbcCoordinator; this.transactionContext = jdbcCoordinator.getTransactionCoordinator().getTransactionContext(); final JdbcServices jdbcServices = transactionContext.getTransactionEnvironment().getJdbcServices(); this.sqlStatementLogger = jdbcServices.getSqlStatementLogger(); this.sqlExceptionHelper = jdbcServices.getSqlExceptionHelper(); }
public TransactionEnvironmentImpl(SessionFactoryImpl sessionFactory) { this.sessionFactory = sessionFactory; this.statisticsImplementor = sessionFactory.getStatisticsImplementor(); this.serviceRegistry = sessionFactory.getServiceRegistry(); this.jdbcServices = serviceRegistry.getService( JdbcServices.class ); this.jtaPlatform = serviceRegistry.getService( JtaPlatform.class ); this.transactionFactory = serviceRegistry.getService( TransactionFactory.class ); }
@Override public void prepare( JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings) { this.catalog = ConfigurationHelper.getString( CATALOG, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_CATALOG, settings ) ); this.schema = ConfigurationHelper.getString( SCHEMA, settings, ConfigurationHelper.getString( AvailableSettings.DEFAULT_SCHEMA, settings ) ); this.cleanUpTables = ConfigurationHelper.getBoolean( CLEAN_UP_ID_TABLES, settings, false ); final Iterator<PersistentClass> entityMappings = mappings.iterateClasses(); final List<Table> idTableDefinitions = new ArrayList<Table>(); while ( entityMappings.hasNext() ) { final PersistentClass entityMapping = entityMappings.next(); final Table idTableDefinition = generateIdTableDefinition( entityMapping ); idTableDefinitions.add( idTableDefinition ); } exportTableDefinitions( idTableDefinitions, jdbcServices, connectionAccess, mappings, mapping ); }
public static void checkEntityManagerFactoryConfiguration(EntityManagerFactory entityManagerFactory) { try { SessionFactoryImpl sessionFactoryImpl = entityManagerFactory.unwrap(SessionFactoryImpl.class); if (PostgreSQL9Dialect.class .isInstance(sessionFactoryImpl.getServiceRegistry().getService(JdbcServices.class).getDialect())) { //fix ClassLeftUnique and ClassRightUnique, as PostgreSQL cannot evaluate them on statement level modifyConstraints(sessionFactoryImpl); } } catch (PersistenceException e) { LogManager.getLogger() .warn("Unsupported EntityManagerFactory found: {}", entityManagerFactory.getClass().getName()); } }
@Override public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, MetadataImplementor metadata, SessionFactoryOptions sessionFactoryOptions) { ConfigurationService configService = sessionFactoryOptions.getServiceRegistry().getService(ConfigurationService.class); this.fullyQualifiedTableName = Objects.requireNonNull(configService.getSetting(TABLE, String.class, null), "Property " + TABLE + " must be set."); this.idColumn = configService.getSetting(ID_COLUMN, String.class, "ID"); this.discriminatorColumn = configService.getSetting(DISCRIMINATOR_COLUMN, String.class, "ENTITY_NAME"); this.cleanRows = configService.getSetting(CLEAN_ROWS, StandardConverters.BOOLEAN, false); }
@Override public void prepare( JdbcServices jdbcServices, JdbcConnectionAccess jdbcConnectionAccess, MetadataImplementor metadataImplementor, SessionFactoryOptions sessionFactoryOptions) { }
public DbOpenHelper(ServiceRegistry serviceRegistry) throws HibernateException { final JdbcServices jdbcServices = serviceRegistry.getService(JdbcServices.class); connectionHelper = new SuppliedConnectionProviderConnectionHelper(jdbcServices.getConnectionProvider()); sqlStatementLogger = jdbcServices.getSqlStatementLogger(); formatter = (sqlStatementLogger.isFormat() ? FormatStyle.DDL : FormatStyle.NONE).getFormatter(); }
/** * Updates (or inserts) table column value with existing id * * @param session * @param currentValue * @return {@link Serializable} */ public Serializable generateIncrementally(final SessionImplementor session, final long currentValue) { final SqlStatementLogger statementLogger = session.getFactory() .getServiceRegistry().getService(JdbcServices.class) .getSqlStatementLogger(); final AccessCallback callback = new AccessCallbackImpl(session, currentValue, statementLogger); return optimizer.generate(callback); }
public JdbcServices getJdbcServices() { return sessionFactoryImplementor.getJdbcServices(); }
public SchemaValidator(ServiceRegistry serviceRegistry, Configuration cfg ) throws HibernateException { this.configuration = cfg; final JdbcServices jdbcServices = serviceRegistry.getService( JdbcServices.class ); this.dialect = jdbcServices.getDialect(); this.connectionHelper = new SuppliedConnectionProviderConnectionHelper( jdbcServices.getConnectionProvider() ); }
@Override public Class<JdbcServices> getServiceInitiated() { return JdbcServices.class; }
@Override public JdbcServices initiateService(Map configurationValues, ServiceRegistryImplementor registry) { return new JdbcServicesImpl(); }
@Override public JdbcServices getJdbcServices() { return jdbcServices; }
/** * Hook for service registry to be able to inject JdbcServices * * @param jdbcServices The JdbcServices service */ @InjectService @SuppressWarnings("UnusedDeclaration") public void injectJdbcServices(JdbcServices jdbcServices) { this.jdbcServices = jdbcServices; }
@Override public AccessCallback buildCallback(final SessionImplementor session) { final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry() .getService( JdbcServices.class ) .getSqlStatementLogger(); final SessionEventListenerManager statsCollector = session.getEventListenerManager(); return new AccessCallback() { @Override public IntegralDataTypeHolder getNextValue() { return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork( new AbstractReturningWork<IntegralDataTypeHolder>() { @Override public IntegralDataTypeHolder execute(Connection connection) throws SQLException { final IntegralDataTypeHolder value = makeValue(); int rows; do { final PreparedStatement selectStatement = prepareStatement( connection, selectQuery, statementLogger, statsCollector ); try { final ResultSet selectRS = executeQuery( selectStatement, statsCollector ); if ( !selectRS.next() ) { final String err = "could not read a hi value - you need to populate the table: " + tableName; LOG.error( err ); throw new IdentifierGenerationException( err ); } value.initialize( selectRS, 1 ); selectRS.close(); } catch (SQLException sqle) { LOG.error( "could not read a hi value", sqle ); throw sqle; } finally { selectStatement.close(); } final PreparedStatement updatePS = prepareStatement( connection, updateQuery, statementLogger, statsCollector ); try { final int increment = applyIncrementSizeToSourceValues ? incrementSize : 1; final IntegralDataTypeHolder updateValue = value.copy().add( increment ); updateValue.bind( updatePS, 1 ); value.bind( updatePS, 2 ); rows = executeUpdate( updatePS, statsCollector ); } catch (SQLException e) { LOG.unableToUpdateQueryHiValue( tableName, e ); throw e; } finally { updatePS.close(); } } while ( rows == 0 ); accessCounter++; return value; } }, true ); } @Override public String getTenantIdentifier() { return session.getTenantIdentifier(); } }; }
protected IntegralDataTypeHolder generateHolder(final SessionImplementor session) { final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry() .getService( JdbcServices.class ) .getSqlStatementLogger(); final SessionEventListenerManager listeners = session.getEventListenerManager(); return session.getTransactionCoordinator().getTransaction().createIsolationDelegate().delegateWork( new AbstractReturningWork<IntegralDataTypeHolder>() { @Override public IntegralDataTypeHolder execute(Connection connection) throws SQLException { IntegralDataTypeHolder value = buildHolder(); int rows; // The loop ensures atomicity of the select + update even for no transaction or // read committed isolation level do { final PreparedStatement qps = prepareStatement( connection, query, statementLogger, listeners ); try { ResultSet rs = executeQuery( qps, listeners ); if ( !rs.next() ) { String err = "could not read a hi value - you need to populate the table: " + tableName; LOG.error(err); throw new IdentifierGenerationException(err); } value.initialize( rs, 1 ); rs.close(); } catch (SQLException e) { LOG.error("Could not read a hi value", e); throw e; } finally { qps.close(); } final PreparedStatement ups = prepareStatement( connection, update, statementLogger, listeners ); try { value.copy().increment().bind( ups, 1 ); value.bind( ups, 2 ); rows = executeUpdate( ups, listeners ); } catch (SQLException sqle) { LOG.error(LOG.unableToUpdateHiValue(tableName), sqle); throw sqle; } finally { ups.close(); } } while (rows==0); return value; } }, true ); }
@Override public void injectServices(ServiceRegistryImplementor serviceRegistry) { this.dialect = serviceRegistry.getService( JdbcServices.class ).getDialect(); }
public JdbcServices getJdbcServices() { return jdbcServices; }
@Override public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings mappings, Mapping mapping, Map settings) { // nothing to do }
@Override public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) { // nothing to do }
@Override public void injectServices(ServiceRegistryImplementor serviceRegistryImplementor) { this.jtaPlatform = serviceRegistryImplementor.getService( JtaPlatform.class ); this.jdbcServices = serviceRegistryImplementor.getService( JdbcServices.class ); }
@Override public void release(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess) { }
@Override public void prepare(JdbcServices jdbcServices, JdbcConnectionAccess connectionAccess, Mappings arg2, Mapping arg3, Map arg4) { // nothing to do }
@Override public JdbcServices getJdbcServices() { return target.getJdbcServices(); }
/** * Retrieve the JDBC services for this environment. * * @return The JDBC services */ public JdbcServices getJdbcServices();
/** * Get the JdbcServices. * @return the JdbcServices */ public JdbcServices getJdbcServices();