public static boolean saveOrUpdate(CategorySurveyProxy proxy) {
   boolean result = false;
   DaoSession session = SageApplication.getInstance().getDaoSession();
   SurveyService surveyService = new SurveyService(session);
   ElementService elementService = new ElementService(session);
   SageApplication.getInstance().getDatabase().beginTransaction();
   try { // main survey must already be saved (this will be the case)
     for (VegetationSurveyProxy survey : proxy.getCanopies()) {
       if (survey.getStationElements() != null && survey.getStationElements().size() > 0) {
         // Save the survey
         survey.setRoot(proxy);
         surveyService.saveOrUpdate(survey);
         // save the elements
         elementService.saveOrUpdate(survey.getStationElements(), survey.getModel());
       } else {
         new ElementService(session).delete(survey.getModel());
       }
     }
     SageApplication.getInstance().getDatabase().setTransactionSuccessful();
     result = true;
   } catch (Exception e) {
     result = false;
   } finally {
     SageApplication.getInstance().getDatabase().endTransaction();
   }
   return result;
 }
 private static VegetationSurveyProxy findOrBuildCanopy(Station parent, String canopyName) {
   Station canopyStation =
       new StationService(SageApplication.getInstance().getDaoSession())
           .getSubstation(parent, VegetationGlobals.STATION_TYPE_VEGETATION_CANOPY, canopyName);
   if (canopyStation == null) return buildCanopy(canopyName);
   else return buildCanopy(canopyStation);
 }
 private static VegetationSurveyProxy buildCanopy(Station station) {
   VegetationSurveyProxy result = new VegetationSurveyProxy();
   result.setModel(station);
   ElementService es = new ElementService(SageApplication.getInstance().getDaoSession());
   List<StationElement> stationElements = es.findStationElements(station);
   if (stationElements != null)
     result.setStationElements(es.convertFromStationElements(stationElements));
   return result;
 }