Java Code Examples for org.hibernate.engine.jdbc.dialect.spi.DialectResolver

The following examples show how to use org.hibernate.engine.jdbc.dialect.spi.DialectResolver. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public void contribute(MetadataBuilder metadataBuilder, StandardServiceRegistry serviceRegistry) {
    DialectResolver dialectResolver = serviceRegistry.getService(DialectResolver.class);

    if (!(dialectResolver instanceof DialectResolverSet)) {
        logger.warnf("DialectResolver '%s' is not an instance of DialectResolverSet, not registering SQLiteDialect",
                dialectResolver);
        return;
    }

    ((DialectResolverSet) dialectResolver).addResolver(resolver);
}
 
Example 2
@Override
public DialectResolver initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final DialectResolverSet resolver = new DialectResolverSet();

	applyCustomerResolvers( resolver, registry, configurationValues );
	resolver.addResolver(StandardDialectResolver.INSTANCE );

	return resolver;
}
 
Example 3
Source Project: pnc   Source File: DefaultSequenceHandlerRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Long getNextID(final String sequenceName) {

    ReturningWork<Long> maxReturningWork = new ReturningWork<Long>() {
        @Override
        public Long execute(Connection connection) throws SQLException {
            DialectResolver dialectResolver = new StandardDialectResolver();
            Dialect dialect = dialectResolver.resolveDialect(getResolutionInfo(connection));
            PreparedStatement preparedStatement = null;
            ResultSet resultSet = null;
            try {
                preparedStatement = connection.prepareStatement(dialect.getSequenceNextValString(sequenceName));
                resultSet = preparedStatement.executeQuery();
                resultSet.next();
                return resultSet.getLong(1);
            } catch (SQLException e) {
                throw e;
            } finally {
                if (preparedStatement != null) {
                    preparedStatement.close();
                }
                if (resultSet != null) {
                    resultSet.close();
                }
            }

        }
    };

    Session session = (Session) entityManager.getDelegate();
    SessionFactory sessionFactory = session.getSessionFactory();

    Long maxRecord = sessionFactory.getCurrentSession().doReturningWork(maxReturningWork);
    return maxRecord;
}
 
Example 4
Source Project: pnc   Source File: DefaultSequenceHandlerRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void createSequence(final String sequenceName) {

    if (sequenceExists(sequenceName)) {
        return;
    }
    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            DialectResolver dialectResolver = new StandardDialectResolver();
            Dialect dialect = dialectResolver.resolveDialect(getResolutionInfo(connection));
            PreparedStatement preparedStatement = null;
            ResultSet resultSet = null;
            try {
                preparedStatement = connection
                        .prepareStatement(dialect.getCreateSequenceStrings(sequenceName, 1, 1)[0]);
                preparedStatement.execute();
            } catch (SQLException e) {
                throw e;
            } finally {
                if (preparedStatement != null) {
                    preparedStatement.close();
                }
                if (resultSet != null) {
                    resultSet.close();
                }
            }

        }
    };

    Session session = (Session) entityManager.getDelegate();
    SessionFactory sessionFactory = session.getSessionFactory();
    sessionFactory.getCurrentSession().doWork(work);
}
 
Example 5
Source Project: pnc   Source File: DefaultSequenceHandlerRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean sequenceExists(final String sequenceName) {
    ReturningWork<Boolean> work = new ReturningWork<Boolean>() {
        @Override
        public Boolean execute(Connection connection) throws SQLException {
            DialectResolver dialectResolver = new StandardDialectResolver();
            Dialect dialect = dialectResolver.resolveDialect(getResolutionInfo(connection));
            PreparedStatement preparedStatement = null;
            ResultSet resultSet = null;
            try {
                preparedStatement = connection.prepareStatement(dialect.getQuerySequencesString());
                resultSet = preparedStatement.executeQuery();
                while (resultSet.next()) {
                    if (sequenceName.equals(resultSet.getString(1))) {
                        return true;
                    }
                }
            } catch (SQLException e) {
                throw e;
            } finally {
                if (preparedStatement != null) {
                    preparedStatement.close();
                }
                if (resultSet != null) {
                    resultSet.close();
                }
            }
            return false;

        }
    };

    Session session = (Session) entityManager.getDelegate();
    SessionFactory sessionFactory = session.getSessionFactory();
    return sessionFactory.getCurrentSession().doReturningWork(work);
}
 
Example 6
Source Project: pnc   Source File: DefaultSequenceHandlerRepository.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void dropSequence(final String sequenceName) {

    Work work = new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            DialectResolver dialectResolver = new StandardDialectResolver();
            Dialect dialect = dialectResolver.resolveDialect(getResolutionInfo(connection));
            PreparedStatement preparedStatement = null;
            ResultSet resultSet = null;
            try {
                preparedStatement = connection.prepareStatement(dialect.getDropSequenceStrings(sequenceName)[0]);
                preparedStatement.execute();
            } catch (SQLException e) {
                throw e;
            } finally {
                if (preparedStatement != null) {
                    preparedStatement.close();
                }
                if (resultSet != null) {
                    resultSet.close();
                }
            }

        }
    };

    Session session = (Session) entityManager.getDelegate();
    SessionFactory sessionFactory = session.getSessionFactory();
    sessionFactory.getCurrentSession().doWork(work);
}
 
Example 7
Source Project: J2Cache   Source File: J2CacheMessageLogger_$logger.java    License: Apache License 2.0 4 votes vote down vote up
public final void unableToExecuteResolver(final DialectResolver arg0, final String arg1) {
    super.log.logf(FQCN, (org.jboss.logging.Logger.Level.WARN), null, unableToExecuteResolver$str(), arg0, arg1);
}
 
Example 8
Source Project: J2Cache   Source File: J2CacheMessageLogger_$logger.java    License: Apache License 2.0 4 votes vote down vote up
public final void unableToExecuteResolver(DialectResolver arg0, String arg1) {
    super.log.logf(FQCN, Logger.Level.WARN, (Throwable)null, this.unableToExecuteResolver$str(), arg0, arg1);
}
 
Example 9
public JdbcContext resolveJdbcContext(Map configurationValues) {
	final JdbcContextBuilder jdbcContextBuilder = new JdbcContextBuilder( serviceRegistry );

	// see if a specific connection has been provided
	final Connection providedConnection = (Connection) configurationValues.get( HBM2DDL_CONNECTION );
	if ( providedConnection != null ) {
		jdbcContextBuilder.jdbcConnectionAccess = new JdbcConnectionAccessProvidedConnectionImpl( providedConnection );
	}

	// see if a specific Dialect override has been provided...
	final String explicitDbName = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_NAME );
	if ( StringHelper.isNotEmpty( explicitDbName ) ) {
		final String explicitDbMajor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MAJOR_VERSION );
		final String explicitDbMinor = (String) configurationValues.get( AvailableSettings.HBM2DDL_DB_MINOR_VERSION );

		final Dialect indicatedDialect = serviceRegistry.getService( DialectResolver.class ).resolveDialect(
				new DialectResolutionInfo() {
					@Override
					public String getDatabaseName() {
						return explicitDbName;
					}

					@Override
					public int getDatabaseMajorVersion() {
						return StringHelper.isEmpty( explicitDbMajor )
								? NO_VERSION
								: Integer.parseInt( explicitDbMajor );
					}

					@Override
					public int getDatabaseMinorVersion() {
						return StringHelper.isEmpty( explicitDbMinor )
								? NO_VERSION
								: Integer.parseInt( explicitDbMinor );
					}

					@Override
					public String getDriverName() {
						return null;
					}

					@Override
					public int getDriverMajorVersion() {
						return NO_VERSION;
					}

					@Override
					public int getDriverMinorVersion() {
						return NO_VERSION;
					}
				}
		);

		if ( indicatedDialect == null ) {
			log.debugf(
					"Unable to resolve indicated Dialect resolution info (%s, %s, %s)",
					explicitDbName,
					explicitDbMajor,
					explicitDbMinor
			);
		}
		else {
			jdbcContextBuilder.dialect = indicatedDialect;
		}
	}

	return jdbcContextBuilder.buildJdbcContext();
}
 
Example 10
Source Project: lams   Source File: DialectFactoryImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void injectServices(ServiceRegistryImplementor serviceRegistry) {
	this.strategySelector = serviceRegistry.getService( StrategySelector.class );
	this.dialectResolver = serviceRegistry.getService( DialectResolver.class );
}
 
Example 11
@Override
public Class<DialectResolver> getServiceInitiated() {
	return DialectResolver.class;
}
 
Example 12
Source Project: lams   Source File: DialectResolverSet.java    License: GNU General Public License v2.0 4 votes vote down vote up
public DialectResolverSet() {
	this( new ArrayList<DialectResolver>() );
}
 
Example 13
Source Project: lams   Source File: DialectResolverSet.java    License: GNU General Public License v2.0 4 votes vote down vote up
public DialectResolverSet(List<DialectResolver> resolvers) {
	this.resolvers = resolvers;
}
 
Example 14
Source Project: lams   Source File: DialectResolverSet.java    License: GNU General Public License v2.0 4 votes vote down vote up
public DialectResolverSet(DialectResolver... resolvers) {
	this( Arrays.asList( resolvers ) );
}
 
Example 15
Source Project: lams   Source File: CoreMessageLogger.java    License: GNU General Public License v2.0 4 votes vote down vote up
@LogMessage(level = WARN)
@Message(value = "Error executing resolver [%s] : %s", id = 316)
void unableToExecuteResolver(
		DialectResolver abstractDialectResolver,
		String message);
 
Example 16
Source Project: lams   Source File: DialectFactoryImpl.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Intended only for use from testing.
 *
 * @param dialectResolver The DialectResolver to use
 */
public void setDialectResolver(DialectResolver dialectResolver) {
	this.dialectResolver = dialectResolver;
}
 
Example 17
Source Project: lams   Source File: DialectResolverSet.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Add a resolver at the end of the underlying resolver list.  The resolver added by this method is at lower
 * priority than any other existing resolvers.
 *
 * @param resolver The resolver to add.
 */
public void addResolver(DialectResolver resolver) {
	resolvers.add( resolver );
}
 
Example 18
Source Project: lams   Source File: DialectResolverSet.java    License: GNU General Public License v2.0 2 votes vote down vote up
/**
 * Add a resolver at the beginning of the underlying resolver list.  The resolver added by this method is at higher
 * priority than any other existing resolvers.
 *
 * @param resolver The resolver to add.
 */
public void addResolverAtFirst(DialectResolver resolver) {
	resolvers.add( 0, resolver );
}