コード例 #1
0
 private void bindFilterDefinitions() {
   if (hibernateMapping.getFilterDef() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLFilterDef filterDefinition : hibernateMapping.getFilterDef()) {
     final String name = filterDefinition.getName();
     final Map<String, Type> parameters = new HashMap<String, Type>();
     String condition = null;
     for (Object o : filterDefinition.getContent()) {
       if (o instanceof String) {
         // represents the condition
         if (condition != null) {
           // log?
         }
         condition = (String) o;
       } else if (o instanceof XMLHibernateMapping.XMLFilterDef.XMLFilterParam) {
         final XMLHibernateMapping.XMLFilterDef.XMLFilterParam paramElement =
             (XMLHibernateMapping.XMLFilterDef.XMLFilterParam) o;
         // todo : should really delay this resolution until later to allow typedef names
         parameters.put(
             paramElement.getName(),
             metadata.getTypeResolver().heuristicType(paramElement.getType()));
       } else {
         throw new MappingException("Unrecognized nested filter content", jaxbRoot.getOrigin());
       }
     }
     if (condition == null) {
       condition = filterDefinition.getCondition();
     }
     metadata.addFilterDefinition(new FilterDefinition(name, condition, parameters));
   }
 }
コード例 #2
0
 private void bindDatabaseObjectDefinitions() {
   if (hibernateMapping.getDatabaseObject() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLDatabaseObject databaseObjectElement :
       hibernateMapping.getDatabaseObject()) {
     final AuxiliaryDatabaseObject auxiliaryDatabaseObject;
     if (databaseObjectElement.getDefinition() != null) {
       final String className = databaseObjectElement.getDefinition().getClazz();
       try {
         auxiliaryDatabaseObject =
             (AuxiliaryDatabaseObject) classLoaderService().classForName(className).newInstance();
       } catch (ClassLoadingException e) {
         throw e;
       } catch (Exception e) {
         throw new MappingException(
             "could not instantiate custom database object class [" + className + "]",
             jaxbRoot.getOrigin());
       }
     } else {
       Set<String> dialectScopes = new HashSet<String>();
       if (databaseObjectElement.getDialectScope() != null) {
         for (XMLHibernateMapping.XMLDatabaseObject.XMLDialectScope dialectScope :
             databaseObjectElement.getDialectScope()) {
           dialectScopes.add(dialectScope.getName());
         }
       }
       auxiliaryDatabaseObject =
           new BasicAuxiliaryDatabaseObjectImpl(
               databaseObjectElement.getCreate(), databaseObjectElement.getDrop(), dialectScopes);
     }
     metadata.addAuxiliaryDatabaseObject(auxiliaryDatabaseObject);
   }
 }
コード例 #3
0
 private void bindIdentifierGenerators() {
   if (hibernateMapping.getIdentifierGenerator() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLIdentifierGenerator identifierGeneratorElement :
       hibernateMapping.getIdentifierGenerator()) {
     metadata.registerIdentifierGenerator(
         identifierGeneratorElement.getName(), identifierGeneratorElement.getClazz());
   }
 }
コード例 #4
0
 private void bindImports() {
   if (hibernateMapping.getImport() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLImport importValue : hibernateMapping.getImport()) {
     String className = getClassName(importValue.getClazz());
     String rename = importValue.getRename();
     rename = (rename == null) ? StringHelper.unqualify(className) : rename;
     metadata.addImport(className, rename);
   }
 }
コード例 #5
0
 private void bindTypeDefinitions() {
   if (hibernateMapping.getTypedef() == null) {
     return;
   }
   for (XMLHibernateMapping.XMLTypedef typedef : hibernateMapping.getTypedef()) {
     final Map<String, String> parameters = new HashMap<String, String>();
     for (XMLParamElement paramElement : typedef.getParam()) {
       parameters.put(paramElement.getName(), paramElement.getValue());
     }
     metadata.addTypeDefinition(new TypeDef(typedef.getName(), typedef.getClazz(), parameters));
   }
 }
コード例 #6
0
 public void bindFetchProfiles(
     List<XMLFetchProfileElement> fetchProfiles, String containingEntityName) {
   for (XMLFetchProfileElement fetchProfile : fetchProfiles) {
     String profileName = fetchProfile.getName();
     Set<FetchProfile.Fetch> fetches = new HashSet<FetchProfile.Fetch>();
     for (XMLFetchProfileElement.XMLFetch fetch : fetchProfile.getFetch()) {
       String entityName = fetch.getEntity() == null ? containingEntityName : fetch.getEntity();
       if (entityName == null) {
         throw new MappingException(
             "could not determine entity for fetch-profile fetch ["
                 + profileName
                 + "]:["
                 + fetch.getAssociation()
                 + "]",
             jaxbRoot.getOrigin());
       }
       fetches.add(new FetchProfile.Fetch(entityName, fetch.getAssociation(), fetch.getStyle()));
     }
     metadata.addFetchProfile(new FetchProfile(profileName, fetches));
   }
 }
コード例 #7
0
  public HibernateMappingProcessor(
      MetadataImplementor metadata, JaxbRoot<XMLHibernateMapping> jaxbRoot) {
    this.metadata = metadata;
    this.jaxbRoot = jaxbRoot;

    this.hibernateMapping = jaxbRoot.getRoot();
    this.mappingDefaults =
        new OverriddenMappingDefaults(
            metadata.getMappingDefaults(),
            hibernateMapping.getPackage(),
            hibernateMapping.getSchema(),
            hibernateMapping.getCatalog(),
            null,
            null,
            hibernateMapping.getDefaultCascade(),
            hibernateMapping.getDefaultAccess(),
            hibernateMapping.isDefaultLazy());

    autoImport = hibernateMapping.isAutoImport();

    metaAttributeContext = extractMetaAttributes();
  }
コード例 #8
0
 private static void bind(
     String name, String typeClass, Map<String, String> prms, MetadataImplementor metadata) {
   LOG.debugf("Binding type definition: %s", name);
   metadata.addTypeDefinition(new TypeDef(name, typeClass, prms));
 }
コード例 #9
0
 private ClassLoaderService classLoaderService() {
   if (classLoaderService == null) {
     classLoaderService = metadata.getServiceRegistry().getService(ClassLoaderService.class);
   }
   return classLoaderService;
 }
コード例 #10
0
 @Override
 public JavaType makeJavaType(String className) {
   return metadata.makeJavaType(className);
 }
コード例 #11
0
 @Override
 public <T> Class<T> locateClassByName(String name) {
   return metadata.locateClassByName(name);
 }
コード例 #12
0
 @Override
 public boolean isGloballyQuotedIdentifiers() {
   return metadata.isGloballyQuotedIdentifiers();
 }
コード例 #13
0
 @Override
 public NamingStrategy getNamingStrategy() {
   return metadata.getOptions().getNamingStrategy();
 }
コード例 #14
0
 @Override
 public ServiceRegistry getServiceRegistry() {
   return metadata.getServiceRegistry();
 }
コード例 #15
0
 private MetaAttributeContext extractMetaAttributes() {
   return hibernateMapping.getMeta() == null
       ? new MetaAttributeContext(metadata.getMetaAttributeContext())
       : HbmHelper.extractMetaAttributeContext(
           hibernateMapping.getMeta(), true, metadata.getMetaAttributeContext());
 }