@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> listByIdsNotManaged(List<Long> objIdList) { String sql = getResourceSQL("GeoObjectDao.listByIdsNotManaged"); List<Object[]> rows = getCurrentSession() .createSQLQuery(sql.toString()) .addScalar("id", StandardBasicTypes.LONG) .addScalar("name", StandardBasicTypes.STRING) .addScalar("created_by", StandardBasicTypes.LONG) .addScalar("changed_by", StandardBasicTypes.LONG) .addScalar("created", StandardBasicTypes.DATE) .addScalar("changed", StandardBasicTypes.DATE) .addScalar("fias_code", StandardBasicTypes.STRING) .addScalar("the_geom", GeometryUserType.TYPE) .addScalar("version", StandardBasicTypes.INTEGER) .setParameterList("ids", objIdList) .list(); if (rows != null && rows.size() > 0) { GeoObject[] objects = new GeoObject[rows.size()]; for (int j = 0; j < rows.size(); j++) { GeoObject obj = new GeoObject(); Object[] row = rows.get(j); obj.setId((Long) row[0]); obj.setVersion((Integer) row[8]); Geometry geom = (Geometry) row[7]; obj.setTheGeom(geom); obj.setName((String) row[1]); obj.setChanged((Date) row[5]); obj.setCreated((Date) row[4]); obj.setFiasCode((String) row[6]); objects[j] = obj; } return Arrays.asList(objects); } return new ArrayList<GeoObject>(); }