コード例 #1
0
  @Path("/updatetype")
  @POST
  public XMLEntityMappings updateType(XMLEntityMappings entityMappings) throws Exception {
    String name = null;
    if (!entityMappings.getEntities().isEmpty()) {

      EntityAccessor entityAccessor = entityMappings.getEntities().get(0);
      name = entityAccessor.getName();
      name = Utils.upperFirstLetter(name);
      entityAccessor.setName(name);
      entityAccessor.setClassName(name);
      JpaMapHelper.replaceClassAccessor(DynamicMetaSource.getEntityMaps(), entityAccessor);
    } else if (!entityMappings.getEmbeddables().isEmpty()) {

      EmbeddableAccessor embeddableAccessor = entityMappings.getEmbeddables().get(0);
      name = embeddableAccessor.getName();
      name = Utils.upperFirstLetter(name);
      embeddableAccessor.setName(name);
      embeddableAccessor.setClassName(name);
      JpaMapHelper.replaceClassAccessor(DynamicMetaSource.getEntityMaps(), embeddableAccessor);
    }
    DynamicMetaSource.normalize();
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return getSingleType(name);
  }
コード例 #2
0
  public XMLEntityMappings saveProp(XMLEntityMappings entityMappings, boolean refreshPu)
      throws Exception {
    String name = null;
    if (!entityMappings.getEntities().isEmpty()) {
      EntityAccessor entityAccessor = entityMappings.getEntities().get(0);
      name = entityAccessor.getName();
      int index = 0;
      for (EntityAccessor entityAccessor2 : DynamicMetaSource.getEntityMaps().getEntities()) {
        if (entityAccessor2.getName().equalsIgnoreCase(name)) {
          break;
        }
        index++;
      }
      DynamicMetaSource.getEntityMaps().getEntities().remove(index);

      DynamicMetaSource.getEntityMaps().getEntities().add(entityAccessor);
    } else if (!entityMappings.getEmbeddables().isEmpty()) {
      EmbeddableAccessor embeddableAccessor = entityMappings.getEmbeddables().get(0);
      name = embeddableAccessor.getName();

      int index = 0;
      for (EmbeddableAccessor embeddableAccessor2 :
          DynamicMetaSource.getEntityMaps().getEmbeddables()) {
        if (embeddableAccessor2.getName().equalsIgnoreCase(name)) {
          break;
        }
        index++;
      }
      DynamicMetaSource.getEntityMaps().getEmbeddables().remove(index);
      DynamicMetaSource.getEntityMaps().getEmbeddables().add(embeddableAccessor);
    }
    DynamicMetaSource.normalize();
    if (refreshPu) {
      App.getPersistenceUnit().refresh(false);
    }
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return getSingleType(name);
  }
コード例 #3
0
  @POST
  @Path("savetype")
  public XMLEntityMappings save(XMLEntityMappings entityMappings) throws Exception {
    String name = null;
    if (!entityMappings.getEntities().isEmpty()) {

      EntityAccessor entityAccessor = entityMappings.getEntities().get(0);
      name = entityAccessor.getName();
      name = Utils.upperFirstLetter(name);
      entityAccessor.setName(name);
      entityAccessor.setClassName(name);

      DynamicMetaSource.getEntityMaps().getEntities().add(entityAccessor);
      if (entityAccessor.getParentClassName().equals(FleximsDynamicEntityImpl.class.getName())) {
        MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
        MetaSourceBuilder.addVersion(entityAccessor);
      } else {
        boolean foundParent = false;
        EntityAccessor parent = null;
        for (EntityAccessor entityAccessor1 : DynamicMetaSource.getEntityMaps().getEntities()) {
          if (entityAccessor1
              .getClassName()
              .equalsIgnoreCase(entityAccessor.getParentClassName())) {
            parent = entityAccessor1;
            break;
          }
        }

        if (parent != null) {
          foundParent = true;
          MetaSourceBuilder.establishInheritance(entityAccessor, parent);
        } else {
          for (MappedSuperclassAccessor entityAccessor2 :
              DynamicMetaSource.getEntityMaps().getMappedSuperclasses()) {
            if (entityAccessor2
                .getClassName()
                .equalsIgnoreCase(entityAccessor.getParentClassName())) {
              foundParent = true;
              break;
            }
          }
          MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
          MetaSourceBuilder.addVersion(entityAccessor);
        }

        if (!foundParent) {
          // ignore parent from client.
          entityAccessor.setParentClassName(FleximsDynamicEntityImpl.class.getName());
          MetaSourceBuilder.addID(entityAccessor, DynamicMetaSource.getEntityMaps());
          MetaSourceBuilder.addVersion(entityAccessor);
        }
      }

    } else if (!entityMappings.getEmbeddables().isEmpty()) {

      EmbeddableAccessor embeddableAccessor = entityMappings.getEmbeddables().get(0);
      name = embeddableAccessor.getName();
      name = Utils.upperFirstLetter(name);
      embeddableAccessor.setName(name);
      embeddableAccessor.setClassName(name);
      DynamicMetaSource.getEntityMaps().getEmbeddables().add(embeddableAccessor);
    }

    DynamicMetaSource.normalize();
    App.getPersistenceUnit().refresh(false);
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return getSingleType(name);
  }