org.hibernate.boot.registry.classloading.spi.ClassLoaderService Java Examples

The following examples show how to use org.hibernate.boot.registry.classloading.spi.ClassLoaderService. 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
Source File: ConfigLoader.java    From lams with GNU General Public License v2.0 7 votes vote down vote up
public LoadedConfig loadConfigXmlResource(String cfgXmlResourceName) {
	final InputStream stream = bootstrapServiceRegistry.getService( ClassLoaderService.class ).locateResourceStream( cfgXmlResourceName );
	if ( stream == null ) {
		throw new ConfigurationException( "Could not locate cfg.xml resource [" + cfgXmlResourceName + "]" );
	}

	try {
		final JaxbCfgHibernateConfiguration jaxbCfg = jaxbProcessorHolder.getValue().unmarshal(
				stream,
				new Origin( SourceType.RESOURCE, cfgXmlResourceName )
		);

		return LoadedConfig.consume( jaxbCfg );
	}
	finally {
		try {
			stream.close();
		}
		catch (IOException e) {
			log.debug( "Unable to close cfg.xml resource stream", e );
		}
	}
}
 
Example #2
Source File: SchemaCreatorImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private ScriptSourceInput interpretLegacyImportScriptSetting(
		String resourceName,
		ClassLoaderService classLoaderService,
		String charsetName) {
	try {
		final URL resourceUrl = classLoaderService.locateResource( resourceName );
		if ( resourceUrl == null ) {
			return ScriptSourceInputNonExistentImpl.INSTANCE;
		}
		else {
			return new ScriptSourceInputFromUrl( resourceUrl, charsetName );
		}
	}
	catch (Exception e) {
		throw new SchemaManagementException( "Error resolving legacy import resource : " + resourceName, e );
	}
}
 
Example #3
Source File: JPAMetadataProvider.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * @deprecated Use {@link JPAMetadataProvider#JPAMetadataProvider(BootstrapContext)} instead.
 */
@Deprecated
public JPAMetadataProvider(final MetadataBuildingOptions metadataBuildingOptions) {
	this( new ClassLoaderAccessDelegateImpl() {
		ClassLoaderAccess delegate;

		@Override
		protected ClassLoaderAccess getDelegate() {
			if ( delegate == null ) {
				delegate = new ClassLoaderAccessImpl(
						metadataBuildingOptions.getTempClassLoader(),
						metadataBuildingOptions.getServiceRegistry().getService( ClassLoaderService.class )
				);
			}
			return delegate;
		}
	} );
}
 
Example #4
Source File: DriverManagerConnectionProviderImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private Driver loadDriverIfPossible(String driverClassName) {
	if ( driverClassName == null ) {
		log.debug( "No driver class specified" );
		return null;
	}

	if ( serviceRegistry != null ) {
		final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );
		final Class<Driver> driverClass = classLoaderService.classForName( driverClassName );
		try {
			return driverClass.newInstance();
		}
		catch ( Exception e ) {
			throw new ServiceException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e );
		}
	}

	try {
		return (Driver) Class.forName( driverClassName ).newInstance();
	}
	catch ( Exception e1 ) {
		throw new ServiceException( "Specified JDBC Driver " + driverClassName + " could not be loaded", e1 );
	}
}
 
Example #5
Source File: DefaultIdentifierGeneratorFactory.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public Class getIdentifierGeneratorClass(String strategy) {
	if ( "hilo".equals( strategy ) ) {
		throw new UnsupportedOperationException( "Support for 'hilo' generator has been removed" );
	}
	String resolvedStrategy = "native".equals( strategy ) ?
			getDialect().getNativeIdentifierGeneratorStrategy() : strategy;

	Class generatorClass = generatorStrategyToClassNameMap.get( resolvedStrategy );
	try {
		if ( generatorClass == null ) {
			final ClassLoaderService cls = serviceRegistry.getService( ClassLoaderService.class );
			generatorClass = cls.classForName( resolvedStrategy );
		}
	}
	catch ( ClassLoadingException e ) {
		throw new MappingException( String.format( "Could not interpret id generator strategy [%s]", strategy ) );
	}
	return generatorClass;
}
 
Example #6
Source File: QuarkusStrategySelectorBuilder.java    From quarkus with Apache License 2.0 6 votes vote down vote up
/**
 * Builds the selector.
 *
 * @param classLoaderService The class loading service used to (attempt to) resolve any un-registered
 *        strategy implementations.
 *
 * @return The selector.
 */
public static StrategySelector buildSelector(ClassLoaderService classLoaderService) {
    final StrategySelectorImpl strategySelector = new StrategySelectorImpl(classLoaderService);

    // build the baseline...
    strategySelector.registerStrategyLazily(Dialect.class, new DefaultDialectSelector());
    strategySelector.registerStrategyLazily(JtaPlatform.class, new DefaultJtaPlatformSelector());
    addTransactionCoordinatorBuilders(strategySelector);
    addMultiTableBulkIdStrategies(strategySelector);
    addImplicitNamingStrategies(strategySelector);
    addCacheKeysFactories(strategySelector);

    // Required to support well known extensions e.g. Envers
    // TODO: should we introduce a new integrator SPI to limit these to extensions supported by Quarkus?
    for (StrategyRegistrationProvider provider : classLoaderService.loadJavaServices(StrategyRegistrationProvider.class)) {
        for (StrategyRegistration discoveredStrategyRegistration : provider.getStrategyRegistrations()) {
            applyFromStrategyRegistration(strategySelector, discoveredStrategyRegistration);
        }
    }

    return strategySelector;
}
 
Example #7
Source File: GrailsDomainBinder.java    From gorm-hibernate5 with Apache License 2.0 6 votes vote down vote up
@Override
public void contribute(InFlightMetadataCollector metadataCollector, IndexView jandexIndex) {
    MetadataBuildingOptions options = metadataCollector.getMetadataBuildingOptions();
    ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class);


    this.metadataBuildingContext = new MetadataBuildingContextRootImpl(
            metadataCollector.getBootstrapContext(),
            options,
            metadataCollector
    );

        java.util.Collection<PersistentEntity> persistentEntities = hibernateMappingContext.getPersistentEntities();
    for (PersistentEntity persistentEntity : persistentEntities) {
        if(!persistentEntity.getJavaClass().isAnnotationPresent(Entity.class)) {
            if(ConnectionSourcesSupport.usesConnectionSource(persistentEntity, dataSourceName) && persistentEntity.isRoot()) {
                bindRoot((HibernatePersistentEntity) persistentEntity, metadataCollector, sessionFactoryName);
            }
        }
    }
}
 
Example #8
Source File: BatchBuilderInitiator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public BatchBuilder initiateService(Map configurationValues, ServiceRegistryImplementor registry) {
	final Object builder = configurationValues.get( BUILDER );
	if ( builder == null ) {
		return new BatchBuilderImpl(
				ConfigurationHelper.getInt( Environment.STATEMENT_BATCH_SIZE, configurationValues, 1 )
		);
	}

	if ( BatchBuilder.class.isInstance( builder ) ) {
		return (BatchBuilder) builder;
	}

	final String builderClassName = builder.toString();
	try {
		return (BatchBuilder) registry.getService( ClassLoaderService.class ).classForName( builderClassName ).newInstance();
	}
	catch (Exception e) {
		throw new ServiceException( "Could not build explicit BatchBuilder [" + builderClassName + "]", e );
	}
}
 
Example #9
Source File: MemcachedRegionFactory.java    From hibernate-l2-memcached with Apache License 2.0 6 votes vote down vote up
private CacheManager useExplicitCacheManager(SessionFactoryOptions settings, Object setting) {
    if (setting instanceof CacheManager) {
        return (CacheManager) setting;
    }

    final Class<? extends CacheManager> cacheManagerClass;
    if (setting instanceof Class) {
        cacheManagerClass = (Class<? extends CacheManager>) setting;
    } else {
        cacheManagerClass = settings.getServiceRegistry().getService(ClassLoaderService.class).classForName(setting.toString());
    }

    try {
        return cacheManagerClass.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new CacheException("Could not use explicit CacheManager : " + setting);
    }
}
 
Example #10
Source File: TypeSafeActivator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings({"unchecked", "UnusedParameters"})
private static void applyRelationalConstraints(ValidatorFactory factory, ActivationContext activationContext) {
	final ConfigurationService cfgService = activationContext.getServiceRegistry().getService( ConfigurationService.class );
	if ( !cfgService.getSetting( BeanValidationIntegrator.APPLY_CONSTRAINTS, StandardConverters.BOOLEAN, 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.getMetadata().getEntityBindings(),
			cfgService.getSettings(),
			activationContext.getServiceRegistry().getService( JdbcServices.class ).getDialect(),
			new ClassLoaderAccessImpl(
					null,
					activationContext.getServiceRegistry().getService( ClassLoaderService.class )
			)
	);
}
 
Example #11
Source File: JBossStandAloneJtaPlatform.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected UserTransaction locateUserTransaction() {
	//Try WildFly first as it's the "new generation":
	try {
		return wildflyBasedAlternative.locateUserTransaction();
	}
	catch ( Exception ignore) {
		// ignore and look for Arjuna class
	}

	try {
		final Class jbossUtClass = serviceRegistry()
				.getService( ClassLoaderService.class )
				.classForName( JBOSS_UT_CLASS_NAME );
		return (UserTransaction) jbossUtClass.getMethod( "userTransaction" ).invoke( null );
	}
	catch ( Exception e ) {
		throw new JtaPlatformException( "Could not obtain JBoss Transactions user transaction instance", e );
	}
}
 
Example #12
Source File: Array.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Class getElementClass() throws MappingException {
	if ( elementClassName == null ) {
		org.hibernate.type.Type elementType = getElement().getType();
		return isPrimitiveArray()
				? ( (PrimitiveType) elementType ).getPrimitiveClass()
				: elementType.getReturnedClass();
	}
	else {
		try {
			return getMetadata().getMetadataBuildingOptions()
					.getServiceRegistry()
					.getService( ClassLoaderService.class )
					.classForName( elementClassName );
		}
		catch (ClassLoadingException e) {
			throw new MappingException( e );
		}
	}
}
 
Example #13
Source File: SimpleValue.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void setTypeName(String typeName) {
	if ( typeName != null && typeName.startsWith( AttributeConverterTypeAdapter.NAME_PREFIX ) ) {
		final String converterClassName = typeName.substring( AttributeConverterTypeAdapter.NAME_PREFIX.length() );
		final ClassLoaderService cls = getMetadata()
				.getMetadataBuildingOptions()
				.getServiceRegistry()
				.getService( ClassLoaderService.class );
		try {
			final Class<? extends AttributeConverter> converterClass = cls.classForName( converterClassName );
			this.attributeConverterDescriptor = new ClassBasedConverterDescriptor(
					converterClass,
					false,
					( (InFlightMetadataCollector) getMetadata() ).getClassmateContext()
			);
			return;
		}
		catch (Exception e) {
			log.logBadHbmAttributeConverterType( typeName, e.getMessage() );
		}
	}

	this.typeName = typeName;
}
 
Example #14
Source File: MetamodelImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
public String[] getImplementors(String className) throws MappingException {
	// computeIfAbsent() can be a contention point and we expect all the values to be in the map at some point so
	// let's do an optimistic check first
	String[] implementors = implementorsCache.get( className );
	if ( implementors != null ) {
		return Arrays.copyOf( implementors, implementors.length );
	}

	try {
		final Class<?> clazz = getSessionFactory().getServiceRegistry().getService( ClassLoaderService.class ).classForName( className );
		implementors = doGetImplementors( clazz );
		if ( implementors.length > 0 ) {
			implementorsCache.putIfAbsent( className, implementors );
			return Arrays.copyOf( implementors, implementors.length );
		}
		else {
			return EMPTY_IMPLEMENTORS;
		}
	}
	catch (ClassLoadingException e) {
		return new String[]{ className }; // we don't cache anything for dynamic classes
	}
}
 
Example #15
Source File: XMLHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public XMLHelper(ClassLoaderService classLoaderService) {
	this.documentFactory = classLoaderService.workWithClassLoader(
			new ClassLoaderService.Work<DocumentFactory>() {
				@Override
				public DocumentFactory doWork(ClassLoader classLoader) {
					final ClassLoader originalTccl = Thread.currentThread().getContextClassLoader();
					try {
						Thread.currentThread().setContextClassLoader( classLoader );
						return DocumentFactory.getInstance();
					}
					finally {
						Thread.currentThread().setContextClassLoader( originalTccl );
					}
				}
			}
	);

}
 
Example #16
Source File: SessionFactoryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void prepareEventListeners(MetadataImplementor metadata) {
	final EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
	final ConfigurationService cfgService = serviceRegistry.getService( ConfigurationService.class );
	final ClassLoaderService classLoaderService = serviceRegistry.getService( ClassLoaderService.class );

	eventListenerRegistry.prepare( metadata );

	for ( Map.Entry entry : ( (Map<?, ?>) cfgService.getSettings() ).entrySet() ) {
		if ( !String.class.isInstance( entry.getKey() ) ) {
			continue;
		}
		final String propertyName = (String) entry.getKey();
		if ( !propertyName.startsWith( org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX ) ) {
			continue;
		}
		final String eventTypeName = propertyName.substring(
				org.hibernate.jpa.AvailableSettings.EVENT_LISTENER_PREFIX.length() + 1
		);
		final EventType eventType = EventType.resolveEventTypeByName( eventTypeName );
		final EventListenerGroup eventListenerGroup = eventListenerRegistry.getEventListenerGroup( eventType );
		for ( String listenerImpl : ( (String) entry.getValue() ).split( " ," ) ) {
			eventListenerGroup.appendListener( instantiate( listenerImpl, classLoaderService ) );
		}
	}
}
 
Example #17
Source File: BootstrapServiceRegistryImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructs a BootstrapServiceRegistryImpl.
 *
 * Do not use directly generally speaking.  Use {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder}
 * instead.
 *
 * @param autoCloseRegistry See discussion on
 * {@link org.hibernate.boot.registry.BootstrapServiceRegistryBuilder#disableAutoClose}
 * @param classLoaderService The ClassLoaderService to use
 * @param providedIntegrators The group of explicitly provided integrators
 *
 * @see org.hibernate.boot.registry.BootstrapServiceRegistryBuilder
 */
public BootstrapServiceRegistryImpl(
		boolean autoCloseRegistry,
		ClassLoaderService classLoaderService,
		LinkedHashSet<Integrator> providedIntegrators) {
	this.autoCloseRegistry = autoCloseRegistry;

	this.classLoaderServiceBinding = new ServiceBinding<ClassLoaderService>(
			this,
			ClassLoaderService.class,
			classLoaderService
	);

	final StrategySelectorImpl strategySelector = new StrategySelectorImpl( classLoaderService );
	this.strategySelectorBinding = new ServiceBinding<StrategySelector>(
			this,
			StrategySelector.class,
			strategySelector
	);

	this.integratorServiceBinding = new ServiceBinding<IntegratorService>(
			this,
			IntegratorService.class,
			new IntegratorServiceImpl( providedIntegrators, classLoaderService )
	);
}
 
Example #18
Source File: IgniteProviderConfiguration.java    From hibernate-ogm-ignite with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Initialize the internal values from the given {@link Map}.
 *
 * @param configurationMap The values to use as configuration
 */
public void initialize(Map configurationMap, ClassLoaderService classLoaderService) {
	ConfigurationPropertyReader configurationPropertyReader = new ConfigurationPropertyReader( configurationMap, classLoaderService );

	this.url = configurationPropertyReader
		.property( IgniteProperties.CONFIGURATION_RESOURCE_NAME, URL.class )
		.withDefault( IgniteProviderConfiguration.class.getClassLoader().getResource( DEFAULT_CONFIG ) )
		.getValue();

	String configBuilderClassName = configurationPropertyReader
			.property( IgniteProperties.CONFIGURATION_CLASS_NAME, String.class )
			.getValue();

	if ( configBuilderClassName != null ) {
		this.configBuilder = configurationPropertyReader
				.property( IgniteProperties.CONFIGURATION_CLASS_NAME, IgniteConfigurationBuilder.class )
				.instantiate()
				.getValue();
	}

	this.instanceName = configurationPropertyReader
			.property( IgniteProperties.IGNITE_INSTANCE_NAME, String.class )
			.getValue();
}
 
Example #19
Source File: SchemaExport.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static TargetDescriptor buildTargetDescriptor(
		EnumSet<TargetType> targetTypes,
		String outputFile,
		ServiceRegistry serviceRegistry) {
	final ScriptTargetOutput scriptTarget;
	if ( targetTypes.contains( TargetType.SCRIPT ) ) {
		if ( outputFile == null ) {
			throw new SchemaManagementException( "Writing to script was requested, but no script file was specified" );
		}
		scriptTarget = Helper.interpretScriptTargetSetting(
				outputFile,
				serviceRegistry.getService( ClassLoaderService.class ),
				(String) serviceRegistry.getService( ConfigurationService.class ).getSettings().get( AvailableSettings.HBM2DDL_CHARSET_NAME )
		);
	}
	else {
		scriptTarget = null;
	}

	return new TargetDescriptorImpl( targetTypes, scriptTarget );
}
 
Example #20
Source File: ScanningCoordinator.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public void coordinateScan(
		ManagedResourcesImpl managedResources,
		BootstrapContext bootstrapContext,
		XmlMappingBinderAccess xmlMappingBinderAccess) {
	if ( bootstrapContext.getScanEnvironment() == null ) {
		return;
	}

	final ClassLoaderService classLoaderService = bootstrapContext.getServiceRegistry().getService( ClassLoaderService.class );
	final ClassLoaderAccess classLoaderAccess = new ClassLoaderAccessImpl(
			bootstrapContext.getJpaTempClassLoader(),
			classLoaderService
	);

	// NOTE : the idea with JandexInitializer/JandexInitManager was to allow adding classes
	// to the index as we discovered them via scanning and .  Currently
	final Scanner scanner = buildScanner( bootstrapContext, classLoaderAccess );
	final ScanResult scanResult = scanner.scan(
			bootstrapContext.getScanEnvironment(),
			bootstrapContext.getScanOptions(),
			StandardScanParameters.INSTANCE
	);

	applyScanResultsToManagedResources( managedResources, scanResult, bootstrapContext, xmlMappingBinderAccess );
}
 
Example #21
Source File: Collection.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public Comparator getComparator() {
	if ( comparator == null && comparatorClassName != null ) {
		try {
			final ClassLoaderService classLoaderService = getMetadata().getMetadataBuildingOptions()
					.getServiceRegistry()
					.getService( ClassLoaderService.class );
			setComparator( (Comparator) classLoaderService.classForName( comparatorClassName ).newInstance() );
		}
		catch (Exception e) {
			throw new MappingException(
					"Could not instantiate comparator class [" + comparatorClassName
							+ "] for collection " + getRole()
			);
		}
	}
	return comparator;
}
 
Example #22
Source File: JBossStandAloneJtaPlatform.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
@Override
protected TransactionManager locateTransactionManager() {
	//Try WildFly first as it's the "new generation":
	try {
		return wildflyBasedAlternative.locateTransactionManager();
	}
	catch ( Exception ignore) {
		// ignore and look for Arjuna class
	}

	try {
		final Class jbossTmClass = serviceRegistry()
				.getService( ClassLoaderService.class )
				.classForName( JBOSS_TM_CLASS_NAME );
		return (TransactionManager) jbossTmClass.getMethod( "transactionManager" ).invoke( null );
	}
	catch ( Exception e ) {
		throw new JtaPlatformException( "Could not obtain JBoss Transactions transaction manager instance", e );
	}
}
 
Example #23
Source File: BitronixJtaPlatform.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected TransactionManager locateTransactionManager() {
	try {
		Class transactionManagerServicesClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
		final Method getTransactionManagerMethod = transactionManagerServicesClass.getMethod( "getTransactionManager" );
		return (TransactionManager) getTransactionManagerMethod.invoke( null );
	}
	catch (Exception e) {
		throw new JtaPlatformException( "Could not locate Bitronix TransactionManager", e );
	}
}
 
Example #24
Source File: JOTMJtaPlatform.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected TransactionManager locateTransactionManager() {
	try {
		final Class tmClass = serviceRegistry().getService( ClassLoaderService.class ).classForName( TM_CLASS_NAME );
		final Method getTransactionManagerMethod = tmClass.getMethod( "getTransactionManager" );
		return (TransactionManager) getTransactionManagerMethod.invoke( null, (Object[]) null );
	}
	catch (Exception e) {
		throw new JtaPlatformException( "Could not obtain JOTM transaction manager instance", e );
	}
}
 
Example #25
Source File: ComponentTuplizerFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link ComponentTuplizerFactory#ComponentTuplizerFactory(BootstrapContext)} instead.
 */
@Deprecated
public ComponentTuplizerFactory(MetadataBuildingOptions metadataBuildingOptions) {
	classLoaderAccess = new ClassLoaderAccessImpl(
			metadataBuildingOptions.getTempClassLoader(),
			metadataBuildingOptions.getServiceRegistry().getService( ClassLoaderService.class )
	);
}
 
Example #26
Source File: Helper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static ScriptTargetOutput interpretScriptTargetSetting(
		Object scriptTargetSetting,
		ClassLoaderService classLoaderService,
		String charsetName ) {
	if ( scriptTargetSetting == null ) {
		return null;
	}
	else if ( Writer.class.isInstance( scriptTargetSetting ) ) {
		return new ScriptTargetOutputToWriter( (Writer) scriptTargetSetting );
	}
	else {
		final String scriptTargetSettingString = scriptTargetSetting.toString();
		log.debugf( "Attempting to resolve script source setting : %s", scriptTargetSettingString );

		// setting could be either:
		//		1) string URL representation (i.e., "file://...")
		//		2) relative file path (resource lookup)
		//		3) absolute file path

		log.trace( "Trying as URL..." );
		// ClassLoaderService.locateResource() first tries the given resource name as url form...
		final URL url = classLoaderService.locateResource( scriptTargetSettingString );
		if ( url != null ) {
			return new ScriptTargetOutputToUrl( url, charsetName );
		}

		// assume it is a File path
		final File file = new File( scriptTargetSettingString );
		return new ScriptTargetOutputToFile( file, charsetName );
	}
}
 
Example #27
Source File: ResultSetWrapperProxy.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Generates a proxy wrapping the ResultSet.
 *
 * @param resultSet The resultSet to wrap.
 * @param columnNameCache The cache storing data for converting column names to column indexes.
 * @param serviceRegistry Access to any needed services
 *
 * @return The generated proxy.
 */
public static ResultSet generateProxy(
		ResultSet resultSet,
		ColumnNameCache columnNameCache,
		ServiceRegistry serviceRegistry) {
	return serviceRegistry.getService( ClassLoaderService.class ).generateProxy(
			new ResultSetWrapperProxy( resultSet, columnNameCache ),
			ResultSet.class
	);
}
 
Example #28
Source File: Helper.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static ScriptSourceInput interpretScriptSourceSetting(
		Object scriptSourceSetting,
		ClassLoaderService classLoaderService,
		String charsetName ) {
	if ( Reader.class.isInstance( scriptSourceSetting ) ) {
		return new ScriptSourceInputFromReader( (Reader) scriptSourceSetting );
	}
	else {
		final String scriptSourceSettingString = scriptSourceSetting.toString();
		log.debugf( "Attempting to resolve script source setting : %s", scriptSourceSettingString );

		// setting could be either:
		//		1) string URL representation (i.e., "file://...")
		//		2) relative file path (resource lookup)
		//		3) absolute file path

		log.trace( "Trying as URL..." );
		// ClassLoaderService.locateResource() first tries the given resource name as url form...
		final URL url = classLoaderService.locateResource( scriptSourceSettingString );
		if ( url != null ) {
			return new ScriptSourceInputFromUrl( url, charsetName );
		}

		// assume it is a File path
		final File file = new File( scriptSourceSettingString );
		return new ScriptSourceInputFromFile( file, charsetName );
	}
}
 
Example #29
Source File: SessionFactoryServiceRegistryFactoryImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public SessionFactoryServiceRegistry buildServiceRegistry(
		SessionFactoryImplementor sessionFactory,
		BootstrapContext bootstrapContext,
		SessionFactoryOptions options) {
	final ClassLoaderService cls = options.getServiceRegistry().getService( ClassLoaderService.class );
	final SessionFactoryServiceRegistryBuilderImpl builder = new SessionFactoryServiceRegistryBuilderImpl( theBasicServiceRegistry );

	for ( SessionFactoryServiceContributor contributor : cls.loadJavaServices( SessionFactoryServiceContributor.class ) ) {
		contributor.contribute( builder );
	}

	return builder.buildSessionFactoryServiceRegistry( sessionFactory, bootstrapContext, options );
}
 
Example #30
Source File: WildFlyStandAloneJtaPlatform.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
protected TransactionManager locateTransactionManager() {
	try {
		final Class wildflyTmClass = serviceRegistry()
				.getService( ClassLoaderService.class )
				.classForName( WILDFLY_TM_CLASS_NAME );
		return (TransactionManager) wildflyTmClass.getMethod( "getInstance" ).invoke( null );
	}
	catch (Exception e) {
		throw new JtaPlatformException(
				"Could not obtain WildFly Transaction Client transaction manager instance",
				e
		);
	}
}