本文整理了Java中org.hibernate.boot.Metadata
类的一些代码示例,展示了Metadata
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata
类的具体详情如下:
包路径:org.hibernate.boot.Metadata
类名称:Metadata
[英]Represents the ORM model as determined from all provided mapping sources. NOTE : for the time being this is essentially a copy of the legacy Mappings contract, split between reading the mapping information exposed here and collecting it via InFlightMetadataCollector
[中]表示根据所有提供的映射源确定的ORM模型。注意:目前这基本上是遗留映射契约的副本,分为读取此处公开的映射信息和通过InFlightMetadataCollector收集信息
代码示例来源:origin: hibernate/hibernate-orm
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding.isInherited() ) {
continue;
final Iterator props = entityBinding.getPropertyClosureIterator();
while ( props.hasNext() ) {
final Property prop = (Property) props.next();
if ( prop.getValue().isSimpleValue() ) {
if ( isLob( ( (SimpleValue) prop.getValue() ).getTypeName() ) ) {
hasLob = true;
break;
entityBinding.setCached( true );
for ( Collection collectionBinding : metadata.getCollectionBindings() ) {
boolean isLob = false;
代码示例来源:origin: hibernate/hibernate-orm
private SessionFactoryImplementor generateSessionFactory() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder()
// should be the default, but lets be specific about which we want to test
.applySetting( AvailableSettings.TRANSACTION_COORDINATOR_STRATEGY, "jdbc" )
.build();
try {
return (SessionFactoryImplementor) new MetadataSources( ssr ).buildMetadata().buildSessionFactory();
}
catch (Exception e) {
StandardServiceRegistryBuilder.destroy( ssr );
throw e;
}
}
代码示例来源:origin: hibernate/hibernate-orm
private SessionFactoryImplementor buildSessionFactory(ExtendedBeanManagerImpl standIn,
NonRegistryManagedBeanConsumingIntegrator beanConsumingIntegrator) {
BootstrapServiceRegistry bsr = new BootstrapServiceRegistryBuilder()
.applyIntegrator( beanConsumingIntegrator )
.build();
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder( bsr )
.applySetting( AvailableSettings.HBM2DDL_AUTO, Action.CREATE_DROP )
.applySetting( AvailableSettings.CDI_BEAN_MANAGER, standIn )
.build();
try {
return (SessionFactoryImplementor) new MetadataSources( ssr )
.addAnnotatedClass( TheEntity.class )
.buildMetadata()
.getSessionFactoryBuilder()
.build();
}
catch (Exception e) {
StandardServiceRegistryBuilder.destroy( ssr );
throw e;
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected void afterMetadataBuilt(Metadata metadata) {
Collection children = metadata.getCollectionBinding( Parent.class.getName() + ".children" );
Component childCompOnents= ( Component ) children.getElement();
Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next();
SQLFunction lengthFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "length" );
if ( lengthFunction != null ) {
ArrayList args = new ArrayList();
args.add( "bio" );
f.setFormula( lengthFunction.render( StandardBasicTypes.INTEGER, args, null ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Override
protected void afterMetadataBuilt(Metadata metadata) {
// Oracle and Postgres do not have year() functions, so we need to
// redefine the 'User.person.yob' formula
//
// consider temporary until we add the capability to define
// mapping formulas which can use dialect-registered functions...
PersistentClass user = metadata.getEntityBinding( User.class.getName() );
org.hibernate.mapping.Property persOnProperty= user.getProperty( "person" );
Component compOnent= ( Component ) personProperty.getValue();
Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
SQLFunction yearFunction = metadata.getDatabase().getJdbcEnvironment().getDialect().getFunctions().get( "year" );
if ( yearFunction == null ) {
// the dialect not know to support a year() function, so rely on the
// ANSI SQL extract function
f.setFormula( "extract( year from dob )");
}
else {
List args = new ArrayList();
args.add( "dob" );
f.setFormula( yearFunction.render( StandardBasicTypes.INTEGER, args, null ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testCollectionAsBasic() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources(ssr).addAnnotatedClass( Post.class )
.getMetadataBuilder().applyBasicType( new DelimitedStringsType() )
.build();
PersistentClass postBinding = metadata.getEntityBinding( Post.class.getName() );
Property tagsAttribute = postBinding.getProperty( "tags" );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testExplicitIncrementGenerator() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources( ssr )
.addAnnotatedClass( ExplicitIncrementGeneratorEntity.class )
.buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding( ExplicitIncrementGeneratorEntity.class.getName() );
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(
bootModel.getIdentifierGeneratorFactory(),
ssr.getService( JdbcEnvironment.class ).getDialect(),
null,
null,
(RootClass) entityMapping
);
assertTyping( IncrementGenerator.class, generator );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNoCircularityDetection() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final Metadata metadata = new MetadataSources( ssr )
.addAnnotatedClass( Entity1.class )
.addAnnotatedClass( Entity2.class )
.buildMetadata();
org.hibernate.mapping.Table entity1Table = metadata.getEntityBinding( Entity1.class.getName() ).getTable();
org.hibernate.mapping.Table entity2Table = metadata.getEntityBinding( Entity2.class.getName() ).getTable();
assertTrue( entity1Table.getName().equals( entity2Table.getName() ) );
assertFalse( entity1Table.getSchema().equals( entity2Table.getSchema() ) );
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
}
代码示例来源:origin: hibernate/hibernate-orm
settings.put(Environment.GENERATE_STATISTICS, "true");
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySettings(settings)
.build();
final PersistentClass customerMapping = metadata.getEntityBinding( Customer.class.getName() );
customerMapping.setCached( true );
((RootClass) customerMapping ).setCacheConcurrencyStrategy( "read-write");
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
sessiOnFactory= (SessionFactoryImplementor) sfb.build();
代码示例来源:origin: com.blazebit/blaze-persistence-integration-hibernate-5
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
for (PersistentClass clazz : metadata.getEntityBindings()) {
Class> entityClass = clazz.getMappedClass();
if (entityClass != null && entityClass.isAnnotationPresent(CTE.class)) {
clazz.getTable().setSubselect("select * from " + clazz.getJpaEntityName());
}
}
serviceRegistry.locateServiceBinding(PersisterClassResolver.class).setService(new CustomPersisterClassResolver());
TableNameFormatter formatter = new NativeTableNameFormatter(sessionFactory.getJdbcServices().getJdbcEnvironment().getQualifiedObjectNameFormatter());
serviceRegistry.locateServiceBinding(Database.class).setService(new SimpleDatabase(getTableIterator(metadata.getDatabase().getNamespaces()), sessionFactory.getDialect(), formatter, metadata));
}
代码示例来源:origin: hibernate/hibernate-orm
private SessionFactoryImplementor buildSessionFactory(Class entityClass, boolean strict) {
final Map settings = new HashMap();
settings.put( AvailableSettings.USE_SECOND_LEVEL_CACHE, "true" );
settings.put( AvailableSettings.JPA_SHARED_CACHE_MODE, SharedCacheMode.ENABLE_SELECTIVE );
settings.put( AvailableSettings.GENERATE_STATISTICS, "true" );
settings.put( AvailableSettings.HBM2DDL_AUTO, "create-drop" );
if ( strict ) {
settings.put( AvailableSettings.JPA_CACHING_COMPLIANCE, "true" );
}
final StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
.applySettings( settings );
return (SessionFactoryImplementor) new MetadataSources( ssrb.build() )
.addAnnotatedClass( Person.class )
.addAnnotatedClass( VersionedPerson.class)
.buildMetadata()
.buildSessionFactory();
}
代码示例来源:origin: hibernate/hibernate-orm
protected SessionFactory sessionFactory(Map
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder()
.applySettings( settings )
.build();
);
final SessionFactoryBuilder sessiOnFactoryBuilder= metadata.getSessionFactoryBuilder();
return sessionFactoryBuilder.build();
代码示例来源:origin: org.infinispan/infinispan-hibernate-cache-commons
private SessionFactory buildSessionFactory() {
StandardServiceRegistryBuilder ssrb = new StandardServiceRegistryBuilder()
.applySetting( Environment.DIALECT, "HSQL" )
.applySetting( Environment.HBM2DDL_AUTO, "create-drop" )
.applySetting( Environment.CONNECTION_PROVIDER, JtaAwareConnectionProviderImpl.class.getName() )
.applySetting( Environment.JNDI_CLASS, "org.jnp.interfaces.NamingContextFactory" )
for ( PersistentClass entityBinding : metadata.getEntityBindings() ) {
if ( entityBinding instanceof RootClass ) {
RootClass rootClass = (RootClass) entityBinding;
for ( Collection collectionBinding : metadata.getCollectionBindings() ) {
collectionBinding.setCacheConcurrencyStrategy( "transactional" );
return metadata.buildSessionFactory();
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue( jiraKey = "HHH-8026" )
public void testUnNamedConstraints() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
final Metadata metadata = new MetadataSources( ssr )
.addAnnotatedClass( UniqueNoNameA.class )
.addAnnotatedClass( UniqueNoNameB.class )
.buildMetadata();
org.hibernate.mapping.Table tableA = null;
org.hibernate.mapping.Table tableB = null;
for ( org.hibernate.mapping.Table table : metadata.collectTableMappings() ) {
if ( table.getName().equals( "UniqueNoNameA" ) ) {
tableA = table;
}
else if ( table.getName().equals( "UniqueNoNameB" ) ) {
tableB = table;
}
}
assertTrue( "Could not find the expected tables.", tableA != null && tableB != null );
assertFalse(
tableA.getUniqueKeyIterator().next().getName().equals(
tableB.getUniqueKeyIterator().next().getName()
)
);
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@TestForIssue( jiraKey = "HHH-9599")
public void basicTest() {
StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
try {
Metadata metadata = new MetadataSources( ssr ).addAnnotatedClass( TestEntity.class ).buildMetadata();
( (MetadataImpl) metadata ).validate();
final PersistentClass entityBinding = metadata.getEntityBinding( TestEntity.class.getName() );
if(metadata.getDatabase().getDialect() instanceof PostgreSQL81Dialect
|| metadata.getDatabase().getDialect() instanceof DB2Dialect){
// See issue HHH-10693 for PostgreSQL, HHH-12753 for DB2
assertEquals(
Types.VARCHAR,
entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
);
}else {
assertEquals(
Types.NVARCHAR,
entityBinding.getProperty( "name" ).getType().sqlTypes( metadata )[0]
);
}
}
finally {
StandardServiceRegistryBuilder.destroy( ssr );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testClassComment() {
StandardServiceRegistryBuilder serviceRegistryBuilder = new StandardServiceRegistryBuilder()
.applySetting("hibernate.dialect", "org.hibernate.dialect.HSQLDialect");
MetadataSources metadataSources = new MetadataSources(serviceRegistryBuilder.build());
metadataSources.addInputStream(new ReaderInputStream(new StringReader(CLASS_COMMENT_HBM_XML)));
Metadata metadata = metadataSources.buildMetadata();
PersistentClass pc = metadata.getEntityBinding("org.hibernate.test.hbm.Foo");
Assert.assertNotNull(pc);
Table table = pc.getTable();
Assert.assertNotNull(table);
Assert.assertEquals("This is class 'Foo' with property 'bar'.", table.getComment());
}
代码示例来源:origin: org.hibernate/hibernate-tools
StandardServiceRegistryBuilder builder = new StandardServiceRegistryBuilder();
Properties properties = (Properties)builder.getSettings();
String defaultCatalog = properties.getProperty(AvailableSettings.DEFAULT_CATALOG);
String defaultSchema = properties.getProperty(AvailableSettings.DEFAULT_SCHEMA);
Iterator
while ( persistentClassIterator.hasNext() ) {
PersistentClass pc = persistentClassIterator.next();
if ( !pc.isInherited() ) {
IdentifierGenerator ig = pc.getIdentifier()
.createIdentifierGenerator(
getMetadata().getIdentifierGeneratorFactory(),
dialect,
defaultCatalog,
Iterator> collectiOnIterator= getMetadata().getCollectionBindings().iterator();
while ( collectionIterator.hasNext() ) {
Collection collection = (Collection) collectionIterator.next();
getMetadata().getIdentifierGeneratorFactory(),
dialect,
defaultCatalog,
代码示例来源:origin: hibernate/hibernate-orm
protected void validateCustomer(Metadata metadata) {
final PersistentClass customerBinding = metadata.getEntityBinding( Customer.class.getName() );
assertNotNull( customerBinding );
validateCustomerPrimaryTableName( customerBinding.getTable().getQuotedName() );
assertEquals( 1, customerBinding.getIdentifier().getColumnSpan() );
validateCustomerPrimaryKeyColumn( (Column) customerBinding.getIdentifier().getColumnIterator().next() );
assertNotNull( customerBinding.getVersion() );
assertEquals( 1, customerBinding.getVersion().getColumnSpan() );
validateCustomerVersionColumn( (Column) customerBinding.getVersion().getColumnIterator().next() );
final Property nameBinding = customerBinding.getProperty( "name" );
assertNotNull( nameBinding );
assertEquals( 1, nameBinding.getColumnSpan() );
validateCustomerNameColumn( (Column) nameBinding.getColumnIterator().next() );
final Property hqAddressBinding = customerBinding.getProperty( "hqAddress" );
assertNotNull( hqAddressBinding );
assertEquals( 3, hqAddressBinding.getColumnSpan() );
validateCustomerHqAddressComponent( assertTyping( Component.class, hqAddressBinding.getValue() ) );
}
代码示例来源:origin: hibernate/hibernate-orm
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()
.configure( "org/hibernate/example/hibernate.cfg.xml" )
.build();
.build();
SessionFactory sessiOnFactory= metadata.getSessionFactoryBuilder()
.applyBeanManager( getBeanManager() )
.build();
.build();
SessionFactoryBuilder sessiOnFactoryBuilder= metadata.getSessionFactoryBuilder();
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testEntityWithMultipleJoinFetchedBags() {
StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder().build();
Metadata metadata = new MetadataSources( standardRegistry )
.addAnnotatedClass( Post.class )
.addAnnotatedClass( PostComment.class )
.addAnnotatedClass( Tag.class )
.getMetadataBuilder()
.build();
try {
metadata.buildSessionFactory();
fail( "MultipleBagFetchException should have been thrown." );
}
catch (MultipleBagFetchException expected) {
}
}