|
Hibernate example source code file (EntityMappingsMocker.java)
The Hibernate EntityMappingsMocker.java source code/* * Hibernate, Relational Persistence for Idiomatic Java * * Copyright (c) 2011, Red Hat Inc. or third-party contributors as * indicated by the @author tags or express copyright attribution * statements applied by the authors. All third-party contributions are * distributed under license by Red Hat Inc.. * * This copyrighted material is made available to anyone wishing to use, modify, * copy, or redistribute it subject to the terms and conditions of the GNU * Lesser General Public License, as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License * for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this distribution; if not, write to: * Free Software Foundation, Inc. * 51 Franklin Street, Fifth Floor * Boston, MA 02110-1301 USA */ package org.hibernate.metamodel.source.annotations.xml.mocker; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import org.jboss.jandex.Index; import org.jboss.logging.Logger; import org.hibernate.internal.CoreMessageLogger; import org.hibernate.metamodel.source.annotation.jaxb.XMLAccessType; import org.hibernate.metamodel.source.annotation.jaxb.XMLEmbeddable; import org.hibernate.metamodel.source.annotation.jaxb.XMLEntity; import org.hibernate.metamodel.source.annotation.jaxb.XMLEntityMappings; import org.hibernate.metamodel.source.annotation.jaxb.XMLMappedSuperclass; import org.hibernate.metamodel.source.annotation.jaxb.XMLPersistenceUnitDefaults; import org.hibernate.metamodel.source.annotation.jaxb.XMLPersistenceUnitMetadata; import org.hibernate.service.ServiceRegistry; /** * Parse all {@link XMLEntityMappings} generated from orm.xml. * * @author Strong Liu */ public class EntityMappingsMocker { private static final CoreMessageLogger LOG = Logger.getMessageLogger( CoreMessageLogger.class, EntityMappingsMocker.class.getName() ); private final List<XMLEntityMappings> entityMappingsList; /** * Default configuration defined in Persistence Metadata Unit, one or zero per Persistence Unit. */ private Default globalDefaults; private final IndexBuilder indexBuilder; private final GlobalAnnotations globalAnnotations; public EntityMappingsMocker(List<XMLEntityMappings> entityMappingsList, Index index, ServiceRegistry serviceRegistry) { this.entityMappingsList = entityMappingsList; this.indexBuilder = new IndexBuilder( index, serviceRegistry ); this.globalAnnotations = new GlobalAnnotations(); } /** * Create new {@link Index} with mocking JPA annotations from {@link XMLEntityMappings} and merge them with existing {@link Index} * * @return new {@link Index} */ public Index mockNewIndex() { processPersistenceUnitMetadata( entityMappingsList ); processEntityMappings( entityMappingsList ); processGlobalAnnotations(); return indexBuilder.build( globalDefaults ); } /** * processing PersistenceUnitMetadata, there should be only one PersistenceUnitMetadata in all mapping xml files. */ private void processPersistenceUnitMetadata(List<XMLEntityMappings> entityMappingsList) { for ( XMLEntityMappings entityMappings : entityMappingsList ) { //we have to iterate entityMappingsList first to find persistence-unit-metadata XMLPersistenceUnitMetadata pum = entityMappings.getPersistenceUnitMetadata(); if ( globalDefaults != null ) { LOG.duplicateMetadata(); return; } if ( pum == null ) { continue; } globalDefaults = new Default(); if ( pum.getXmlMappingMetadataComplete() != null ) { globalDefaults.setMetadataComplete( true ); indexBuilder.mappingMetadataComplete(); } XMLPersistenceUnitDefaults pud = pum.getPersistenceUnitDefaults(); if ( pud == null ) { return; } globalDefaults.setSchema( pud.getSchema() ); globalDefaults.setCatalog( pud.getCatalog() ); //globalDefaults.setAccess( pud.getAccess() ); globalDefaults.setCascadePersist( pud.getCascadePersist() != null ); new PersistenceMetadataMocker( indexBuilder, pud ).process(); } } private void processEntityMappings(List<XMLEntityMappings> entityMappingsList) { List<AbstractEntityObjectMocker> mockerList = new ArrayList Other Hibernate examples (source code examples)Here is a short list of links related to this Hibernate EntityMappingsMocker.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.