本文整理了Java中com.j256.ormlite.stmt.Where.isNull()
方法的一些代码示例,展示了Where.isNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Where.isNull()
方法的具体详情如下:
包路径:com.j256.ormlite.stmt.Where
类名称:Where
方法名:isNull
[英]Add a 'IS NULL' clause so the column must be null. '=' NULL does not work.
[中]添加一个'IS NULL'子句,使列必须为NULL。'='空值不起作用。
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public List<Room> getByParentId(Integer parentId) {
if (parentId == null) {
try {
return this.getDao().queryBuilder().where().isNull(Room.KEY_PARENT_ID).query();
} catch (SQLException ex) {
_logger.error("unable to get parent", ex);
return null;
}
} else {
return super.getAll(Room.KEY_PARENT_ID, parentId);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public List<Room> getByParentId(Integer parentId) {
if (parentId == null) {
try {
return this.getDao().queryBuilder().where().isNull(Room.KEY_PARENT_ID).query();
} catch (SQLException ex) {
_logger.error("unable to get parent", ex);
throw new McDatabaseException(ex);
}
} else {
return super.getAll(Room.KEY_PARENT_ID, parentId);
}
}
代码示例来源:origin: mil.nga.geopackage/geopackage-core
/**
* Set the foreign key column criteria in the where clause
*
* @param where
* where clause
* @param fileId
* file id
* @param parentId
* parent id
* @throws SQLException
*/
private void setFkWhere(Where<MetadataReference, Void> where, long fileId,
Long parentId) throws SQLException {
where.eq(MetadataReference.COLUMN_FILE_ID, fileId);
if (parentId == null) {
where.and().isNull(MetadataReference.COLUMN_PARENT_ID);
} else {
where.and().eq(MetadataReference.COLUMN_PARENT_ID, parentId);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
public void updateBulk(String setColName, Object setColValue, String whereColName, Object whereColValue) {
try {
UpdateBuilder<Tdao, Tid> updateBuilder = this.getDao().updateBuilder();
updateBuilder.updateColumnValue(setColName, setColValue);
if (whereColName != null) {
if (whereColValue != null) {
updateBuilder.where().eq(whereColName, whereColValue);
} else {
updateBuilder.where().isNull(whereColName);
}
}
Integer updateCount = updateBuilder.update();
_logger.debug("Updated column[{}] with value[{}] where column[{}] == value[{}], Updated row count:{}",
setColName, setColValue, whereColName, whereColValue, updateCount);
} catch (SQLException ex) {
_logger.error("unable to update column[{}] with value[{}] where column[{}] == value[{}]", setColName,
setColValue, whereColName, whereColValue, ex);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testIsNull() throws Exception {
Where<Foo, String> where = new Where<Foo, String>(createTableInfo(), null, databaseType);
where.isNull(Foo.VAL_COLUMN_NAME);
StringBuilder whereSb = new StringBuilder();
where.appendSql(null, whereSb, new ArrayList<ArgumentHolder>());
StringBuilder sb = new StringBuilder();
databaseType.appendEscapedEntityName(sb, Foo.VAL_COLUMN_NAME);
sb.append(" IS NULL ");
assertEquals(sb.toString(), whereSb.toString());
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public Room getByNameAndParentId(String name, Integer parentId) {
try {
QueryBuilder<Room, Integer> queryBuilder = this.getDao().queryBuilder();
Where<Room, Integer> where = queryBuilder.where();
int whereCount = 0;
where.eq(Room.KEY_NAME, name);
whereCount++;
if (parentId == null) {
where.isNull(Room.KEY_PARENT_ID);
} else {
where.eq(Room.KEY_PARENT_ID, parentId);
}
whereCount++;
where.and(whereCount);
queryBuilder.setWhere(where);
List<Room> rooms = queryBuilder.query();
if (rooms != null && !rooms.isEmpty()) {
return rooms.get(0);
}
} catch (SQLException ex) {
_logger.error("unable to get room", ex);
}
return null;
}
代码示例来源:origin: mil.nga.geopackage/geopackage-core
where.and().isNull(Extensions.COLUMN_TABLE_NAME);
} else {
where.and().eq(Extensions.COLUMN_TABLE_NAME, tableName);
where.and().isNull(Extensions.COLUMN_COLUMN_NAME);
} else {
where.and().eq(Extensions.COLUMN_COLUMN_NAME, columnName);
代码示例来源:origin: mycontroller-org/mycontroller
public void updateBulk(String setColName, Object setColValue, String whereColName, Object whereColValue) {
try {
UpdateBuilder<Tdao, Tid> updateBuilder = this.getDao().updateBuilder();
updateBuilder.updateColumnValue(setColName, setColValue);
if (whereColName != null) {
if (whereColValue != null) {
updateBuilder.where().eq(whereColName, whereColValue);
} else {
updateBuilder.where().isNull(whereColName);
}
}
Integer updateCount = updateBuilder.update();
_logger.debug("Updated column[{}] with value[{}] where column[{}] == value[{}], Updated row count:{}",
setColName, setColValue, whereColName, whereColValue, updateCount);
} catch (SQLException ex) {
_logger.error("unable to update column[{}] with value[{}] where column[{}] == value[{}]", setColName,
setColValue, whereColName, whereColValue, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public Room getByNameAndParentId(String name, Integer parentId) {
try {
QueryBuilder<Room, Integer> queryBuilder = this.getDao().queryBuilder();
Where<Room, Integer> where = queryBuilder.where();
int whereCount = 0;
where.eq(Room.KEY_NAME, name);
whereCount++;
if (parentId == null) {
where.isNull(Room.KEY_PARENT_ID);
} else {
where.eq(Room.KEY_PARENT_ID, parentId);
}
whereCount++;
where.and(whereCount);
queryBuilder.setWhere(where);
List<Room> rooms = queryBuilder.query();
if (rooms != null && !rooms.isEmpty()) {
return rooms.get(0);
}
} catch (SQLException ex) {
_logger.error("unable to get room", ex);
throw new McDatabaseException(ex);
}
return null;
}
代码示例来源:origin: annmuor/jnode
break;
case "null":
wh.isNull(args[i].toString());
i -= 1;
break;
代码示例来源:origin: mil.nga.geopackage/geopackage-core
/**
* Set the unique column criteria in the where clause
*
* @param where
* where clause
* @param constraintName
* constraint name
* @param constraintType
* constraint type
* @param value
* value
* @throws SQLException
*/
private void setUniqueWhere(Where<DataColumnConstraints, Void> where,
String constraintName, DataColumnConstraintType constraintType,
String value) throws SQLException {
where.eq(DataColumnConstraints.COLUMN_CONSTRAINT_NAME, constraintName)
.and()
.eq(DataColumnConstraints.COLUMN_CONSTRAINT_TYPE,
constraintType.getValue());
if (value == null) {
where.and().isNull(DataColumnConstraints.COLUMN_VALUE);
} else {
where.and().eq(DataColumnConstraints.COLUMN_VALUE, value);
}
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public Settings get(Integer userId, String key, String subKey) {
try {
Where<Settings, Integer> where = this.getDao().queryBuilder().where();
int andCount = 0;
if (userId == null) {
where.isNull(Settings.KEY_USER_ID);
andCount++;
} else {
where.eq(Settings.KEY_USER_ID, userId);
andCount++;
}
where.eq(Settings.KEY_KEY, key);
andCount++;
where.eq(Settings.KEY_SUB_KEY, subKey);
andCount++;
where.and(andCount);
QueryBuilder<Settings, Integer> queryBuilder = this.getDao().queryBuilder();
queryBuilder.setWhere(where);
return queryBuilder.queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get item for userId:{}, key:{}, subKey:{}", userId, key, subKey, ex);
return null;
}
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public Settings get(Integer userId, String key, String subKey) {
try {
Where<Settings, Integer> where = this.getDao().queryBuilder().where();
int andCount = 0;
if (userId == null) {
where.isNull(Settings.KEY_USER_ID);
andCount++;
} else {
where.eq(Settings.KEY_USER_ID, userId);
andCount++;
}
where.eq(Settings.KEY_KEY, key);
andCount++;
where.eq(Settings.KEY_SUB_KEY, subKey);
andCount++;
where.and(andCount);
QueryBuilder<Settings, Integer> queryBuilder = this.getDao().queryBuilder();
queryBuilder.setWhere(where);
return queryBuilder.queryForFirst();
} catch (SQLException ex) {
_logger.error("unable to get item for userId:{}, key:{}, subKey:{}", userId, key, subKey, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testNullForeign() throws Exception {
Dao<OrderOrdered, Integer> orderDao = createDao(OrderOrdered.class, true);
int numOrders = 10;
for (int orderC = 0; orderC < numOrders; orderC++) {
OrderOrdered order = new OrderOrdered();
order.val = orderC;
assertEquals(1, orderDao.create(order));
}
List<OrderOrdered> results = orderDao.queryBuilder().where().isNull(Order.ACCOUNT_FIELD_NAME).query();
assertNotNull(results);
assertEquals(numOrders, results.size());
}
代码示例来源:origin: org.mycontroller.standalone/mycontroller-core
@Override
public Sensor getByRoomId(String sensorName, Integer roomId) {
try {
if (roomId == null) {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().isNull(Sensor.KEY_ROOM_ID)
.and().eq(Sensor.KEY_NAME, sensorName).prepare());
} else {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().eq(Sensor.KEY_ROOM_ID, roomId)
.and().eq(Sensor.KEY_NAME, sensorName).prepare());
}
} catch (SQLException ex) {
_logger.error("unable to get, roomId:{}, sensorName:{}", roomId, sensorName, ex);
}
return null;
}
代码示例来源:origin: mycontroller-org/mycontroller
@Override
public Sensor getByRoomId(String sensorName, Integer roomId) {
try {
if (roomId == null) {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().isNull(Sensor.KEY_ROOM_ID)
.and().eq(Sensor.KEY_NAME, sensorName).prepare());
} else {
return this.getDao().queryForFirst(
this.getDao().queryBuilder()
.where().eq(Sensor.KEY_ROOM_ID, roomId)
.and().eq(Sensor.KEY_NAME, sensorName).prepare());
}
} catch (SQLException ex) {
_logger.error("unable to get, roomId:{}, sensorName:{}", roomId, sensorName, ex);
throw new McDatabaseException(ex);
}
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testNullForeign() throws Exception {
Dao<Order, Integer> orderDao = createDao(Order.class, true);
int numOrders = 10;
for (int orderC = 0; orderC < numOrders; orderC++) {
Order order = new Order();
order.val = orderC;
assertEquals(1, orderDao.create(order));
}
List<Order> results = orderDao.queryBuilder().where().isNull(Order.ONE_FIELD_NAME).query();
assertNotNull(results);
assertEquals(numOrders, results.size());
}
代码示例来源:origin: com.j256.ormlite/ormlite-jdbc
@Test
public void testIsNull() throws Exception {
Dao<Foo, String> fooDao = createTestData();
QueryBuilder<Foo, String> qb = fooDao.queryBuilder();
// null fields start off as null so 0 are not-null
qb.where().isNotNull(Foo.NULL_COLUMN_NAME);
List<Foo> results = fooDao.query(qb.prepare());
assertEquals(0, results.size());
// all are null
qb.where().isNull(Foo.NULL_COLUMN_NAME);
results = fooDao.query(qb.prepare());
assertEquals(2, results.size());
assertEquals(foo1, results.get(0));
assertEquals(foo2, results.get(1));
// set the null fields to not-null
for (Foo foo : results) {
foo.nullField = "not null";
assertEquals(1, fooDao.update(foo));
}
// no null results should be found
qb.where().isNull(Foo.NULL_COLUMN_NAME);
results = fooDao.query(qb.prepare());
assertEquals(0, results.size());
// all are not-null
qb.where().isNotNull(Foo.NULL_COLUMN_NAME);
results = fooDao.query(qb.prepare());
assertEquals(2, results.size());
assertEquals(foo1, results.get(0));
assertEquals(foo2, results.get(1));
}
代码示例来源:origin: j256/ormlite-core
@Test
public void testRandomIsNull() throws Exception {
Dao<SeralizableNull, Integer> dao = createDao(SeralizableNull.class, true);
SeralizableNull sn1 = new SeralizableNull();
assertEquals(1, dao.create(sn1));
SeralizableNull sn2 = new SeralizableNull();
sn2.serializable = "wow";
assertEquals(1, dao.create(sn2));
List<SeralizableNull> results =
dao.queryBuilder().where().isNull(SeralizableNull.FIELD_NAME_SERIALIZABLE).query();
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(sn1.id, results.get(0).id);
results = dao.queryBuilder().where().isNotNull(SeralizableNull.FIELD_NAME_SERIALIZABLE).query();
assertNotNull(results);
assertEquals(1, results.size());
assertEquals(sn2.id, results.get(0).id);
}
内容来源于网络,如有侵权,请联系作者删除!