org.hibernate.boot.spi.MetadataImplementor Java Examples

The following examples show how to use org.hibernate.boot.spi.MetadataImplementor. 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 Project: lams   Author: lamsfoundation   File: SchemaExport.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void execute(CommandLineArgs commandLineArgs) throws Exception {
	StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( commandLineArgs );
	try {
		final MetadataImplementor metadata = buildMetadata( commandLineArgs, serviceRegistry );

		new SchemaExport()
				.setHaltOnError( commandLineArgs.halt )
				.setOutputFile( commandLineArgs.outputFile )
				.setDelimiter( commandLineArgs.delimiter )
				.setFormat( commandLineArgs.format )
				.setManageNamespaces( commandLineArgs.manageNamespaces )
				.setImportFiles( commandLineArgs.importFile )
				.execute( commandLineArgs.targetTypes, commandLineArgs.action, metadata, serviceRegistry );
	}
	finally {
		StandardServiceRegistryBuilder.destroy( serviceRegistry );
	}
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: SchemaUpdate.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
	try {
		final CommandLineArgs parsedArgs = CommandLineArgs.parseCommandLineArgs( args );
		final StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( parsedArgs );

		try {
			final MetadataImplementor metadata = buildMetadata( parsedArgs, serviceRegistry );

			new SchemaUpdate()
					.setOutputFile( parsedArgs.outputFile )
					.setDelimiter( parsedArgs.delimiter )
					.execute( parsedArgs.targetTypes, metadata, serviceRegistry );
		}
		finally {
			StandardServiceRegistryBuilder.destroy( serviceRegistry );
		}
	}
	catch (Exception e) {
		LOG.unableToRunSchemaUpdate( e );
	}
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: SchemaValidator.java    License: GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) {
	try {
		final CommandLineArgs parsedArgs = CommandLineArgs.parseCommandLineArgs( args );
		final StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( parsedArgs );

		try {
			final MetadataImplementor metadata = buildMetadata( parsedArgs, serviceRegistry );
			new SchemaValidator().validate( metadata, serviceRegistry );
		}
		finally {
			StandardServiceRegistryBuilder.destroy( serviceRegistry );
		}
	}
	catch (Exception e) {
		LOG.unableToRunSchemaUpdate( e );
	}
}
 
Example #4
Source Project: lams   Author: lamsfoundation   File: SessionFactoryImpl.java    License: 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 #5
Source Project: lams   Author: lamsfoundation   File: LocalTemporaryTableBulkIdStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected IdTableInfoImpl buildIdTableInfo(
		PersistentClass entityBinding,
		Table idTable,
		JdbcServices jdbcServices,
		MetadataImplementor metadata,
		PreparationContext context) {
	return new IdTableInfoImpl(
			jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
					idTable.getQualifiedTableName(),
					jdbcServices.getJdbcEnvironment().getDialect()
			),
			buildIdTableCreateStatement( idTable, jdbcServices, metadata ),
			buildIdTableDropStatement( idTable, jdbcServices )
	);
}
 
Example #6
Source Project: lams   Author: lamsfoundation   File: GlobalTemporaryTableBulkIdStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected IdTableInfoImpl buildIdTableInfo(
		PersistentClass entityBinding,
		Table idTable,
		JdbcServices jdbcServices,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) );
	if ( dropIdTables ) {
		context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) );
	}

	final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
			idTable.getQualifiedTableName(),
			jdbcServices.getJdbcEnvironment().getDialect()
	);

	return new IdTableInfoImpl( renderedName );
}
 
Example #7
Source Project: lams   Author: lamsfoundation   File: GlobalTemporaryTableBulkIdStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void finishPreparation(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	IdTableHelper.INSTANCE.executeIdTableCreationStatements(
			context.creationStatements,
			jdbcServices,
			connectionAccess
	);

	this.dropTableStatements = dropIdTables
			? context.dropStatements.toArray( new String[ context.dropStatements.size() ] )
			: null;
}
 
Example #8
Source Project: lams   Author: lamsfoundation   File: PersistentTableBulkIdStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected IdTableInfoImpl buildIdTableInfo(
		PersistentClass entityBinding,
		Table idTable,
		JdbcServices jdbcServices,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	final String renderedName = jdbcServices.getJdbcEnvironment().getQualifiedObjectNameFormatter().format(
			idTable.getQualifiedTableName(),
			jdbcServices.getJdbcEnvironment().getDialect()
	);

	context.creationStatements.add( buildIdTableCreateStatement( idTable, jdbcServices, metadata ) );
	if ( dropIdTables ) {
		context.dropStatements.add( buildIdTableDropStatement( idTable, jdbcServices ) );
	}

	return new IdTableInfoImpl( renderedName );
}
 
Example #9
Source Project: lams   Author: lamsfoundation   File: PersistentTableBulkIdStrategy.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
protected void finishPreparation(
		JdbcServices jdbcServices,
		JdbcConnectionAccess connectionAccess,
		MetadataImplementor metadata,
		PreparationContextImpl context) {
	IdTableHelper.INSTANCE.executeIdTableCreationStatements(
			context.creationStatements,
			jdbcServices,
			connectionAccess
	);

	this.dropTableStatements = dropIdTables
			? context.dropStatements.toArray( new String[ context.dropStatements.size() ] )
			: null;
}
 
Example #10
Source Project: mPaaS   Author: lihangqi   File: HibernateMetadataExtractor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public SessionFactoryBuilder getSessionFactoryBuilder(
        MetadataImplementor metadata,
        SessionFactoryBuilderImplementor defaultBuilder) {
    List<String> handled = new ArrayList<>();
    for (PersistentClass entity : metadata.getEntityBindings()) {
        bind(entity, handled);
    }
    return null;
}
 
Example #11
Source Project: lams   Author: lamsfoundation   File: OneToOne.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * @deprecated Use {@link OneToOne#OneToOne(MetadataBuildingContext, Table, PersistentClass)} instead.
 */
@Deprecated
public OneToOne(MetadataImplementor metadata, Table table, PersistentClass owner) throws MappingException {
	super( metadata, table );
	this.identifier = owner.getKey();
	this.entityName = owner.getEntityName();
}
 
Example #12
Source Project: lams   Author: lamsfoundation   File: SchemaExport.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * For testing use
 */
public void perform(Action action, Metadata metadata, ScriptTargetOutput target) {
	doExecution(
			action,
			false,
			metadata,
			( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry(),
			new TargetDescriptorImpl( EnumSet.of( TargetType.SCRIPT ), target )
	);
}
 
Example #13
Source Project: lams   Author: lamsfoundation   File: SchemaExport.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Intended for test usage only.  Builds a Metadata using the same algorithm  as
 * {@link #main}
 *
 * @param args The "command line args"
 *
 * @return The built Metadata
 *
 * @throws Exception Problems building the Metadata
 */
public static MetadataImplementor buildMetadataFromMainArgs(String[] args) throws Exception {
	final CommandLineArgs commandLineArgs = CommandLineArgs.parseCommandLineArgs( args );
	StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( commandLineArgs );
	try {
		return buildMetadata( commandLineArgs, serviceRegistry );
	}
	finally {
		StandardServiceRegistryBuilder.destroy( serviceRegistry );
	}
}
 
Example #14
Source Project: lams   Author: lamsfoundation   File: SchemaUpdate.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Intended for test usage only.  Builds a Metadata using the same algorithm  as
 * {@link #main}
 *
 * @param args The "command line args"
 *
 * @return The built Metadata
 *
 * @throws Exception Problems building the Metadata
 */
public static MetadataImplementor buildMetadataFromMainArgs(String[] args) throws Exception {
	final CommandLineArgs commandLineArgs = CommandLineArgs.parseCommandLineArgs( args );
	StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( commandLineArgs );
	try {
		return buildMetadata( commandLineArgs, serviceRegistry );
	}
	finally {
		StandardServiceRegistryBuilder.destroy( serviceRegistry );
	}
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: SchemaValidator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Intended for test usage only.  Builds a Metadata using the same algorithm  as
 * {@link #main}
 *
 * @param args The "command line args"
 *
 * @return The built Metadata
 *
 * @throws Exception Problems building the Metadata
 */
public static MetadataImplementor buildMetadataFromMainArgs(String[] args) throws Exception {
	final CommandLineArgs commandLineArgs = CommandLineArgs.parseCommandLineArgs( args );
	StandardServiceRegistry serviceRegistry = buildStandardServiceRegistry( commandLineArgs );
	try {
		return buildMetadata( commandLineArgs, serviceRegistry );
	}
	finally {
		StandardServiceRegistryBuilder.destroy( serviceRegistry );
	}
}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: SchemaCreatorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * For testing...
 *
 * @param metadata The metadata for which to generate the creation commands.
 *
 * @return The generation commands
 */
public List<String> generateCreationCommands(Metadata metadata, final boolean manageNamespaces) {
	final JournalingGenerationTarget target = new JournalingGenerationTarget();

	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions()
			.getServiceRegistry();
	final Dialect dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect();

	final ExecutionOptions options = new ExecutionOptions() {
		@Override
		public boolean shouldManageNamespaces() {
			return manageNamespaces;
		}

		@Override
		public Map getConfigurationValues() {
			return Collections.emptyMap();
		}

		@Override
		public ExceptionHandler getExceptionHandler() {
			return ExceptionHandlerHaltImpl.INSTANCE;
		}
	};

	createFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );

	return target.commands;
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: SchemaCreatorImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void doCreation(
		Metadata metadata,
		final boolean manageNamespaces,
		GenerationTarget... targets) {
	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry();
	doCreation(
			metadata,
			serviceRegistry,
			serviceRegistry.getService( ConfigurationService.class ).getSettings(),
			manageNamespaces,
			targets
	);
}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: AbstractSchemaMigrator.java    License: GNU General Public License v2.0 5 votes vote down vote up
private UniqueConstraintSchemaUpdateStrategy determineUniqueConstraintSchemaUpdateStrategy(Metadata metadata) {
	final ConfigurationService cfgService = ((MetadataImplementor) metadata).getMetadataBuildingOptions()
			.getServiceRegistry()
			.getService( ConfigurationService.class );

	return UniqueConstraintSchemaUpdateStrategy.interpret(
			cfgService.getSetting( UNIQUE_CONSTRAINT_SCHEMA_UPDATE_STRATEGY, StandardConverters.STRING )
	);
}
 
Example #19
Source Project: lams   Author: lamsfoundation   File: SchemaDropperImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * For testing...
 *
 * @param metadata The metadata for which to generate the creation commands.
 *
 * @return The generation commands
 */
public List<String> generateDropCommands(Metadata metadata, final boolean manageNamespaces) {
	final JournalingGenerationTarget target = new JournalingGenerationTarget();

	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions()
			.getServiceRegistry();
	final Dialect dialect = serviceRegistry.getService( JdbcEnvironment.class ).getDialect();

	final ExecutionOptions options = new ExecutionOptions() {
		@Override
		public boolean shouldManageNamespaces() {
			return manageNamespaces;
		}

		@Override
		public Map getConfigurationValues() {
			return Collections.emptyMap();
		}

		@Override
		public ExceptionHandler getExceptionHandler() {
			return ExceptionHandlerHaltImpl.INSTANCE;
		}
	};

	dropFromMetadata( metadata, options, dialect, FormatStyle.NONE.getFormatter(), target );

	return target.commands;
}
 
Example #20
Source Project: lams   Author: lamsfoundation   File: SchemaDropperImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * For tests
 */
public void doDrop(Metadata metadata, boolean manageNamespaces, GenerationTarget... targets) {
	final ServiceRegistry serviceRegistry = ( (MetadataImplementor) metadata ).getMetadataBuildingOptions().getServiceRegistry();
	doDrop(
			metadata,
			serviceRegistry,
			serviceRegistry.getService( ConfigurationService.class ).getSettings(),
			manageNamespaces,
			targets
	);
}
 
Example #21
Source Project: lams   Author: lamsfoundation   File: EntityManagerFactoryBuilderImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
private MetadataImplementor metadata() {
	if ( this.metadata == null ) {
		this.metadata = MetadataBuildingProcess.complete(
				managedResources,
				metamodelBuilder.getBootstrapContext(),
				metamodelBuilder.getMetadataBuildingOptions()
		);
	}
	return metadata;
}
 
Example #22
Source Project: lams   Author: lamsfoundation   File: EventListenerRegistryImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(MetadataImplementor metadata) {
	if ( callbackBuilder == null ) {
		// TODO : not needed anymore when the deprecate constructor will be removed
		this.callbackBuilder = new CallbackBuilderLegacyImpl(
				sessionFactory.getServiceRegistry().getService( ManagedBeanRegistry.class ),
				metadata.getMetadataBuildingOptions().getReflectionManager()
		);
	}
	for ( PersistentClass persistentClass : metadata.getEntityBindings() ) {
		if ( persistentClass.getClassName() == null ) {
			// we can have non java class persisted by hibernate
			continue;
		}
		callbackBuilder.buildCallbacksForEntity( persistentClass.getClassName(), callbackRegistry );

		for ( Iterator propertyIterator = persistentClass.getDeclaredPropertyIterator();
				propertyIterator.hasNext(); ) {
			Property property = (Property) propertyIterator.next();

			if ( property.getType().isComponentType() ) {
				callbackBuilder.buildCallbacksForEmbeddable(
						property,
						persistentClass.getClassName(),
						callbackRegistry
				);
			}
		}
	}
}
 
Example #23
Source Project: lams   Author: lamsfoundation   File: MetadataBuilderImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public MetadataImplementor build() {
	final CfgXmlAccessService cfgXmlAccessService = options.serviceRegistry.getService( CfgXmlAccessService.class );
	if ( cfgXmlAccessService.getAggregatedConfig() != null ) {
		if ( cfgXmlAccessService.getAggregatedConfig().getMappingReferences() != null ) {
			for ( MappingReference mappingReference : cfgXmlAccessService.getAggregatedConfig().getMappingReferences() ) {
				mappingReference.apply( sources );
			}
		}
	}

	return MetadataBuildingProcess.build( sources, bootstrapContext, options );
}
 
Example #24
Source Project: lams   Author: lamsfoundation   File: SessionFactoryBuilderImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
public SessionFactoryBuilderImpl(MetadataImplementor metadata, BootstrapContext bootstrapContext) {
	this.metadata = metadata;
	this.bootstrapContext = bootstrapContext;

	this.optionsBuilder = new SessionFactoryOptionsBuilder(
			metadata.getMetadataBuildingOptions().getServiceRegistry(),
			bootstrapContext
	);

	if ( metadata.getSqlFunctionMap() != null ) {
		for ( Map.Entry<String, SQLFunction> sqlFunctionEntry : metadata.getSqlFunctionMap().entrySet() ) {
			applySqlFunction( sqlFunctionEntry.getKey(), sqlFunctionEntry.getValue() );
		}
	}
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: CteValuesListBulkIdStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: InlineIdsInClauseBulkIdStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #27
Source Project: lams   Author: lamsfoundation   File: InlineIdsSubSelectValueListBulkIdStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #28
Source Project: lams   Author: lamsfoundation   File: InlineIdsOrClauseBulkIdStrategy.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void prepare(
		JdbcServices jdbcServices,
		JdbcConnectionAccess jdbcConnectionAccess,
		MetadataImplementor metadataImplementor,
		SessionFactoryOptions sessionFactoryOptions) {
	// nothing to do
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: AbstractMultiTableBulkIdStrategyImpl.java    License: GNU General Public License v2.0 5 votes vote down vote up
protected String buildIdTableCreateStatement(Table idTable, JdbcServices jdbcServices, MetadataImplementor metadata) {
	final JdbcEnvironment jdbcEnvironment = jdbcServices.getJdbcEnvironment();
	final Dialect dialect = jdbcEnvironment.getDialect();

	StringBuilder buffer = new StringBuilder( getIdTableSupport().getCreateIdTableCommand() )
			.append( ' ' )
			.append( jdbcEnvironment.getQualifiedObjectNameFormatter().format( idTable.getQualifiedTableName(), dialect ) )
			.append( " (" );

	Iterator itr = idTable.getColumnIterator();
	while ( itr.hasNext() ) {
		final Column column = (Column) itr.next();
		buffer.append( column.getQuotedName( dialect ) ).append( ' ' );
		buffer.append( column.getSqlType( dialect, metadata ) );
		if ( column.isNullable() ) {
			buffer.append( dialect.getNullColumnString() );
		}
		else {
			buffer.append( " not null" );
		}
		if ( itr.hasNext() ) {
			buffer.append( ", " );
		}
	}

	buffer.append( ") " );
	if ( getIdTableSupport().getCreateIdTableStatementOptions() != null ) {
		buffer.append( getIdTableSupport().getCreateIdTableStatementOptions() );
	}

	return buffer.toString();
}
 
Example #30
Source Project: hypersistence-optimizer   Author: vladmihalcea   File: AbstractTest.java    License: Apache License 2.0 4 votes vote down vote up
private SessionFactory newSessionFactory() {
    final BootstrapServiceRegistryBuilder bsrb = new BootstrapServiceRegistryBuilder()
        .enableAutoClose();

    final BootstrapServiceRegistry bsr = bsrb.build();

    final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder(bsr)
        .applySettings(properties())
        .build();

    final MetadataSources metadataSources = new MetadataSources(serviceRegistry);

    for (Class annotatedClass : entities()) {
        metadataSources.addAnnotatedClass(annotatedClass);
    }

    String[] packages = packages();
    if (packages != null) {
        for (String annotatedPackage : packages) {
            metadataSources.addPackage(annotatedPackage);
        }
    }

    String[] resources = resources();
    if (resources != null) {
        for (String resource : resources) {
            metadataSources.addResource(resource);
        }
    }

    final MetadataBuilder metadataBuilder = metadataSources.getMetadataBuilder();
    metadataBuilder.enableNewIdentifierGeneratorSupport(true);

    MetadataImplementor metadata = (MetadataImplementor) metadataBuilder.build();

    final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
    Interceptor interceptor = interceptor();
    if (interceptor != null) {
        sfb.applyInterceptor(interceptor);
    }

    return sfb.build();
}