Java Code Examples for org.hibernate.mapping.PersistentClass#isInherited()

The following examples show how to use org.hibernate.mapping.PersistentClass#isInherited() . 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: InFlightMetadataCollectorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void processExportableProducers() {
	// for now we only handle id generators as ExportableProducers

	final Dialect dialect = getDatabase().getJdbcEnvironment().getDialect();
	final String defaultCatalog = extractName( getDatabase().getDefaultNamespace().getName().getCatalog(), dialect );
	final String defaultSchema = extractName( getDatabase().getDefaultNamespace().getName().getSchema(), dialect );

	for ( PersistentClass entityBinding : entityBindingMap.values() ) {
		if ( entityBinding.isInherited() ) {
			continue;
		}

		handleIdentifierValueBinding(
				entityBinding.getIdentifier(),
				dialect,
				defaultCatalog,
				defaultSchema,
				(RootClass) entityBinding
		);
	}

	for ( Collection collection : collectionBindingMap.values() ) {
		if ( !IdentifierCollection.class.isInstance( collection ) ) {
			continue;
		}

		handleIdentifierValueBinding(
				( (IdentifierCollection) collection ).getIdentifier(),
				dialect,
				defaultCatalog,
				defaultSchema,
				null
		);
	}
}
 
Example 2
Source File: ExecutionEnvironment.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void applyCacheSettings(Configuration configuration) {
	if ( settings.getCacheConcurrencyStrategy() != null ) {
		Iterator iter = configuration.getClassMappings();
		while ( iter.hasNext() ) {
			PersistentClass clazz = (PersistentClass) iter.next();
			Iterator props = clazz.getPropertyClosureIterator();
			boolean hasLob = false;
			while ( props.hasNext() ) {
				Property prop = (Property) props.next();
				if ( prop.getValue().isSimpleValue() ) {
					String type = ( ( SimpleValue ) prop.getValue() ).getTypeName();
					if ( "blob".equals(type) || "clob".equals(type) ) {
						hasLob = true;
					}
					if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) {
						hasLob = true;
					}
				}
			}
			if ( !hasLob && !clazz.isInherited() && settings.overrideCacheStrategy() ) {
				configuration.setCacheConcurrencyStrategy( clazz.getEntityName(), settings.getCacheConcurrencyStrategy() );
			}
		}
		iter = configuration.getCollectionMappings();
		while ( iter.hasNext() ) {
			Collection coll = (Collection) iter.next();
			configuration.setCollectionCacheConcurrencyStrategy( coll.getRole(), settings.getCacheConcurrencyStrategy() );
		}
	}
}
 
Example 3
Source File: HibernateL2CacheStrategySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + TIMESTAMP_CACHE, TIMESTAMP_CACHE);
    builder.applySetting(REGION_CACHE_PROPERTY + QUERY_CACHE, QUERY_CACHE);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}
 
Example 4
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = registryBuilder();

    for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    // Use the same cache for Entity and Entity2.
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    StandardServiceRegistry srvcRegistry = builder.build();

    MetadataSources metadataSources = new MetadataSources(srvcRegistry);

    for (Class entityClass : getAnnotatedClasses())
        metadataSources.addAnnotatedClass(entityClass);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
        collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName() );

    return metadata.buildSessionFactory();
}
 
Example 5
Source File: HibernateL2CacheStrategySelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * @param accessType Cache access typr.
 * @param igniteInstanceName Name of the grid providing caches.
 * @return Session factory.
 */
private SessionFactory startHibernate(AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();

    builder.applySetting("hibernate.connection.url", CONNECTION_URL);

    for (Map.Entry<String, String> e : HibernateL2CacheSelfTest.hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    builder.applySetting(USE_STRUCTURED_CACHE, "true");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY1_NAME, "cache1");
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, "cache2");
    builder.applySetting(REGION_CACHE_PROPERTY + DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME, DEFAULT_UPDATE_TIMESTAMPS_REGION_UNQUALIFIED_NAME);
    builder.applySetting(REGION_CACHE_PROPERTY + DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME, DEFAULT_QUERY_RESULTS_REGION_UNQUALIFIED_NAME);

    MetadataSources metadataSources = new MetadataSources(builder.build());

    metadataSources.addAnnotatedClass(Entity1.class);
    metadataSources.addAnnotatedClass(Entity2.class);
    metadataSources.addAnnotatedClass(Entity3.class);
    metadataSources.addAnnotatedClass(Entity4.class);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass)entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    return metadata.buildSessionFactory();
}
 
Example 6
Source File: HibernateL2CacheSelfTest.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Starts Hibernate.
 *
 * @param accessType Cache access type.
 * @param igniteInstanceName Ignite instance name.
 * @return Session factory.
 */
private SessionFactory startHibernate(org.hibernate.cache.spi.access.AccessType accessType, String igniteInstanceName) {
    StandardServiceRegistryBuilder builder = registryBuilder();

    for (Map.Entry<String, String> e : hibernateProperties(igniteInstanceName, accessType.name()).entrySet())
        builder.applySetting(e.getKey(), e.getValue());

    // Use the same cache for Entity and Entity2.
    builder.applySetting(REGION_CACHE_PROPERTY + ENTITY2_NAME, ENTITY_NAME);

    StandardServiceRegistry srvcRegistry = builder.build();

    MetadataSources metadataSources = new MetadataSources(srvcRegistry);

    for (Class entityClass : getAnnotatedClasses())
        metadataSources.addAnnotatedClass(entityClass);

    Metadata metadata = metadataSources.buildMetadata();

    for (PersistentClass entityBinding : metadata.getEntityBindings()) {
        if (!entityBinding.isInherited())
            ((RootClass) entityBinding).setCacheConcurrencyStrategy(accessType.getExternalName());
    }

    for (org.hibernate.mapping.Collection collectionBinding : metadata.getCollectionBindings())
        collectionBinding.setCacheConcurrencyStrategy(accessType.getExternalName());

    return metadata.buildSessionFactory();
}
 
Example 7
Source File: TestCase.java    From cacheonix-core with GNU Lesser General Public License v2.1 4 votes vote down vote up
private void buildSessionFactory() throws Exception {
	if ( getSessions()!=null ) {
		getSessions().close();
	}

	TestCase.dialect = Dialect.getDialect();
	if ( ! appliesTo( getDialect() ) ) {
		return;
	}

	try {

		TestCase.cfg = new Configuration();
		cfg.setProperty( Environment.CACHE_PROVIDER, "org.hibernate.cache.HashtableCacheProvider" );
		if( recreateSchema() ) {
			cfg.setProperty( Environment.HBM2DDL_AUTO, "create-drop" );
		}
		addMappings( getMappings(), cfg );
		configure( cfg );

		if ( getCacheConcurrencyStrategy() != null ) {
			Iterator iter = cfg.getClassMappings();
			while ( iter.hasNext() ) {
				PersistentClass clazz = (PersistentClass) iter.next();
				Iterator props = clazz.getPropertyClosureIterator();
				boolean hasLob = false;
				while ( props.hasNext() ) {
					Property prop = (Property) props.next();
					if ( prop.getValue().isSimpleValue() ) {
						String type = ( (SimpleValue) prop.getValue() ).getTypeName();
						if ( "blob".equals(type) || "clob".equals(type) ) hasLob = true;
						if ( Blob.class.getName().equals(type) || Clob.class.getName().equals(type) ) hasLob = true;
					}
				}
				if ( !hasLob && !clazz.isInherited() && overrideCacheStrategy() ) {
					cfg.setCacheConcurrencyStrategy(
							clazz.getEntityName(),
							getCacheConcurrencyStrategy()
						);
				}
			}
			iter = cfg.getCollectionMappings();
			while ( iter.hasNext() ) {
				Collection coll = (Collection) iter.next();
				cfg.setCollectionCacheConcurrencyStrategy(
						coll.getRole(),
						getCacheConcurrencyStrategy()
					);
			}
		}

		// make sure we use the same dialect...
		cfg.setProperty( Environment.DIALECT, TestCase.dialect.getClass().getName() );
		TestCase.sessions = cfg.buildSessionFactory();
		afterSessionFactoryBuilt();
	}
	catch ( Exception e ) {
		e.printStackTrace();
		throw e;
	}
}