Esempio n. 1
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();
  }
Esempio n. 2
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();
 }