Esempio n. 1
0
 @Autowired
 public void setDataSource(DataSource dataSource) {
   jdbcInsert = new SimpleJdbcInsert(dataSource);
   jdbcInsert.setTableName("tb_user");
   jdbcInsert.setGeneratedKeyName("user_id");
   jdbcTemplate = new JdbcTemplate(dataSource);
 }
Esempio n. 2
0
  @Override
  public long save(MisoPrintService printService) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params
        .addValue("serviceName", printService.getName())
        .addValue("contextName", printService.getPrintContext().getName())
        .addValue("enabled", printService.isEnabled())
        .addValue("printServiceFor", printService.getPrintServiceFor().getName());
    try {
      JSONObject contextFields =
          PrintServiceUtils.mapContextFieldsToJSON(printService.getPrintContext());
      String contextFieldJSON = contextFields.toString();
      params.addValue("contextFields", contextFieldJSON);
    } catch (IllegalAccessException e) {
      e.printStackTrace();
    }

    if (printService.getServiceId() == -1) {
      SimpleJdbcInsert insert =
          new SimpleJdbcInsert(template)
              .withTableName(TABLE_NAME)
              .usingGeneratedKeyColumns("serviceId");
      Number newId = insert.executeAndReturnKey(params);
      printService.setServiceId(newId.longValue());
    } else {
      params.addValue("serviceId", printService.getServiceId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(PRINT_SERVICE_UPDATE, params);
    }
    return printService.getServiceId();
  }
  @Override
  public Ride addRide(Ride ride) throws Exception {
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("status", ride.getStatus());
    parameters.put("origin_lat", ride.getOriginLat());
    parameters.put("origin_long", ride.getOriginLong());
    parameters.put("dest_lat", ride.getDestLat());
    parameters.put("dest_long", ride.getDestLong());
    parameters.put("start_datetime", ride.getStartDatetime());
    parameters.put("end_datetime", ride.getEndDatetime());
    parameters.put("fare", ride.getFare());
    parameters.put("rider_rate_quality", ride.getRiderRateQuality());
    parameters.put("rider_rate_msg", ride.getRiderRateMsg());
    parameters.put("driver_rate_quality", ride.getDriverRateQuality());
    parameters.put("driver_rate_msg", ride.getDriverRateMsg());
    parameters.put("riders_rider_id", ride.getRidersRiderId());
    parameters.put("drivers_driver_id", ride.getDriversDriverId());

    SimpleJdbcInsert insert =
        new SimpleJdbcInsert(ds).withTableName("rides").usingGeneratedKeyColumns("ride_id");

    Number newId = insert.executeAndReturnKey(parameters);
    ride.setRideId(newId.intValue());
    return ride;
  }
 @Override
 public void save(Guest... guests) {
   SimpleJdbcInsert insertStmt = new SimpleJdbcInsert(jdbc).withTableName("guest");
   for (Guest guest : guests) {
     BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(guest);
     insertStmt.execute(params);
   }
 }
 @Override
 public void insert(Transaction transaction) throws SQLException {
   logger.debug("Inserting transaction with type [{}]", transaction.getFlockId());
   Map<String, Object> valuesToInsert = new HashMap<String, Object>();
   valuesToInsert.put("FlockID", transaction.getFlockId());
   valuesToInsert.put("Name", transaction.getName());
   valuesToInsert.put("Expenses", transaction.getExpenses());
   valuesToInsert.put("Revenues", transaction.getRevenues());
   jdbcInsert.setGeneratedKeyName("ID");
   jdbcInsert.execute(valuesToInsert);
 }
Esempio n. 6
0
  private Vehicle insert(Vehicle vehicle) {
    SimpleJdbcInsert insert =
        new SimpleJdbcInsert(template).withTableName("vehicles").usingGeneratedKeyColumns("id");

    SqlParameterSource parameters =
        new MapSqlParameterSource()
            .addValue("manufacturer", vehicle.getManufacturer())
            .addValue("model", vehicle.getModel());

    Number id = insert.executeAndReturnKey(parameters);
    vehicle.setId(id.intValue());

    return vehicle;
  }
 @AuditTrail
 public Invoice create(final Invoice invoice) {
   SimpleJdbcInsert insert =
       new SimpleJdbcInsert(dataSource).withTableName("invoice").usingGeneratedKeyColumns("id");
   Map<String, Object> parameters = new HashMap<String, Object>();
   parameters.put("account_id", invoice.getAccountId().intValue());
   parameters.put("period_from", invoice.getPeriodFrom());
   parameters.put("period_to", invoice.getPeriodTo());
   parameters.put("sent_time", invoice.getSentTime());
   parameters.put("state", invoice.getState());
   LOG.debug(parameters.toString());
   Number id = insert.executeAndReturnKey(parameters);
   invoice.setId(BigInteger.valueOf(id.longValue()));
   return invoice;
 }
Esempio n. 8
0
  private String saveTxn(TransactionVO currentTransaction) throws ParseException {
    insertTransaction =
        new SimpleJdbcInsert(getDataSource())
            .withTableName("transaction")
            .usingGeneratedKeyColumns("id");

    SqlParameterSource parameters =
        new MapSqlParameterSource()
            .addValue("dateReported", getMySQLSaveDate(currentTransaction.getDateReported()))
            .addValue("customerId", currentTransaction.getCustomerId())
            .addValue("productCategory", currentTransaction.getProductCategory())
            .addValue("makeId", currentTransaction.getMakeId())
            .addValue("modelId", currentTransaction.getModelId())
            .addValue("serialNo", currentTransaction.getSerialNo())
            .addValue("accessories", currentTransaction.getAccessories())
            .addValue("complaintReported", currentTransaction.getComplaintReported())
            .addValue("complaintDiagnosed", currentTransaction.getComplaintDiagonsed())
            .addValue("engineerRemarks", currentTransaction.getEnggRemark())
            .addValue("repairAction", currentTransaction.getRepairAction())
            .addValue("note", currentTransaction.getNotes())
            .addValue("status", currentTransaction.getStatus())
            .addValue("createdOn", currentTransaction.getCreatedOn())
            .addValue("modifiedOn", currentTransaction.getModifiedOn())
            .addValue("createdBy", currentTransaction.getCreatedBy())
            .addValue("modifiedBy", currentTransaction.getModifiedBy());
    Number newId = insertTransaction.executeAndReturnKey(parameters);
    LOG.info(" the queryForInt resulted in  " + newId.longValue());
    currentTransaction.setId(newId.longValue());
    // update the tag No
    String tagNo = "WON2N" + newId.longValue();
    String query = "update transaction set TagNo = '" + tagNo + "' where id =" + newId.longValue();
    getJdbcTemplate().update(query);
    return tagNo;
  }
Esempio n. 9
0
  public void addTeam(Team team) {
    SimpleJdbcInsert insertTeam = new SimpleJdbcInsert(getDataSource()).withTableName("teams");

    Map<String, Object> teamParameters = new HashMap<String, Object>(5);
    teamParameters.put("teamid", team.getTeamId());
    teamParameters.put("location", team.getLocation());
    teamParameters.put("abbreviation", team.getAbbreviation());
    teamParameters.put("displayname", team.getDisplayName());
    teamParameters.put("venueid", team.getVenue().getVenueId());

    try {
      insertTeam.execute(teamParameters);
    } catch (DataIntegrityViolationException divex) {
      log.warning("Duplicate entry");
    }
  }
Esempio n. 10
0
  public void saveRelapse(final Relapse relapse) throws Exception {
    Map<String, Object> relapseMap =
        new HashMap<String, Object>() {
          {
            put("relID", relapse.getId());
            put("RADAR_NO", relapse.getRadarNumber());
            put("DATE_ONSET_RELAP", relapse.getDateOfRelapse());
            put(
                "RELAP_TX_NAT",
                relapse.getTransplantedNative() != null
                    ? relapse.getTransplantedNative().getId()
                    : null);
            put("TRIG_VIRAL", relapse.getViralTrigger());
            put("TRIG_IMMUN", relapse.getImmunisationTrigger());
            put("TRIG_OTHER", relapse.getOtherTrigger());
            put("RELAP_DRUG_1", relapse.getDrug1());
            put("RELAP_DRUG_2", relapse.getDrug2());
            put("RELAP_DRUG_3", relapse.getDrug3());
            put(
                "REMISS_ACHIEVE",
                relapse.getRemissionAchieved() != null
                    ? relapse.getRemissionAchieved().getId()
                    : null);
            put("DATE_REMISSION", relapse.getDateOfRemission());
            put("SEQ_NO", relapse.getSequenceNumber());
          }
        };

    simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Relapse");
    simpleJdbcInsert.execute(relapseMap);
  }
  /**
   * Add a new TournamentEnrollment to the database
   *
   * @param enrollment the enrollment to be added
   */
  public void addEnrollment(TournamentEnrollment enrollment) {
    SimpleJdbcInsert insertEnrollment =
        new SimpleJdbcInsert(getDataSource()).withTableName("tournament_enrollments");

    Map<String, Object> parameters = new HashMap<String, Object>(3);
    parameters.put("tournamentId", enrollment.getTournamentid());
    parameters.put("fantasy_teamId", enrollment.getTeamId());
    parameters.put("score", enrollment.getScore());

    try {
      insertEnrollment.execute(parameters);
    } catch (DataIntegrityViolationException divx) {
      String msg = "Duplicate entry";
      log.warning(msg);
    }
  }
Esempio n. 12
0
  public void addGame(Game game) throws GameServiceException {
    SimpleJdbcInsert insertGame = new SimpleJdbcInsert(getDataSource()).withTableName("games");
    Map<String, Object> gameParameters = new HashMap<String, Object>(5);
    gameParameters.put("gameid", game.getGameId());
    gameParameters.put("startTime", game.getStartTime());
    gameParameters.put("teamHomeid", game.getTeamHome().getTeamId());
    gameParameters.put("teamAwayid", game.getTeamAway().getTeamId());
    gameParameters.put("venueid", game.getVenue().getVenueId());

    try {
      insertGame.execute(gameParameters);
    } catch (DataIntegrityViolationException divex) {
      log.warning("Duplicate entry");
      throw new GameServiceException(divex.getMessage(), divex);
    }
  }
Esempio n. 13
0
 public static void insert(
     DataSource dataSource,
     String tableName,
     List<String> usingColumns,
     List<Map<String, Object>> fields) {
   SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert(dataSource);
   jdbcInsert.withTableName(tableName);
   List<String> pp = new ArrayList<>();
   pp.addAll(usingColumns);
   pp.add(tableName + "_id");
   jdbcInsert.usingColumns(pp.toArray(new String[usingColumns.size()]));
   for (Map<String, Object> field : fields) {
     field.put(tableName + "_id", UUID.randomUUID().toString());
   }
   Map<String, Object>[] batch = fields.toArray(new Map[fields.size()]);
   jdbcInsert.executeBatch(batch);
 }
Esempio n. 14
0
 /** {@inheritDoc} */
 @Override
 public void insert(Relay relay) {
   logger.debug("Inserting relay with id [{}]", relay.getId());
   Map<String, Object> valuesToInsert = new HashMap<String, Object>();
   valuesToInsert.put("id", relay.getId());
   valuesToInsert.put("name", relay.getText());
   jdbcInsert.execute(valuesToInsert);
 }
Esempio n. 15
0
  public synchronized CookingRecipe insertCookingRecipe(CookingRecipe recipe) throws Exception {
    System.out.println("Database: insertCookingRecipe(" + recipe + ")");
    SimpleJdbcInsert insert = new SimpleJdbcInsert(jdbcTemplate);
    insert.withTableName("recipes");
    insert.setGeneratedKeyName("id");
    Map<String, Object> mapa = new HashMap<String, Object>();
    mapa.put("recipe_name", recipe.getName());
    mapa.put("author", recipe.getAuthor());
    mapa.put("guide", recipe.getGuide());
    // mapa.put("incident_ID", incidentID);
    Number insertedRecipeId = insert.executeAndReturnKey(mapa);
    recipe.setId(insertedRecipeId.longValue());

    insertIngredients(recipe.getIngredients(), insertedRecipeId.longValue());
    for (CookingIngredient ci : recipe.getIngredients()) {
      ci.setRecipe_id(insertedRecipeId.longValue());
    }
    return recipe;
  }
Esempio n. 16
0
  public long saveGroup(Group group) throws IOException {
    MapSqlParameterSource params = new MapSqlParameterSource();
    params.addValue("name", group.getName()).addValue("description", group.getDescription());

    if (group.getGroupId() == Group.UNSAVED_ID) {
      SimpleJdbcInsert insert =
          new SimpleJdbcInsert(template)
              .withTableName("_Group")
              .usingGeneratedKeyColumns("groupId");
      Number newId = insert.executeAndReturnKey(params);
      group.setGroupId(newId.longValue());
    } else {
      params.addValue("groupId", group.getGroupId());
      NamedParameterJdbcTemplate namedTemplate = new NamedParameterJdbcTemplate(template);
      namedTemplate.update(GROUP_UPDATE, params);
    }

    return group.getGroupId();
  }
Esempio n. 17
0
 public void savePhenotypes(final long id, final String desc) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("pID", id);
           put("pDesc", desc);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_PHENOTYPES");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 18
0
 public void saveCountry(final Country country) throws Exception {
   Map<String, Object> map =
       new HashMap<String, Object>() {
         {
           put("cID", country.getId());
           put("cName", country.getName());
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Country");
   simpleJdbcInsert.execute(map);
 }
Esempio n. 19
0
 public void saveTherapy(final Therapy therapy) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("RADAR_NO", therapy.getRadarNumber());
           put("tID", therapy.getId());
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Therapy");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 20
0
 public void savePrdCode(final String code, final String term) throws Exception {
   Map<String, Object> map =
       new HashMap<String, Object>() {
         {
           put("ERA_EDTA_PRD_code", code);
           put("ERA_EDTA_primaryRenalDiagnosisTerm", term);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("rdr_prd_code");
   simpleJdbcInsert.execute(map);
 }
Esempio n. 21
0
 public void savePlasmaLu(final long id, final String desc) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("exID", id);
           put("exDesc", desc);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_RRT_PLASMA_LU");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 22
0
 public void saveKarotype(final long id, final String type) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("kID", id);
           put("KARYOTYPE", type);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Karyotype");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 23
0
 public void saveRRTTreatment(final long id, final long radarNo) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("tID", id);
           put("RADAR_NO", radarNo);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_RRT_TREATMENT");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 24
0
 public void saveLabData(final long id, final long radarNo) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("labID", id);
           put("RADAR_NO", radarNo);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_LabData");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 25
0
 public void createClinPres(final Long id, final String pres) throws Exception {
   Map<String, Object> map =
       new HashMap<String, Object>() {
         {
           put("cID", id);
           put("CLIN_PRES", pres);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Clin_Pres");
   simpleJdbcInsert.execute(map);
 }
Esempio n. 26
0
 public void saveTransplantModality(final long id, final String desc) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("trID", id);
           put("trDesc", desc);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_TRANSPLANT_MODALITY");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 27
0
 public void saveClinicalData(final ClinicalData clinicalData) throws Exception {
   Map<String, Object> clinicalDataMap =
       new HashMap<String, Object>() {
         {
           put("cID", clinicalData.getId());
           put("RADAR_NO", clinicalData.getRadarNumber());
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_clinicalData");
   simpleJdbcInsert.execute(clinicalDataMap);
 }
Esempio n. 28
0
 public void saveSex(final long id, final String type) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("sID", id);
           put("sType", type);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Sex");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 29
0
 public void saveTransplantReject(final long id, final long trId) {
   Map<String, Object> therapMap =
       new HashMap<String, Object>() {
         {
           put("recID", id);
           put("trID", trId);
         }
       };
   simpleJdbcInsert = new SimpleJdbcInsert(dataSource).withTableName("tbl_Transplant_Reject");
   simpleJdbcInsert.execute(therapMap);
 }
Esempio n. 30
0
 /*
  * (non-Javadoc)
  *
  * @see org.cuny.sensors.dao.IDao#save(java.lang.Object)
  */
 @Override
 public RawFile save(RawFile obj) throws Exception {
   Map<String, Object> parameters = new HashMap<String, Object>(5);
   parameters.put(FILE_NAME, obj.getFilename());
   parameters.put(FILE_SIZE, obj.getFileSize());
   parameters.put(STATUS, obj.getStatus().toString());
   parameters.put(BUILDING, obj.getBuilding());
   parameters.put(CAMPUS, obj.getCampus());
   Number newId = insertActor.executeAndReturnKey(parameters);
   obj.setId(newId.longValue());
   return obj;
 }