amberpersistenceunit.java

来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,802 行 · 第 1/3 页

JAVA
1,802
字号
      return entityType;    // ejb/0al2    // entityType = (EntityType) _typeManager.get(beanClass.getName());    if (entityType == null) {      // The parent type can be a @MappedSuperclass or an @EntityType.      EntityType parentType = null;      for (Class parentClass = beanClass.getSuperclass();           parentType == null && parentClass != null;           parentClass = parentClass.getSuperclass()) {        parentType = (EntityType) _typeManager.get(parentClass.getName());      }      if (parentType != null)        entityType = new SubEntityType(this, parentType);      else        entityType = new EntityType(this);    }    // _typeManager.put(name, entityType);    _typeManager.put(name, entityType);    // XXX: some confusion about the double entry    if (_typeManager.get(beanClass.getName()) == null)      _typeManager.put(beanClass.getName(), entityType);    entityType.setName(name);    entityType.setBeanClass(beanClass);    _lazyConfigure.add(entityType);    // getEnvManager().addLazyConfigure(entityType);    AmberEntityHome entityHome = _entityHomeMap.get(beanClass.getName());    if (entityHome == null) {      entityHome = new AmberEntityHome(this, entityType);      _lazyHomeInit.add(entityHome);      _isInit = false;    }    addEntityHome(name, entityHome);    // XXX: some confusion about the double entry, related to the EJB 3.0    // confuction of named instances.    addEntityHome(beanClass.getName(), entityHome);    return entityType;  }  /**   * Adds an entity.   */  public MappedSuperclassType createMappedSuperclass(String name,                                                     Class beanClass)  {    MappedSuperclassType mappedSuperType      = (MappedSuperclassType) _typeManager.get(name);    if (mappedSuperType != null)      return mappedSuperType;    mappedSuperType = new MappedSuperclassType(this);    _typeManager.put(name, mappedSuperType);    // XXX: some confusion about the double entry    if (_typeManager.get(beanClass.getName()) == null)      _typeManager.put(beanClass.getName(), mappedSuperType);    _mappedSuperclassTypes.add(mappedSuperType);    mappedSuperType.setName(name);    mappedSuperType.setBeanClass(beanClass);    return mappedSuperType;  }  /**   * Adds an embeddable type.   */  public EmbeddableType createEmbeddable(Class beanClass)  {    return createEmbeddable(beanClass.getName(), beanClass);  }  /**   * Adds an embeddable type.   */  public EmbeddableType createEmbeddable(String name,                                         Class beanClass)  {    AmberType type = _typeManager.get(name);    if (type != null && ! (type instanceof EmbeddableType))      throw new ConfigException(L.l("'{0}' is not a valid embeddable type",				    name));        EmbeddableType embeddableType;    embeddableType = (EmbeddableType) type;    if (embeddableType != null)      return embeddableType;    embeddableType = new EmbeddableType(this);    _typeManager.put(name, embeddableType);    // XXX: some confusion about the double entry    if (_typeManager.get(beanClass.getName()) == null)      _typeManager.put(beanClass.getName(), embeddableType);    embeddableType.setName(name);    embeddableType.setBeanClass(beanClass);    _embeddableTypes.add(embeddableType);    _amberContainer.addEmbeddable(beanClass.getName(), embeddableType);    return embeddableType;  }  /**   * Adds an enumerated type.   */  public EnumType createEnum(String name,                             Class beanClass)  {    EnumType enumType = (EnumType) _typeManager.get(name);    if (enumType != null)      return enumType;    enumType = new EnumType();    _typeManager.put(name, enumType);    // XXX: some confusion about the double entry    if (_typeManager.get(beanClass.getName()) == null)      _typeManager.put(beanClass.getName(), enumType);    enumType.setName(name);    enumType.setBeanClass(beanClass);    return enumType;  }  /**   * Gets a default listener.   */  public ListenerType getDefaultListener(String className)  {    return _amberContainer.getDefaultListener(className);  }  /**   * Adds a default listener.   */  public ListenerType addDefaultListener(Class beanClass)  {    ListenerType listenerType = getListener(beanClass);    if (! _defaultListeners.contains(listenerType)) {      _defaultListeners.add(listenerType);      _amberContainer.addDefaultListener(beanClass.getName(),                                         listenerType);    }    return listenerType;  }  /**   * Gets an entity listener.   */  public ListenerType getEntityListener(String className)  {    return _amberContainer.getEntityListener(className);  }  /**   * Adds an entity listener.   */  public ListenerType addEntityListener(String entityName,                                        Class listenerClass)  {    ListenerType listenerType = getListener(listenerClass);    _amberContainer.addEntityListener(entityName,                                      listenerType);    return listenerType;  }  private ListenerType getListener(Class beanClass)  {    String name = beanClass.getName();    ListenerType listenerType = (ListenerType) _typeManager.get(name);    if (listenerType != null)      return listenerType;    listenerType = new ListenerType(this);    ListenerType parentType = null;    for (Class parentClass = beanClass.getSuperclass();         parentType == null && parentClass != null;         parentClass = parentClass.getSuperclass()) {      parentType = (ListenerType) _typeManager.get(parentClass.getName());    }    if (parentType != null)      listenerType = new SubListenerType(this, parentType);    else      listenerType = new ListenerType(this);    _typeManager.put(name, listenerType);    listenerType.setName(name);    listenerType.setBeanClass(beanClass);    return listenerType;  }  /**   * Adds a new home bean.   */  private void addEntityHome(String name, AmberEntityHome home)  {    _entityHomeMap.put(name, home);    // getEnvManager().addEntityHome(name, home);  }  /**   * Returns a table generator.   */  public IdGenerator getTableGenerator(String name)  {    return _tableGenMap.get(name);  }  /**   * Sets a table generator.   */  public IdGenerator putTableGenerator(String name, IdGenerator gen)  {    synchronized (_tableGenMap) {      IdGenerator oldGen = _tableGenMap.get(name);      if (oldGen != null)        return oldGen;      else {        _tableGenMap.put(name, gen);        return gen;      }    }  }  /**   * Adds a generator table.   */  public GeneratorTableType createGeneratorTable(String name)  {    AmberType type = _typeManager.get(name);    if (type instanceof GeneratorTableType)      return (GeneratorTableType) type;    if (type != null)      throw new RuntimeException(L.l("'{0}' is a duplicate generator table.",                                     type));    GeneratorTableType genType = new GeneratorTableType(this, name);    _typeManager.put(name, genType);    // _lazyGenerate.add(genType);    return genType;  }  /**   * Returns a sequence generator.   */  public SequenceIdGenerator createSequenceGenerator(String name, int size)    throws ConfigException  {    synchronized (_sequenceGenMap) {      SequenceIdGenerator gen = _sequenceGenMap.get(name);      if (gen == null) {        gen = new SequenceIdGenerator(this, name, size);        _sequenceGenMap.put(name, gen);      }      return gen;    }  }  /**   * Configures a type.   */  public void initType(AbstractEnhancedType type)    throws Exception  {    type.init();    getGenerator().generate(type);  }  /**   * Configure lazy.   */  public void generate()    throws Exception  {    configure();    AbstractEnhancedType type = null;    try {      for (MappedSuperclassType mappedType : _mappedSuperclassTypes) {	type = mappedType;	        initType(mappedType);      }      while (_lazyGenerate.size() > 0) {        EntityType entityType = _lazyGenerate.remove(0);	type = entityType;        // Entity        initType(entityType);        ArrayList<ListenerType> listeners;        String className = entityType.getBeanClass().getName();        listeners = _amberContainer.getEntityListeners(className);        if (listeners == null)          continue;        // Entity Listeners        for (ListenerType listenerType : listeners) {	  type = listenerType;	            initType(listenerType);	}      }      // Embeddable      for (EmbeddableType embeddableType : _embeddableTypes) {	type = embeddableType;	        initType(embeddableType);      }      // Default Listeners      for (ListenerType listenerType : _defaultListeners) {	type = listenerType;	        initType(listenerType);      }    } catch (Exception e) {      if (type != null) {        type.setConfigException(e);        _amberContainer.addEntityException(type.getBeanClass().getName(), e);      }      throw e;    }    try {      getGenerator().compile();    } catch (Exception e) {      _amberContainer.addException(e);      throw e;    }  }  /**   * Gets the JPA flag.   */  public boolean isJPA()  {    return _isJPA;  }  /**   * Sets the JPA flag.   */  public void setJPA(boolean isJPA)  {    _isJPA = isJPA;  }  /**   * Configure lazy.   */  public void generate(JavaClassGenerator javaGen)    throws Exception  {    configure();    while (_lazyGenerate.size() > 0) {      EntityType type = _lazyGenerate.remove(0);      type.init();      if (type instanceof EntityType) {        EntityType entityType = (EntityType) type;        if (! entityType.isGenerated()) {          if (entityType.getInstanceClassName() == null)            throw new ConfigException(L.l("'{0}' does not have a configured instance class.",                                          entityType));          entityType.setGenerated(true);          try {            getGenerator().generateJava(javaGen, entityType);          } catch (Exception e) {            log.log(Level.FINER, e.toString(), e);          }        }      }      configure();    }    for (EmbeddableType embeddableType : _embeddableTypes) {      embeddableType.init();      if (! embeddableType.isGenerated()) {        if (embeddableType.getInstanceClassName() == null)          throw new ConfigException(L.l("'{0}' does not have a configured instance class.",                                        embeddableType));        embeddableType.setGenerated(true);        try {          getGenerator().generateJava(javaGen, embeddableType);        } catch (Exception e) {          log.log(Level.FINER, e.toString(), e);        }      }    }    for (SequenceIdGenerator gen : _sequenceGenMap.values())      gen.init(this);    while (_defaultListeners.size() > 0) {      ListenerType type = _defaultListeners.remove(0);      type.init();      if (! type.isGenerated()) {        if (type.getInstanceClassName() == null)          throw new ConfigException(L.l("'{0}' does not have a configured instance class.",                                        type));        type.setGenerated(true);        try {          getGenerator().generateJava(javaGen, type);        } catch (Exception e) {          log.log(Level.FINER, e.toString(), e);        }      }    }  }  /**   * Returns the @Embeddable introspector.   */  public EmbeddableIntrospector getEmbeddableIntrospector()  {    return _embeddableIntrospector;  }  /**   * Configure lazy.   */  public void configure()    throws Exception  {    //_embeddableIntrospector.configure();    //_mappedSuperIntrospector.configure();    _configManager.configure();    while (_lazyConfigure.size() > 0) {      EntityType type = _lazyConfigure.remove(0);      if (type.startConfigure()) {        // getEnvManager().getGenerator().configure(type);      }      _configManager.configure();      if (! _lazyGenerate.contains(type))        _lazyGenerate.add(type);    }    updateFlushPriority();  }  /**   * Returns the entity home.   */  public AmberEntityHome getEntityHome(String name)  {    if (! _isInit) {      try {        initEntityHomes();      } catch (RuntimeException e) {        throw e;      } catch (Exception e) {        throw new AmberRuntimeException(e);      }    }    return _entityHomeMap.get(name);  }  /**   * Returns the entity home by the schema name.   */  public AmberEntityHome getHomeBySchema(String name)  {    for (AmberEntityHome home : _entityHomeMap.values()) {      if (name.equals(home.getEntityType().getName()))        return home;    }    try {      createType(name);    } catch (Exception e) {    }    return _entityHomeMap.get(name);  }  /**   * Returns a matching embeddable type.   */  public EmbeddableType getEmbeddable(String className)  {    AmberType type = _typeManager.get(className);    if (type instanceof EmbeddableType)      return (EmbeddableType) type;    else      return null;  }  public EntityType getEntityType(Class cl)  {    return getEntityType(cl.getName());  }    /**   * Returns a matching entity.   */  public EntityType getEntityType(String className)  {    AmberType type = _typeManager.get(className);    if (type instanceof EntityType)      return (EntityType) type;    else      return null;  }  /**   * Returns a matching mapped superclass.   */  public MappedSuperclassType getMappedSuperclass(String className)  {    AmberType type = _typeManager.get(className);    if (type instanceof MappedSuperclassType)      return (MappedSuperclassType) type;    return null;  }  /**   * Returns a matching entity.   */  public EntityType getEntityByInstanceClass(String className)  {    return _typeManager.getEntityByInstanceClass(className);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?