@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(); }
public Attribute<?, ?> getAttribute() { if (attr != null) { return attr; } Metamodel metamodel = App.getPersistenceUnit().getEMF().getMetamodel(); ManagedType<?> type = JpaMetamodelHelper.getManagedType(metamodel, query.getQueryType()); attr = JpaMetamodelHelper.getAttribute(type, getProp()); return attr; }
@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(); }
@Path("/checkname/{typename}") @GET public AppMsg checkTypeName(@PathParam("typename") String typeName) throws Exception { Connection con = App.getConnection(); String msg = TypeUtil.validateTypeName(typeName, con, false); con.close(); AppMsg ret = new AppMsg(); if (msg != null) { ret.setStatuscode(1); ret.setMsg(msg); } return ret; }
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); }
@Path("/schema") @GET @Produces(MediaType.TEXT_PLAIN) public String getSchema() throws Exception { return App.getPersistenceUnit().getSchema(); }
@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); }