Package org.springframework.jdbc.core.namedparam

Examples of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource


        //Note: Remember that spring doesn't generate ID. The database generates the next id. Make sure the database
        // has a trigger or autoincrement facility on the ID column.
        SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(getDataSource()).withTableName(TABLE_NAME)
                .usingGeneratedKeyColumns("ID");

        SqlParameterSource parameters = new BeanPropertySqlParameterSource(resource);

        Number id = simpleJdbcInsert.executeAndReturnKey(parameters);
        resource.setId(id.intValue());
        return resource;
    }
View Full Code Here


            objectTypeEnum.toString()
    );
  }

  public void insert(EditHistoryDto editHistoryDto) {
    editInsert.execute(new BeanPropertySqlParameterSource(editHistoryDto));
  }
View Full Code Here

      if (arg instanceof MapSqlParameterSource) {
        msp.addValues(((MapSqlParameterSource) arg).getValues());
        continue;
      }

      BeanPropertySqlParameterSource sps = new BeanPropertySqlParameterSource(arg);
      List<Field> fields = new ArrayList<Field>();
      for (Class<?> c = arg.getClass(); c != null; c = c.getSuperclass()) {
        if (c.equals(Object.class))
          continue;
        fields.addAll(Arrays.asList(c.getDeclaredFields()));
      }
      for (Field f : fields) {
        try {
          String fn = f.getName();
          if (msp.hasValue(fn)) {
            if (warnParamOverride) {
              warnParamOverride = false;
              logger.warn(String.format("Field with name=%s has "
                  + "been already mapped by another arg bean. Overriding! Next time will warn if DEBUG is enabled.", fn));
            } else {
              if (logger.isDebugEnabled()) {
                logger.warn(String.format("Field with name=%s has "
                  + "been already mapped by another arg bean. Overriding!", fn));
              }
            }
          }
          if (Enum.class.isAssignableFrom(f.getType())) {
            sps.registerSqlType(f.getName(), Types.VARCHAR);
          }

          msp.addValue(fn, sps.getValue(fn), sps.getSqlType(fn), sps.getTypeName(fn));
          logger.debug(String.format("prepared sql arg: name=%s, value=%s, type=%s", fn, sps.getValue(fn),
              sps.getTypeName(fn)));
        } catch (Exception e) {
          Throwables.propagate(e);
        }
      }
    }
View Full Code Here

  @Transactional
  public void storeOwner(Owner owner) throws DataAccessException {
    if (owner.isNew()) {
      Number newKey = this.insertOwner.executeAndReturnKey(
          new BeanPropertySqlParameterSource(owner));
      owner.setId(newKey.intValue());
    }
    else {
      this.simpleJdbcTemplate.update(
          "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
          "city=:city, telephone=:telephone WHERE id=:id",
          new BeanPropertySqlParameterSource(owner));
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.