/**
   * Retrieves the transient properties
   *
   * @param domainClass The owning domain class
   * @return A list of transient properties
   */
  private List getTransients(GrailsDomainClass domainClass) {
    List transientProps;
    transientProps = (List) domainClass.getPropertyValue(TRANSIENT, List.class);

    // Undocumented feature alert! Steve insisted on this :-)
    List evanescent = (List) domainClass.getPropertyValue(EVANESCENT, List.class);
    if (evanescent != null) {
      if (transientProps == null) transientProps = new ArrayList();

      transientProps.addAll(evanescent);
    }
    return transientProps;
  }
  /** Overrides the default behaviour to including binding of Grails domain classes. */
  @Override
  protected void secondPassCompile() throws MappingException {
    final Thread currentThread = Thread.currentThread();
    final ClassLoader originalContextLoader = currentThread.getContextClassLoader();
    if (!configLocked) {
      if (LOG.isDebugEnabled())
        LOG.debug(
            "[GrailsAnnotationConfiguration] ["
                + domainClasses.size()
                + "] Grails domain classes to bind to persistence runtime");

      // do Grails class configuration
      configureDomainBinder(binder, grailsApplication, domainClasses);

      for (GrailsDomainClass domainClass : domainClasses) {

        final String fullClassName = domainClass.getFullName();

        String hibernateConfig = fullClassName.replace('.', '/') + ".hbm.xml";
        final ClassLoader loader = originalContextLoader;
        // don't configure Hibernate mapped classes
        if (loader.getResource(hibernateConfig) != null) continue;

        final Mappings mappings = super.createMappings();
        if (!GrailsHibernateUtil.usesDatasource(domainClass, dataSourceName)) {
          continue;
        }

        LOG.debug(
            "[GrailsAnnotationConfiguration] Binding persistent class [" + fullClassName + "]");

        Mapping m = binder.getMapping(domainClass);
        mappings.setAutoImport(m == null || m.getAutoImport());
        binder.bindClass(domainClass, mappings, sessionFactoryBeanName);
      }
    }

    try {
      currentThread.setContextClassLoader(grailsApplication.getClassLoader());
      super.secondPassCompile();
      createSubclassForeignKeys();
    } finally {
      currentThread.setContextClassLoader(originalContextLoader);
    }

    configLocked = true;
  }
  /* (non-Javadoc)
   * @see org.grails.orm.hibernate.cfg.GrailsDomainConfiguration#addDomainClass(org.codehaus.groovy.grails.commons.GrailsDomainClass)
   */
  public GrailsDomainConfiguration addDomainClass(GrailsDomainClass domainClass) {
    if (shouldMapWithGorm(domainClass)) {
      domainClasses.add(domainClass);
    } else {
      addAnnotatedClass(domainClass.getClazz());
    }

    return this;
  }
  /** Evaluates the fetchmode */
  private void establishFetchMode() {

    Map fetchMap =
        (Map) domainClass.getPropertyValue(GrailsDomainClassProperty.FETCH_MODE, Map.class);
    if (fetchMap != null && fetchMap.containsKey(this.name)) {
      if ("eager".equals(fetchMap.get(this.name))) {
        this.fetchMode = FETCH_EAGER;
      }
    }
  }
  public DefaultGrailsDomainClassProperty(
      GrailsDomainClass domainClass, PropertyDescriptor descriptor) {
    this.domainClass = domainClass;
    // persistant by default
    this.persistant = true;
    this.name = descriptor.getName();
    this.naturalName = GrailsNameUtils.getNaturalName(descriptor.getName());
    this.type = descriptor.getPropertyType();
    this.identity = descriptor.getName().equals(IDENTITY);

    // establish if property is persistant
    if (domainClass != null) {
      // figure out if this property is inherited
      if (!domainClass.isRoot()) {
        this.inherited = GrailsClassUtils.isPropertyInherited(domainClass.getClazz(), this.name);
      }
      List transientProps = getTransients(domainClass);
      checkIfTransient(transientProps);

      establishFetchMode();
    }
  }
 private boolean shouldMapWithGorm(GrailsDomainClass domainClass) {
   return !AnnotationDomainClassArtefactHandler.isJPADomainClass(domainClass.getClazz())
       && domainClass.getMappingStrategy().equalsIgnoreCase(GrailsDomainClass.GORM);
 }
 public void setReferencedDomainClass(GrailsDomainClass referencedDomainClass) {
   if (referencedDomainClass != null) {
     this.referencedDomainClass = referencedDomainClass;
     this.referencedPropertyType = referencedDomainClass.getClazz();
   }
 }
 /* (non-Javadoc)
  * @see org.codehaus.groovy.grails.domain.GrailsDomainClassProperty#isRequired()
  */
 public boolean isOptional() {
   ConstrainedProperty constrainedProperty =
       (ConstrainedProperty) domainClass.getConstrainedProperties().get(name);
   return (constrainedProperty != null) && constrainedProperty.isNullable();
 }