示例#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
  @Path("deleteprop/{typename}/{propname}")
  @GET
  public XMLEntityMappings deleteProp(
      @PathParam("typename") String typeName, @PathParam("propname") String propName)
      throws Exception {
    ClassAccessor entity =
        JpaMapHelper.findClassAccessor(DynamicMetaSource.getEntityMaps(), typeName);
    Attribute<?, ?> attr = JpaMetamodelHelper.getAttribute(typeName, propName);
    if (JpaMapHelper.findPropertyBbyMappedBy(
            JpaMetamodelHelper.getAttributeType(attr).getSimpleName(), propName)
        != null) {
      throw new CodedExceptionImpl(
          PROP_REFERED,
          "Deletion can not be performed. Target Property is referred by other types");
    }

    EntityManager eManager = App.getEM();
    eManager.getTransaction().begin();
    Connection connection = eManager.unwrap(Connection.class);
    for (String sql : JpaHelper.deletePropDBStructure(eManager, typeName, propName)) {
      LOGGER.info(sql);
      connection.createStatement().execute(sql);
    }
    eManager.getTransaction().commit();
    JpaMapHelper.deleteProp(entity, propName);
    App.getPersistenceUnit().refresh(false);
    mapPersister.save(DynamicMetaSource.getEntityMaps());
    return DynamicMetaSource.getEntityMaps();
  }
示例#3
0
 @Path("deletetype/{typename}")
 @GET
 public XMLEntityMappings deleteType(@PathParam("typename") String typeName) throws Exception {
   List<Attribute<?, ?>> attrs = JpaMetamodelHelper.findReferringProps(typeName, true);
   if (!attrs.isEmpty()) {
     throw new CodedExceptionImpl(
         TYPE_REFERED, "Deletion can not be performed. Target type is referred by other types");
   }
   EntityManager eManager = App.getEM();
   eManager.getTransaction().begin();
   Connection connection = eManager.unwrap(Connection.class);
   for (String sql : JpaHelper.deletePropDBStructure(eManager, typeName)) {
     LOGGER.info(sql);
     connection.createStatement().execute(sql);
   }
   eManager.getTransaction().commit();
   JpaMapHelper.deleteClassAccessor(DynamicMetaSource.getEntityMaps(), typeName);
   App.getPersistenceUnit().refresh(false);
   mapPersister.save(DynamicMetaSource.getEntityMaps());
   return DynamicMetaSource.getEntityMaps();
 }
示例#4
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);
  }
示例#5
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);
  }