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 File: PersistentTableBulkIdStrategy.java    From lams with 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 #2
Source File: GlobalTemporaryTableBulkIdStrategy.java    From lams with 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 #3
Source File: GlobalTemporaryTableBulkIdStrategy.java    From lams with 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 #4
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 #5
Source File: LocalTemporaryTableBulkIdStrategy.java    From lams with 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 File: PersistentTableBulkIdStrategy.java    From lams with 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 #7
Source File: SchemaValidator.java    From lams with 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 #8
Source File: SchemaExport.java    From lams with 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 #9
Source File: SchemaUpdate.java    From lams with 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 #10
Source File: InlineIdsSubSelectValueListBulkIdStrategy.java    From lams with 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 #11
Source File: InlineIdsOrClauseBulkIdStrategy.java    From lams with 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 #12
Source File: EntityManagerFactoryBuilderImpl.java    From lams with 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 #13
Source File: HibernateMetadataExtractor.java    From mPaaS with 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 #14
Source File: AbstractMultiTableBulkIdStrategyImpl.java    From lams with 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 #15
Source File: CteValuesListBulkIdStrategy.java    From lams with 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 #16
Source File: MetadataBuilderImpl.java    From lams with 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 #17
Source File: SessionFactoryBuilderImpl.java    From lams with 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 #18
Source File: EventListenerRegistryImpl.java    From lams with 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 #19
Source File: InlineIdsInClauseBulkIdStrategy.java    From lams with 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 #20
Source File: SchemaUpdate.java    From lams with 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 #21
Source File: SchemaDropperImpl.java    From lams with 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 #22
Source File: SchemaDropperImpl.java    From lams with 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 #23
Source File: AbstractSchemaMigrator.java    From lams with 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 #24
Source File: OneToOne.java    From lams with 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 #25
Source File: SchemaCreatorImpl.java    From lams with 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 #26
Source File: SchemaCreatorImpl.java    From lams with 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 #27
Source File: SchemaValidator.java    From lams with 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 #28
Source File: SchemaExport.java    From lams with 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 #29
Source File: SchemaExport.java    From lams with 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 #30
Source File: HibernateMetadata.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public static MetadataImplementor getMetadataImplementor()
{
    return metadataImplementor.get();
}