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


Java UpdateBuilder.updateColumnExpression方法代码示例

本文整理汇总了Java中com.j256.ormlite.stmt.UpdateBuilder.updateColumnExpression方法的典型用法代码示例。如果您正苦于以下问题:Java UpdateBuilder.updateColumnExpression方法的具体用法?Java UpdateBuilder.updateColumnExpression怎么用?Java UpdateBuilder.updateColumnExpression使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.j256.ormlite.stmt.UpdateBuilder的用法示例。


在下文中一共展示了UpdateBuilder.updateColumnExpression方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeComment

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
/**
 * Removes a comment.
 * @param commentHandle comment handle
 */
public void removeComment(String commentHandle) {
	DeleteBuilder<CommentFeedRelation, Integer> deleteBuilder = commentFeedDao.deleteBuilder();
	try {
		String topicHandle = getCommentParentHandle(commentHandle);
		deleteBuilder.where().eq(DbSchemas.CommentFeedRelation.COMMENT_HANDLE, commentHandle);
		deleteBuilder.delete();
		if (!TextUtils.isEmpty(topicHandle)) {
			UpdateBuilder<TopicView, String> updateBuilder = topicDao.updateBuilder();
			updateBuilder.where()
				.eq(DbSchemas.Topics.TOPIC_HANDLE, topicHandle)
				.and().gt(DbSchemas.Topics.TOTAL_COMMENTS, 0);
			updateBuilder.updateColumnExpression(
				DbSchemas.Topics.TOTAL_COMMENTS,
				DbSchemas.Topics.TOTAL_COMMENTS + " - 1");
			updateBuilder.update();
		}
	} catch (SQLException e) {
		DebugLog.logException(e);
	}
}
 
开发者ID:Microsoft,项目名称:EmbeddedSocial-Android-SDK,代码行数:25,代码来源:ContentCache.java

示例2: testPrepareStatementUpdateValueExpression

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
@Test
public void testPrepareStatementUpdateValueExpression() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	Foo foo = new Foo();
	foo.val = 123213;
	assertEquals(1, fooDao.create(foo));

	QueryBuilder<Foo, Integer> stmtb = fooDao.queryBuilder();
	stmtb.where().eq(Foo.ID_FIELD_NAME, foo.id);
	List<Foo> results = fooDao.query(stmtb.prepare());
	assertEquals(1, results.size());

	UpdateBuilder<Foo, Integer> updateb = fooDao.updateBuilder();
	String stuff = "deopdjq";
	updateb.updateColumnValue(Foo.STUFF_FIELD_NAME, stuff);
	StringBuilder sb = new StringBuilder();
	updateb.escapeColumnName(sb, Foo.VAL_FIELD_NAME);
	sb.append("+ 1");
	updateb.updateColumnExpression(Foo.VAL_FIELD_NAME, sb.toString());
	assertEquals(1, fooDao.update(updateb.prepare()));

	results = fooDao.queryForAll();
	assertEquals(1, results.size());
	assertEquals(stuff, results.get(0).stuff);
	assertEquals(foo.val + 1, results.get(0).val);
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:27,代码来源:JdbcBaseDaoImplTest.java

示例3: testPrepareStatementUpdateValueExpression

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
public void testPrepareStatementUpdateValueExpression() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	Foo foo = new Foo();
	foo.val = 123213;
	assertEquals(1, fooDao.create(foo));

	QueryBuilder<Foo, Integer> stmtb = fooDao.queryBuilder();
	stmtb.where().eq(Foo.ID_FIELD_NAME, foo.id);
	List<Foo> results = fooDao.query(stmtb.prepare());
	assertEquals(1, results.size());

	UpdateBuilder<Foo, Integer> updateb = fooDao.updateBuilder();
	String stuff = "deopdjq";
	updateb.updateColumnValue(Foo.STUFF_FIELD_NAME, stuff);
	StringBuilder sb = new StringBuilder();
	updateb.escapeColumnName(sb, Foo.VAL_FIELD_NAME);
	sb.append("+ 1");
	updateb.updateColumnExpression(Foo.VAL_FIELD_NAME, sb.toString());
	assertEquals(1, fooDao.update(updateb.prepare()));

	results = fooDao.queryForAll();
	assertEquals(1, results.size());
	assertEquals(stuff, results.get(0).stuff);
	assertEquals(foo.val + 1, results.get(0).val);
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:26,代码来源:AndroidJdbcBaseDaoImplTest.java

示例4: readWriteData

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
/**
 * Read and write some example data.
 */
private void readWriteData() throws Exception {
	// create an instance of User
	String name = "Jim Coakley";
	Date birthDate = new Date();
	DateTime createDateTime = new DateTime().plusDays(10);
	User user = new User(name, birthDate, createDateTime);

	// persist the user object to the database
	userDao.create(user);

	// if we get the user from the database then we should
	User result = userDao.queryForId(user.getId());
	// our result birth-date should now be null because it is too early
	assertEquals(birthDate, result.getBirthDate());
	assertEquals(createDateTime, result.getCreateDateTime());

	// to simulate a 'zero-date' we update the database by hand
	UpdateBuilder<User, Integer> ub = userDao.updateBuilder();
	// set it to some silly value
	ub.updateColumnExpression(User.FIELD_BIRTH_DATE, "'0000-01-01'");
	assertEquals(1, ub.update());

	// now we pull back out the user to see if we get a null birth-date
	result = userDao.queryForId(user.getId());
	// our result birth-date should now be null because it is too early
	assertNull(result.getBirthDate());
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:31,代码来源:DataPersisterMain.java

示例5: testPrepareStatementUpdateValueWhere

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
@Test
public void testPrepareStatementUpdateValueWhere() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	foo1.val = 78582351;
	assertEquals(1, fooDao.create(foo1));
	Foo foo2 = new Foo();
	String stuff = "eopqjdepodje";
	foo2.stuff = stuff;
	foo2.val = 123344131;
	assertEquals(1, fooDao.create(foo2));

	UpdateBuilder<Foo, Integer> updateb = fooDao.updateBuilder();
	String newStuff = "deopdjq";
	updateb.updateColumnValue(Foo.STUFF_FIELD_NAME, newStuff);
	StringBuilder sb = new StringBuilder();
	updateb.escapeColumnName(sb, Foo.VAL_FIELD_NAME);
	sb.append("+ 1");
	updateb.updateColumnExpression(Foo.VAL_FIELD_NAME, sb.toString());
	updateb.where().eq(Foo.ID_FIELD_NAME, foo2.id);
	assertEquals(1, fooDao.update(updateb.prepare()));

	List<Foo> results = fooDao.queryForAll();
	assertEquals(2, results.size());
	Foo foo = results.get(0);
	assertEquals(foo1.id, foo.id);
	assertEquals(foo1.val, foo.val);
	assertNull(foo.stuff);
	foo = results.get(1);
	assertEquals(foo2.id, foo.id);
	assertEquals(foo2.val + 1, foo.val);
	assertEquals(newStuff, foo.stuff);
}
 
开发者ID:j256,项目名称:ormlite-jdbc,代码行数:34,代码来源:JdbcBaseDaoImplTest.java

示例6: testPrepareStatementUpdateValueWhere

import com.j256.ormlite.stmt.UpdateBuilder; //导入方法依赖的package包/类
public void testPrepareStatementUpdateValueWhere() throws Exception {
	Dao<Foo, Integer> fooDao = createDao(Foo.class, true);
	Foo foo1 = new Foo();
	foo1.val = 78582351;
	assertEquals(1, fooDao.create(foo1));
	Foo foo2 = new Foo();
	String stuff = "eopqjdepodje";
	foo2.stuff = stuff;
	foo2.val = 123344131;
	assertEquals(1, fooDao.create(foo2));

	UpdateBuilder<Foo, Integer> updateb = fooDao.updateBuilder();
	String newStuff = "deopdjq";
	updateb.updateColumnValue(Foo.STUFF_FIELD_NAME, newStuff);
	StringBuilder sb = new StringBuilder();
	updateb.escapeColumnName(sb, Foo.VAL_FIELD_NAME);
	sb.append("+ 1");
	updateb.updateColumnExpression(Foo.VAL_FIELD_NAME, sb.toString());
	updateb.where().eq(Foo.ID_FIELD_NAME, foo2.id);
	assertEquals(1, fooDao.update(updateb.prepare()));

	List<Foo> results = fooDao.queryForAll();
	assertEquals(2, results.size());
	Foo foo = results.get(0);
	assertEquals(foo1.id, foo.id);
	assertEquals(foo1.val, foo.val);
	assertNull(foo.stuff);
	foo = results.get(1);
	assertEquals(foo2.id, foo.id);
	assertEquals(foo2.val + 1, foo.val);
	assertEquals(newStuff, foo.stuff);
}
 
开发者ID:j256,项目名称:ormlite-android-tests,代码行数:33,代码来源:AndroidJdbcBaseDaoImplTest.java


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