当前位置: 首页>>代码示例>>Java>>正文


Java BeanPropertySqlParameterSource类代码示例

本文整理汇总了Java中org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource的典型用法代码示例。如果您正苦于以下问题:Java BeanPropertySqlParameterSource类的具体用法?Java BeanPropertySqlParameterSource怎么用?Java BeanPropertySqlParameterSource使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


BeanPropertySqlParameterSource类属于org.springframework.jdbc.core.namedparam包,在下文中一共展示了BeanPropertySqlParameterSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: add

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
public Object add(Object object) {
	SqlModel<Object> sqlModel = sqlBuilder.insertSelectiveSql(object);
	checkSqlModel(sqlModel);
	
	SqlParameterSource paramSource =  new BeanPropertySqlParameterSource(object);
	KeyHolder generatedKeyHolder =  new  GeneratedKeyHolder();
	namedPjdbcTemplate.update(sqlModel.getSql(), paramSource, generatedKeyHolder);
	Number num = generatedKeyHolder.getKey();
	
	String[] primaryKeys = sqlModel.getPrimaryKeys();
	if(primaryKeys != null && primaryKeys.length > 0){
		BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(object);
		beanWrapper.setPropertyValue(primaryKeys[0], num);
	}
	
	return object;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:19,代码来源:NamedJdbcDao.java

示例2: batchUpdate

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
public int[] batchUpdate(Collection<?> objects) {
	SqlParameterSource[] batchArgs = new BeanPropertySqlParameterSource[objects.size()];
	String sql = null;
	int index = 0;
	for (Object object : objects) {
		if(index == 0 ){
			//XXX: thinking 共享第一实体的sql
			SqlModel<Object> sqlModel = sqlBuilder.updateSql(object);
			sql = sqlModel.getSql();
		}
		batchArgs[index] = new BeanPropertySqlParameterSource(object);
		
		index ++;
	}
	int[] rows = namedPjdbcTemplate.batchUpdate(sql, batchArgs);
	return rows;
}
 
开发者ID:thinking-github,项目名称:nbone,代码行数:19,代码来源:NamedJdbcDao.java

示例3: testInsert

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Test
public void testInsert() {
    GeneratedAlwaysRecord record = new GeneratedAlwaysRecord();
    record.setId(100);
    record.setFirstName("Bob");
    record.setLastName("Jones");
    
    InsertStatementProvider<GeneratedAlwaysRecord> insertStatement = insert(record)
            .into(generatedAlways)
            .map(id).toProperty("id")
            .map(firstName).toProperty("firstName")
            .map(lastName).toProperty("lastName")
            .build()
            .render(RenderingStrategy.SPRING_NAMED_PARAMETER);
    
    SqlParameterSource parameterSource = new BeanPropertySqlParameterSource(insertStatement.getRecord());
    KeyHolder keyHolder = new GeneratedKeyHolder();
    
    int rows = template.update(insertStatement.getInsertStatement(), parameterSource, keyHolder);
    String generatedKey = (String) keyHolder.getKeys().get("FULL_NAME");
    
    assertThat(rows).isEqualTo(1);
    assertThat(generatedKey).isEqualTo("Bob Jones");
    
}
 
开发者ID:mybatis,项目名称:mybatis-dynamic-sql,代码行数:26,代码来源:SpringTest.java

示例4: addChat

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
public int addChat(Chat chat) throws Exception {
	List<String> fields = Arrays.asList(
		SADisplayConstants.CHAT_ID,	SADisplayConstants.COLLAB_ROOM_ID, SADisplayConstants.USER_ORG_ID,
		SADisplayConstants.CREATED, SADisplayConstants.SEQ_NUM, SADisplayConstants.MESSAGE);
		
	QueryModel model = QueryManager.createQuery(SADisplayConstants.CHAT_TABLE).insertInto(fields);
	
	//generate a chatid if not set
	if (chat.getChatid() <= 0) {
		QueryModel idModel = QueryManager.createQuery("chat_seq").selectNextVal();
		int id = this.template.queryForObject(idModel.toString(), new MapSqlParameterSource(), Integer.class);
		chat.setChatid(id);
	}
	
	try {
		this.template.update(model.toString(), new BeanPropertySqlParameterSource(chat));
		return chat.getChatid();
	} catch(Exception e) {
		throw new Exception("Unhandled exception while persisting Chat entity:", e);
	}
}
 
开发者ID:hadrsystems,项目名称:nics-common,代码行数:22,代码来源:ChatDAOImpl.java

示例5: editEmployee

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@PUT
@Path("/{employeeId}")
public Employee editEmployee(final Employee employee, @PathParam("employeeId") Integer employeeId) {

	String sql = "update EMPLOYEE set name=:name, address=:address where id=:id";

	SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(employee);

	this.namedParameterJdbcTemplate.update(sql, namedParameters);

	sql = "select * from EMPLOYEE where id=:employeeId";
	SqlParameterSource namedParameters2 = new MapSqlParameterSource("employeeId", employeeId);
	return namedParameterJdbcTemplate.query(sql, namedParameters2, new EmployeeMapper()).get(0);
}
 
开发者ID:geekmj,项目名称:jersey-jax-rs-examples,代码行数:15,代码来源:EmployeeResource.java

示例6: createExampleByPk

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
/**
 * 根据主键创建查询条件
 *
 * @param pathBase Querydsl query type
 * @param pk       主键
 * @return 查询条件
 */
public static QueryExample createExampleByPk(RelationalPathBase<?> pathBase, Object pk) {
    int numOfPk = pathBase.getPrimaryKey().getLocalColumns().size();
    Validate.isTrue(numOfPk > 0, "primaryKey not exists");
    QueryExample example = QueryExample.newInstance();
    if (numOfPk == 1) {
        example.equalsTo(pathBase.getPrimaryKey().getLocalColumns()
                .get(0).getMetadata().getName(), pk);
    } else {
        SqlParameterSource source = new BeanPropertySqlParameterSource(pk);
        for (Path<?> path : pathBase.getPrimaryKey().getLocalColumns()) {
            String name = path.getMetadata().getName();
            String humpName = humpName(name);
            example.equalsTo(humpName, source.getValue(name));
        }
    }
    return example;
}
 
开发者ID:edgar615,项目名称:javase-study,代码行数:25,代码来源:QueryExampleHelper.java

示例7: runCommand

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
private String runCommand(StepContext steoContext, String sqlCommand) throws Exception {

		String msg = "";
		if (sqlCommand.trim().toUpperCase().startsWith("SELECT")) {
			logger.debug("Executing: " + sqlCommand);
			List<Map<String, Object>> result = jdbcTemplate.queryForList(sqlCommand,
					new BeanPropertySqlParameterSource(steoContext));
			msg = "Result: " + result;
			logger.debug(msg);
		} else {
			logger.debug("Updating : " + sqlCommand);
			int updated = jdbcTemplate.update(sqlCommand, new BeanPropertySqlParameterSource(steoContext));
			msg = "Updated: " + updated + " rows";
			logger.debug(msg);
		}

		return msg;
	}
 
开发者ID:tzolov,项目名称:spring-xd-jdbc-job,代码行数:19,代码来源:JdbcTasklet.java

示例8: create

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
@Transactional
public String create(Alert alert) {
    log.debug("Inserting alert into SQL backend: " + alert);
    checkArgument(StringUtils.isBlank(alert.getId()), "alert id cannot be already set");

    String id = UUID.randomUUID().toString();
    alert.setId(id);
    String sql = "INSERT INTO Alert (id, created_by, message, priority, user_id,  acknowledged, created_date) " +
            "VALUES (:id, :createdBy, :message, :priority, :userId, :acknowledged, :createdDate)";

    BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(alert);
    int results = this.namedJdbcTemplate.update(sql, source);
    log.debug("Got: " + results + " results");

    return id;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:18,代码来源:PGAlertDao.java

示例9: readPage

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Alert> readPage(PagingCriteria criteria) {
    log.debug("reading page with criteria: " + criteria);
    if (criteria == null || criteria.getLimit() == null || criteria.getStart() == null) {
        log.warn("criteria invalid - reading all instead of subset");
        return readAll();
    }
    String sql = "SELECT LIMIT :start :limit * FROM Alert ORDER BY created_date ASC";
    BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(criteria);

    List<Alert> alerts = this.namedJdbcTemplate.query(sql, source, new AlertRowMapper());
    log.debug(alerts.size() + " alerts returned using criteria: " + criteria);

    return alerts;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:17,代码来源:PGAlertDao.java

示例10: create

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
@Transactional
public String create(Document document) {
    log.debug("Inserting Document into SQL backend: " + document);
    checkArgument(StringUtils.isBlank(document.getId()), "Document id cannot be already set");

    String id = UUID.randomUUID().toString();
    document.setId(id);
    String sql = "INSERT INTO Document (id, author, title, content, summary, group_id, state_, created_date) " +
            "VALUES (:id, :author, :title, :content, :summary, :groupId, :state, :createdDate)";

    BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(document);
    int results = this.namedJdbcTemplate.update(sql, source);
    log.debug("Got: " + results + " results");
    document.setId(id);
    return id;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:18,代码来源:PGDocumentDao.java

示例11: readPage

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public List<Document> readPage(PagingCriteria criteria) {
    log.debug("reading page with criteria: " + criteria);
    if (criteria == null || criteria.getLimit() == null || criteria.getStart() == null) {
        log.warn("criteria invalid - reading all instead of subset");
        return readAll();
    }
    String sql = "SELECT LIMIT :start :limit * FROM Document ORDER BY created_date ASC";
    BeanPropertySqlParameterSource source = new BeanPropertySqlParameterSource(criteria);

    List<Document> documents = this.namedJdbcTemplate.query(sql, source, new DocumentRowMapper());
    log.debug(documents.size() + " Documents returned using criteria: " + criteria);

    return documents;
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:17,代码来源:PGDocumentDao.java

示例12: delete

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
public <T> int delete(T t) throws DataAccessException {
    StringBuilder sql = new StringBuilder();
    sql.append(DELETE).append(SPACE).append(FROM).append(SPACE).append(t.getClass().getSimpleName().toLowerCase()).append(SPACE);
    sql.append(WHERE).append(SPACE).append(IDENTICAL).append(SPACE);
    PropertyDescriptor[] pds = BeanUtils.getPropertyDescriptors(t.getClass());
    BeanWrapper beanWrapper = PropertyAccessorFactory.forBeanPropertyAccess(t);
    for (int i = 0; i < pds.length; i++) {
        PropertyDescriptor pd = pds[i];
        String name = pd.getName();
        if (!CLASS.equals(name) && beanWrapper.isReadableProperty(name) && beanWrapper.getPropertyValue(name) != null) {
            sql.append(AND).append(SPACE).append(CamelCaseUtils.underscoreName(name)).append(SPACE);
            sql.append(EQUAL).append(SPACE).append(COLON).append(name).append(SPACE);
        }
    }
    return namedJdbcTemplate.update(sql.toString(), new BeanPropertySqlParameterSource(t));
}
 
开发者ID:mynah,项目名称:oblatum,代码行数:17,代码来源:MappingJdbcTemplate.java

示例13: insertUser

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
public Long insertUser(User u) {
	StringBuffer sql = new StringBuffer("");
	sql.append(" insert into user ");
	sql.append(" ( username, password ) ");
	sql.append(" values ( ");
	sql.append("   :username ");
	sql.append(" , :password ");
	sql.append(" ) ");
	
	SqlParameterSource paramSource = new BeanPropertySqlParameterSource(u);
	KeyHolder generatedKeyHolder = new GeneratedKeyHolder();
	int rows = getDao().update(sql.toString(), paramSource, generatedKeyHolder);
	
	if(rows > 0 ){
		Long userId = generatedKeyHolder.getKey().longValue();
		u.setId(userId);
	}
	
	return u.getId();
}
 
开发者ID:jiucai,项目名称:appframework,代码行数:22,代码来源:UserDaoJdbcImpl.java

示例14: listUser

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
	public List<User> listUser(User query) {
		StringBuffer sql = new StringBuffer("");
		sql.append(" select * ").append("\n");
		sql.append(" from user ").append("\n");
		sql.append(" where 1=1 ").append("\n");
		
		if(null != query.getId()){
			sql.append(" and id = :id  ").append("\n");
		}
		sql.append(" order by id desc ").append("\n");
		
		SqlParameterSource paramSource = new BeanPropertySqlParameterSource(query);
		
//		RowMapper<User> rowMapper = ParameterizedBeanPropertyRowMapper.newInstance(User.class);
		
	    BeanPropertyRowMapper<User> rowMapper = new BeanPropertyRowMapper<User>(User.class);
		
		return getDao().query(sql.toString(), paramSource, rowMapper);

	}
 
开发者ID:jiucai,项目名称:appframework,代码行数:22,代码来源:UserDaoJdbcImpl.java

示例15: save

import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource; //导入依赖的package包/类
@Override
public void save(Owner owner) throws DataAccessException {
    BeanPropertySqlParameterSource parameterSource = new BeanPropertySqlParameterSource(owner);
    if (owner.isNew()) {
        Number newKey = this.insertOwner.executeAndReturnKey(parameterSource);
        owner.setId(newKey.intValue());
    } else {
        this.namedParameterJdbcTemplate.update(
            "UPDATE owners SET first_name=:firstName, last_name=:lastName, address=:address, " +
                "city=:city, telephone=:telephone WHERE id=:id",
            parameterSource);
    }
}
 
开发者ID:PacktPublishing,项目名称:DevOps-for-Web-Development,代码行数:14,代码来源:JdbcOwnerRepositoryImpl.java


注:本文中的org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。