@SuppressWarnings("unchecked") @Override public List<GeoObject> listByLayerIdWithTags(Long layerId) { List<GeoObject> objs = (List<GeoObject>) getCurrentSession() .createQuery( ("Select o from GeoLayer l inner join l.geoObjects o left join fetch o.geoObjectProperties p left join fetch o.createdBy cb left join fetch o.changedBy chb where l.id = :layerId")) .setLong("layerId", layerId) .list(); if (objs.size() == 0) return objs; List<GeoObjectTag> tags = getCurrentSession() .createQuery( "SELECT t from GeoObjectTag t join t.geoObject o join o.geoLayers l where l.id = :layerId") .setLong("layerId", layerId) .list(); for (GeoObject obj : objs) { HashSet<GeoObjectTag> fetchedTags = new HashSet<GeoObjectTag>(); for (GeoObjectTag tag : tags) { if (tag.getGeoObject().getId() == obj.getId()) { fetchedTags.add(tag); } } obj.setTags(fetchedTags); } return objs; }
@Override @CacheEvict(value = "objectPermanent", allEntries = true) public void cloneObjectListToLayer( List<Long> objIdList, Long targetLayerId, GeoUser currentGeoUser) { List<GeoObject> originalObjects = listByIds(objIdList); for (GeoObject orig : originalObjects) { GeoObject obj = orig.clone(); obj.setId(null); HashSet<GeoObjectTag> objectTags = new HashSet<GeoObjectTag>(); for (GeoObjectTag prop : orig.getTags()) { GeoObjectTag tag = new GeoObjectTag(); tag.setKey(prop.getKey()); tag.setValue(prop.getValue()); tag.setGeoObject(obj); objectTags.add(tag); } obj.setTags(objectTags); obj.setCreatedBy(currentGeoUser); obj.setCreated(Calendar.getInstance().getTime()); getCurrentSession() .createSQLQuery( "INSERT INTO geo_layer_to_object (layer_id, object_id) VALUES(:lId, :oId)") .setLong("oId", add(obj).getId()) .setLong("lId", targetLayerId) .executeUpdate(); } }
@SuppressWarnings("unchecked") @Override public List<GeoObject> listByLayerIdFromRevision(Long layerId, Long revId) { List<GeoObject> objs = (List<GeoObject>) getCurrentSession() .createSQLQuery(getResourceSQL("GeoObjectDao.listByLayerIdFromRevision")) .addEntity(GeoObject.class) .setLong("layerId", layerId) .setLong("revId", revId) .list(); if (objs.size() == 0) return objs; List<GeoObjectTag> tags = getCurrentSession() .createQuery("from GeoObjectTag t where t.geoObject in :objs") .setParameterList("objs", objs) .list(); for (GeoObject obj : objs) { HashSet<GeoObjectTag> fetchedTags = new HashSet<GeoObjectTag>(); for (GeoObjectTag tag : tags) { if (tag.getGeoObject().getId() == obj.getId()) { fetchedTags.add(tag); } } obj.setTags(fetchedTags); } return objs; /* for(GeoObject obj : objs){ List<GeoObjectTag> tags = getCurrentSession().createQuery("from GeoObjectTag t where t.geoObject = :obj").setEntity("obj", obj).list(); obj.setTags(new HashSet<GeoObjectTag>(tags)); } return objs; */ }