use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class DiscriminatorMultiTenancyTest method setUp.
@Before
public void setUp() {
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.DISCRIMINATOR);
settings.put(Environment.MULTI_TENANT_IDENTIFIER_RESOLVER, currentTenantResolver);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
ServiceRegistryImplementor serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
Metadata metadata = ms.buildMetadata();
final PersistentClass customerMapping = metadata.getEntityBinding(Customer.class.getName());
customerMapping.setCached(true);
((RootClass) customerMapping).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
connectionProvider = ConnectionProviderBuilder.buildConnectionProvider();
final GenerationTargetToDatabase target = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, connectionProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, target);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, target);
target.release();
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class AbstractSchemaBasedMultiTenancyTest method setUp.
@Before
public void setUp() {
T multiTenantConnectionProvider = buildMultiTenantConnectionProvider();
Map settings = new HashMap();
settings.put(Environment.MULTI_TENANT, MultiTenancyStrategy.SCHEMA);
settings.put(Environment.CACHE_REGION_FACTORY, CachingRegionFactory.class.getName());
settings.put(Environment.GENERATE_STATISTICS, "true");
serviceRegistry = (ServiceRegistryImplementor) new StandardServiceRegistryBuilder().applySettings(settings).addService(MultiTenantConnectionProvider.class, multiTenantConnectionProvider).build();
MetadataSources ms = new MetadataSources(serviceRegistry);
ms.addAnnotatedClass(Customer.class);
ms.addAnnotatedClass(Invoice.class);
Metadata metadata = ms.buildMetadata();
final PersistentClass customerMapping = metadata.getEntityBinding(Customer.class.getName());
customerMapping.setCached(true);
((RootClass) customerMapping).setCacheConcurrencyStrategy("read-write");
HibernateSchemaManagementTool tool = new HibernateSchemaManagementTool();
tool.injectServices(serviceRegistry);
final GenerationTargetToDatabase acmeTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, acmeProvider));
final GenerationTargetToDatabase jbossTarget = new GenerationTargetToDatabase(new DdlTransactionIsolatorTestingImpl(serviceRegistry, jbossProvider));
new SchemaDropperImpl(serviceRegistry).doDrop(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
new SchemaCreatorImpl(serviceRegistry).doCreation(metadata, serviceRegistry, settings, true, acmeTarget, jbossTarget);
final SessionFactoryBuilder sfb = metadata.getSessionFactoryBuilder();
configure(sfb);
sessionFactory = (SessionFactoryImplementor) sfb.build();
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class VersionsJoinTableRangeComponentNamingTest method testOverrideNotAudited.
/**
* Verify that
* {@link VersionsJoinTableRangeComponentTestEntity#getComponent3()} is
* partially audited.
*/
@Test
public void testOverrideNotAudited() {
PersistentClass auditClass = metadata().getEntityBinding(VersionsJoinTableRangeComponentTestEntity.class.getName() + "_AUD");
assert auditClass != null;
@SuppressWarnings({ "unchecked" }) Iterator<Column> columns = auditClass.getTable().getColumnIterator();
boolean auditColumn1Found = false;
boolean auditColumn2Found = false;
while (columns.hasNext()) {
Column column = columns.next();
if ("STR1".equals(column.getName())) {
auditColumn1Found = true;
}
if ("STR2".equals(column.getName())) {
auditColumn2Found = true;
}
}
assert auditColumn1Found && !auditColumn2Found;
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class EntitiesConfigurator method configure.
public EntitiesConfigurations configure(MetadataImplementor metadata, ServiceRegistry serviceRegistry, ReflectionManager reflectionManager, MappingCollector mappingCollector, GlobalConfiguration globalConfiguration, AuditEntitiesConfiguration auditEntitiesConfiguration, AuditStrategy auditStrategy, Document revisionInfoXmlMapping, Element revisionInfoRelationMapping) {
// Creating a name register to capture all audit entity names created.
final AuditEntityNameRegister auditEntityNameRegister = new AuditEntityNameRegister();
// Sorting the persistent class topologically - superclass always before subclass
final Iterator<PersistentClass> classes = GraphTopologicalSort.sort(new PersistentClassGraphDefiner(metadata)).iterator();
final ClassesAuditingData classesAuditingData = new ClassesAuditingData();
final Map<PersistentClass, EntityXmlMappingData> xmlMappings = new HashMap<>();
// Reading metadata from annotations
while (classes.hasNext()) {
final PersistentClass pc = classes.next();
// Ensure we're in POJO, not dynamic model, mapping.
if (pc.getClassName() != null) {
// Collecting information from annotations on the persistent class pc
final AnnotationsMetadataReader annotationsMetadataReader = new AnnotationsMetadataReader(globalConfiguration, reflectionManager, pc);
final ClassAuditingData auditData = annotationsMetadataReader.getAuditData();
classesAuditingData.addClassAuditingData(pc, auditData);
}
}
// Now that all information is read we can update the calculated fields.
classesAuditingData.updateCalculatedFields();
final AuditMetadataGenerator auditMetaGen = new AuditMetadataGenerator(metadata, serviceRegistry, globalConfiguration, auditEntitiesConfiguration, auditStrategy, revisionInfoRelationMapping, auditEntityNameRegister);
// First pass
for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
final PersistentClass pc = pcDatasEntry.getKey();
final ClassAuditingData auditData = pcDatasEntry.getValue();
final EntityXmlMappingData xmlMappingData = new EntityXmlMappingData();
if (auditData.isAudited()) {
if (!StringTools.isEmpty(auditData.getAuditTable().value())) {
auditEntitiesConfiguration.addCustomAuditTableName(pc.getEntityName(), auditData.getAuditTable().value());
}
auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, true);
} else {
auditMetaGen.generateFirstPass(pc, auditData, xmlMappingData, false);
}
xmlMappings.put(pc, xmlMappingData);
}
// Second pass
for (Map.Entry<PersistentClass, ClassAuditingData> pcDatasEntry : classesAuditingData.getAllClassAuditedData()) {
final EntityXmlMappingData xmlMappingData = xmlMappings.get(pcDatasEntry.getKey());
if (pcDatasEntry.getValue().isAudited()) {
auditMetaGen.generateSecondPass(pcDatasEntry.getKey(), pcDatasEntry.getValue(), xmlMappingData);
try {
mappingCollector.addDocument(xmlMappingData.getMainXmlMapping());
for (Document additionalMapping : xmlMappingData.getAdditionalXmlMappings()) {
mappingCollector.addDocument(additionalMapping);
}
} catch (DocumentException e) {
throw new MappingException(e);
}
}
}
// Only if there are any versioned classes
if (auditMetaGen.getEntitiesConfigurations().size() > 0) {
try {
if (revisionInfoXmlMapping != null) {
mappingCollector.addDocument(revisionInfoXmlMapping);
}
} catch (DocumentException e) {
throw new MappingException(e);
}
}
return new EntitiesConfigurations(auditMetaGen.getEntitiesConfigurations(), auditMetaGen.getNotAuditedEntitiesConfigurations());
}
use of org.hibernate.mapping.PersistentClass in project hibernate-orm by hibernate.
the class GeneratedValueTests method baseline.
@Test
public void baseline() {
final StandardServiceRegistry ssr = new StandardServiceRegistryBuilder().build();
final Metadata bootModel = new MetadataSources(ssr).addAnnotatedClass(ExplicitGeneratorEntity.class).buildMetadata();
final PersistentClass entityMapping = bootModel.getEntityBinding(ExplicitGeneratorEntity.class.getName());
final IdentifierGenerator generator = entityMapping.getIdentifier().createIdentifierGenerator(bootModel.getIdentifierGeneratorFactory(), ssr.getService(JdbcEnvironment.class).getDialect(), null, null, (RootClass) entityMapping);
final SequenceStyleGenerator sequenceStyleGenerator = assertTyping(SequenceStyleGenerator.class, generator);
assertThat(sequenceStyleGenerator.getDatabaseStructure().getName(), is("my_real_db_sequence"));
// all the JPA defaults since they were not defined
assertThat(sequenceStyleGenerator.getDatabaseStructure().getInitialValue(), is(100));
assertThat(sequenceStyleGenerator.getDatabaseStructure().getIncrementSize(), is(500));
}
Aggregations