com.j256.ormlite.dao.Dao.objectsEqual()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(10.0k)|赞(0)|评价(0)|浏览(143)

本文整理了Java中com.j256.ormlite.dao.Dao.objectsEqual()方法的一些代码示例,展示了Dao.objectsEqual()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dao.objectsEqual()方法的具体详情如下:
包路径:com.j256.ormlite.dao.Dao
类名称:Dao
方法名:objectsEqual

Dao.objectsEqual介绍

[英]Return true if the two parameters are equal. This checks each of the fields defined in the database to see if they are equal. Useful for testing and debugging.
[中]如果两个参数相等,则返回true。这将检查数据库中定义的每个字段,以查看它们是否相等。用于测试和调试。

代码示例

代码示例来源:origin: j256/ormlite-core

/**
 * @see Dao#objectsEqual(Object, Object)
 */
@Override
public boolean objectsEqual(T data1, T data2) {
  try {
    return dao.objectsEqual(data1, data2);
  } catch (SQLException e) {
    logMessage(e, "objectsEqual threw exception on: " + data1 + " and " + data2);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

/**
 * A call through to the {@link Dao#objectsEqual(Object, Object)}.
 */
public boolean objectsEqual(T other) throws SQLException {
  checkForDao();
  @SuppressWarnings("unchecked")
  T t = (T) this;
  return dao.objectsEqual(t, other);
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * A call through to the {@link Dao#objectsEqual(Object, Object)}.
 */
public boolean objectsEqual(T other) throws SQLException {
  checkForDao();
  @SuppressWarnings("unchecked")
  T t = (T) this;
  return dao.objectsEqual(t, other);
}

代码示例来源:origin: com.j256.ormlite/ormlite-core

/**
 * @see Dao#objectsEqual(Object, Object)
 */
@Override
public boolean objectsEqual(T data1, T data2) {
  try {
    return dao.objectsEqual(data1, data2);
  } catch (SQLException e) {
    logMessage(e, "objectsEqual threw exception on: " + data1 + " and " + data2);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: j256/ormlite-core

@Test(expected = RuntimeException.class)
public void testObjectsEqualThrow() throws Exception {
  @SuppressWarnings("unchecked")
  Dao<Foo, String> dao = (Dao<Foo, String>) createMock(Dao.class);
  RuntimeExceptionDao<Foo, String> rtDao = new RuntimeExceptionDao<Foo, String>(dao);
  expect(dao.objectsEqual(null, null)).andThrow(new SQLException("Testing catch"));
  replay(dao);
  rtDao.objectsEqual(null, null);
  verify(dao);
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

all.doubleObj = Double.parseDouble(DEFAULT_DOUBLE_VALUE);
all.ourEnum = OurEnum.valueOf(DEFAULT_ENUM_VALUE);
assertFalse(allDao.objectsEqual(all, allList.get(0)));

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testObjectsEqual() throws Exception {
  Foo foo = new Foo();
  assertEquals(1, fooDao.create(foo));
  int id = foo.id;
  Foo foo2 = fooDao.queryForId(id);
  // both other are null
  assertTrue(fooDao.objectsEqual(foo, foo2));
  // set to some other number
  foo2.id = 1341313;
  assertFalse(fooDao.objectsEqual(foo2, foo));
  foo2 = fooDao.queryForId(id);
  foo.other = "not null";
  // try null checks from either direction
  assertFalse(fooDao.objectsEqual(foo, foo2));
  assertFalse(fooDao.objectsEqual(foo2, foo));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testBooleanDefaultValueHandling() throws Exception {
  Dao<BooleanDefault, Object> allDao = createDao(BooleanDefault.class, true);
  BooleanDefault all = new BooleanDefault();
  assertEquals(1, allDao.create(all));
  List<BooleanDefault> allList = allDao.queryForAll();
  assertEquals(1, allList.size());
  all.booleanField = Boolean.parseBoolean(DEFAULT_BOOLEAN_VALUE);
  all.booleanObj = Boolean.parseBoolean(DEFAULT_BOOLEAN_VALUE);
  assertFalse(allDao.objectsEqual(all, allList.get(0)));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testStringWidthOkay() throws Exception {
  Dao<StringWidth, Object> stringWidthDao = createDao(StringWidth.class, true);
  StringWidth stringWidth = new StringWidth();
  StringBuilder sb = new StringBuilder();
  for (int i = 0; i < ALL_TYPES_STRING_WIDTH; i++) {
    sb.append('c');
  }
  String string = sb.toString();
  assertTrue(string.length() == ALL_TYPES_STRING_WIDTH);
  stringWidth.stringField = string;
  assertEquals(1, stringWidthDao.create(stringWidth));
  List<StringWidth> stringWidthList = stringWidthDao.queryForAll();
  assertEquals(1, stringWidthList.size());
  assertTrue(stringWidthDao.objectsEqual(stringWidth, stringWidthList.get(0)));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

/**
 * Returns the object if the query failed or null otherwise.
 */
private boolean checkQueryResult(Dao<AllTypes, Integer> allDao, QueryBuilder<AllTypes, Integer> qb,
    AllTypes allTypes, String fieldName, Object value, boolean required) throws SQLException {
  qb.where().eq(fieldName, value);
  List<AllTypes> results = allDao.query(qb.prepare());
  if (required) {
    assertEquals(1, results.size());
    assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
  } else if (results.size() == 1) {
    assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
  } else {
    return false;
  }
  SelectArg selectArg = new SelectArg();
  qb.where().eq(fieldName, selectArg);
  selectArg.setValue(value);
  results = allDao.query(qb.prepare());
  assertEquals(1, results.size());
  assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
  return true;
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testNullHandling() throws Exception {
  Dao<AllObjectTypes, Object> allDao = createDao(AllObjectTypes.class, true);
  AllObjectTypes all = new AllObjectTypes();
  assertEquals(1, allDao.create(all));
  List<AllObjectTypes> allList = allDao.queryForAll();
  assertEquals(1, allList.size());
  assertTrue(allDao.objectsEqual(all, allList.get(0)));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testAllTypesDefault() throws Exception {
  Dao<AllTypes, Integer> allDao = createDao(AllTypes.class, true);
  AllTypes allTypes = new AllTypes();
  assertEquals(1, allDao.create(allTypes));
  List<AllTypes> allTypesList = allDao.queryForAll();
  assertEquals(1, allTypesList.size());
  assertTrue(allDao.objectsEqual(allTypes, allTypesList.get(0)));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testBasicStuff() throws Exception {
  Dao<Basic, String> fooDao = createDao(Basic.class, true);
  String string = "s1";
  Basic foo1 = new Basic();
  foo1.id = string;
  assertEquals(1, fooDao.create(foo1));
  Basic foo2 = fooDao.queryForId(string);
  assertTrue(fooDao.objectsEqual(foo1, foo2));
  List<Basic> fooList = fooDao.queryForAll();
  assertEquals(1, fooList.size());
  assertTrue(fooDao.objectsEqual(foo1, fooList.get(0)));
  int i = 0;
  for (Basic foo3 : fooDao) {
    assertTrue(fooDao.objectsEqual(foo1, foo3));
    i++;
  }
  assertEquals(1, i);
  assertEquals(1, fooDao.delete(foo2));
  assertNull(fooDao.queryForId(string));
  fooList = fooDao.queryForAll();
  assertEquals(0, fooList.size());
  i = 0;
  for (Basic foo3 : fooDao) {
    assertTrue(fooDao.objectsEqual(foo1, foo3));
    i++;
  }
  assertEquals(0, i);
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

assertTrue(numberDao.objectsEqual(numberMins, allTypesList.get(0)));
assertTrue(numberDao.objectsEqual(numberMins2, allTypesList.get(1)));
assertTrue(numberDao.objectsEqual(numberMaxs, allTypesList.get(2)));

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testObjectNotNullHandling() throws Exception {
  Dao<AllObjectTypes, Object> allDao = createDao(AllObjectTypes.class, true);
  AllObjectTypes all = new AllObjectTypes();
  all.stringField = "foo";
  all.booleanField = false;
  Date dateValue = new Date(1279649192000L);
  all.dateField = dateValue;
  all.byteField = 0;
  all.shortField = 0;
  all.intField = 0;
  all.longField = 0L;
  all.floatField = 0F;
  all.doubleField = 0D;
  all.objectField = new SerialData();
  all.ourEnum = OurEnum.FIRST;
  assertEquals(1, allDao.create(all));
  assertEquals(1, allDao.refresh(all));
  List<AllObjectTypes> allList = allDao.queryForAll();
  assertEquals(1, allList.size());
  assertTrue(allDao.objectsEqual(all, allList.get(0)));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

/**
 * This is special because comparing floats may not work as expected.
 */
@Test
public void testAllTypesFloat() throws Exception {
  Dao<AllTypes, Integer> allDao = createDao(AllTypes.class, true);
  AllTypes allTypes = new AllTypes();
  float floatVal = 123.13F;
  float floatLowVal = floatVal * 0.9F;
  float floatHighVal = floatVal * 1.1F;
  allTypes.floatField = floatVal;
  assertEquals(1, allDao.create(allTypes));
  List<AllTypes> allTypesList = allDao.queryForAll();
  assertEquals(1, allTypesList.size());
  assertTrue(allDao.objectsEqual(allTypes, allTypesList.get(0)));
  assertEquals(1, allDao.refresh(allTypes));
  // queries on all fields
  QueryBuilder<AllTypes, Integer> qb = allDao.queryBuilder();
  // float comparisons are not exactly right so we switch to a low -> high query instead
  if (!checkQueryResult(allDao, qb, allTypes, AllTypes.FLOAT_FIELD_NAME, floatVal, false)) {
    qb.where().gt(AllTypes.FLOAT_FIELD_NAME, floatLowVal).and().lt(AllTypes.FLOAT_FIELD_NAME, floatHighVal);
    List<AllTypes> results = allDao.query(qb.prepare());
    assertEquals(1, results.size());
    assertTrue(allDao.objectsEqual(allTypes, results.get(0)));
  }
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

@Test
public void testObject() throws Exception {
  Dao<ObjectHolder, Integer> objDao = createDao(ObjectHolder.class, true);
  ObjectHolder foo1 = new ObjectHolder();
  foo1.obj = new SerialData();
  String key = "key2";
  String value = "val2";
  foo1.obj.addEntry(key, value);
  String strObj = "fjpwefefwpjoefwjpojopfew";
  foo1.strObj = strObj;
  assertEquals(1, objDao.create(foo1));
  ObjectHolder foo2 = objDao.queryForId(foo1.id);
  assertTrue(objDao.objectsEqual(foo1, foo2));
}

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

assertEquals(wrapper.id, wrapper2.id);
assertEquals(wrapper.foreign.id, wrapper2.foreign.id);
assertTrue(wrapperDao.objectsEqual(wrapper, wrapper2));
assertFalse(foreignDao.objectsEqual(foreign, wrapper2.foreign));
assertNull(wrapper2.foreign.stringField);
assertEquals(1, foreignDao.refresh(wrapper2.foreign));
assertTrue(foreignDao.objectsEqual(foreign, wrapper2.foreign));
assertEquals(stuff1, wrapper2.foreign.stringField);
assertEquals(wrapper.id, wrapper2.id);
assertEquals(wrapper.foreign.id, wrapper2.foreign.id);
assertTrue(wrapperDao.objectsEqual(wrapper, wrapper2));
assertFalse(foreignDao.objectsEqual(foreign, wrapper2.foreign));
assertNull(wrapper2.foreign.stringField);
assertEquals(1, foreignDao.refresh(wrapper2.foreign));
assertTrue(foreignDao.objectsEqual(foreign, wrapper2.foreign));
assertEquals(stuff2, wrapper2.foreign.stringField);

代码示例来源:origin: com.j256.ormlite/ormlite-jdbc

assertTrue(orderDao.objectsEqual(order1, orders.get(0)));
assertTrue(orderDao.objectsEqual(order2, orders.get(1)));

代码示例来源:origin: j256/ormlite-core

assertTrue(dao.objectsEqual(foo, list.get(0)));
  assertTrue(dao.objectsEqual(foo, list.get(0)));
  assertTrue(dao.objectsEqual(foo, list.get(0)));

相关文章