@Test
public void testAliasMapping() throws Exception {
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ Db db = IciqlSuite.openDb();
db.insertAll(Product.getList());
Product p = new Product();
import java.sql.SQLException;
import java.util.List;
-import org.h2.constant.ErrorCode;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.iciql.test.models.ProductInheritedAnnotation;
import com.iciql.test.models.ProductMixedAnnotation;
import com.iciql.test.models.ProductNoCreateTable;
+import com.iciql.util.JdbcUtils;
+import com.iciql.util.Utils;
/**
* Test annotation processing.
@Before
public void setUp() {
- db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ db = IciqlSuite.openDb();
db.insertAll(Product.getList());
db.insertAll(ProductAnnotationOnly.getList());
db.insertAll(ProductMixedAnnotation.getList());
public void testIndexCreation() throws SQLException {
// test indexes are created, and columns are in the right order
DatabaseMetaData meta = db.getConnection().getMetaData();
+ boolean isH2 = meta.getDatabaseProductName().equals("H2");
ResultSet rs = meta.getIndexInfo(null, "PUBLIC", "ANNOTATEDPRODUCT", false, true);
+ // first index is primary key index
+ // H2 gives this a testable name.
assertTrue(rs.next());
- assertStartsWith(rs.getString("INDEX_NAME"), "PRIMARY_KEY");
+ if (isH2) {
+ assertStartsWith(rs.getString("INDEX_NAME"), "PRIMARY_KEY");
+ }
assertTrue(rs.next());
assertStartsWith(rs.getString("INDEX_NAME"), "ANNOTATEDPRODUCT_0");
assertStartsWith(rs.getString("COLUMN_NAME"), "NAME");
// test IQTable.annotationsOnly=true
// public String unmappedField is ignored by iciql
- assertEquals(0, db.from(p).where(p.unmappedField).is("unmapped").selectCount());
-
- // test IQColumn.autoIncrement=true
+ try {
+ db.from(p).where(p.unmappedField).is("unmapped").selectCount();
+ assertTrue("this should never execute", false);
+ } catch (IciqlException e) {
+ assertEquals(IciqlException.CODE_UNMAPPED_FIELD, e.getIciqlCode());
+ }
+
// 10 objects, 10 autoIncremented unique values
- assertEquals(10, db.from(p).selectDistinct(p.autoIncrement).size());
+ assertEquals(10, db.from(p).selectDistinct(p.productName).size());
// test IQTable.primaryKey=id
try {
db.insertAll(ProductAnnotationOnly.getList());
- } catch (IciqlException r) {
- SQLException s = (SQLException) r.getCause();
- assertEquals(ErrorCode.DUPLICATE_KEY_1, s.getErrorCode());
+ } catch (IciqlException e) {
+ assertEquals(IciqlException.CODE_DUPLICATE_KEY, e.getIciqlCode());
}
}
// test IQColumn.primaryKey=true
try {
db.insertAll(ProductMixedAnnotation.getList());
- } catch (IciqlException r) {
- SQLException s = (SQLException) r.getCause();
- assertEquals(ErrorCode.DUPLICATE_KEY_1, s.getErrorCode());
+ } catch (IciqlException e) {
+ assertEquals(IciqlException.CODE_DUPLICATE_KEY, e.getIciqlCode());
}
}
// tests IQTable.createTableIfRequired=false
try {
db.insertAll(ProductNoCreateTable.getList());
- } catch (IciqlException r) {
- SQLException s = (SQLException) r.getCause();
- assertEquals(ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1, s.getErrorCode());
+ } catch (IciqlException e) {
+ assertEquals(IciqlException.CODE_TABLE_NOT_FOUND, e.getIciqlCode());
}
}
\r
@Test\r
public void testBooleanColumn() {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
db.insertAll(BooleanModel.getList());\r
BooleanAsIntModel b = new BooleanAsIntModel();\r
List<BooleanAsIntModel> models = db.from(b).select();\r
\r
@Test\r
public void testIntColumn() {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
// insert INT column\r
db.insertAll(BooleanAsIntModel.getList());\r
\r
@Test
public void testClob() throws Exception {
String create = "CREATE TABLE CLOB_TEST(ID INT PRIMARY KEY, WORDS {0})";
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ Db db = IciqlSuite.openDb();
db.executeUpdate(MessageFormat.format(create, "VARCHAR(255)"));
db.insertAll(StringRecord.getList());
testSimpleUpdate(db, "VARCHAR fail");
db.close();
- db = Db.open("jdbc:h2:mem:", "sa", "sa");
- db.executeUpdate(MessageFormat.format(create, "TEXT"));
+ db = IciqlSuite.openDb();
+ db.executeUpdate(MessageFormat.format(create, "CLOB"));
db.insertAll(StringRecord.getList());
testSimpleUpdate(db, "CLOB fail because of single quote artifacts");
db.close();
import org.junit.Test;
import com.iciql.Db;
+import com.iciql.IciqlException;
import com.iciql.Query;
import com.iciql.test.models.Product;
import com.iciql.util.Utils;
@Before
public void setUp() {
- db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ db = IciqlSuite.openDb();
db.insertAll(Product.getList());
}
Query<Product> query2 = db.from(p);
// if you could share alias instances both counts should be equal
- long count1 = query1.where(p.category).is("Beverages").selectCount();
+ long count1 = 0;
+ try {
+ count1 = query1.where(p.category).is("Beverages").selectCount();
+ } catch (IciqlException e) {
+ assertEquals(IciqlException.CODE_UNMAPPED_FIELD, e.getIciqlCode());
+ }
long count2 = query2.where(p.category).is("Beverages").selectCount();
// but they aren't
try {
int testCase = testNumber % 10;
test(testCase, p);
- } catch (Throwable rex) {
+ } catch (AssertionError e) {
+ failures.incrementAndGet();
+ } catch (IciqlException e) {
failures.incrementAndGet();
- System.err.println("EXPECTED ERROR");
- rex.printStackTrace();
+ if (e.getIciqlCode() != IciqlException.CODE_UNMAPPED_FIELD) {
+ System.err.println("UNEXPECTED ERROR in testConcurrencyFinal()");
+ e.printStackTrace();
+ }
}
}
}, "ICIQL-" + i);
try {
int testCase = testNumber % 10;
test(testCase, tl.get());
- } catch (Throwable rex) {
+ } catch (AssertionError e) {
+ failures.incrementAndGet();
+ } catch (IciqlException e) {
failures.incrementAndGet();
- rex.printStackTrace();
+ if (e.getIciqlCode() != IciqlException.CODE_UNMAPPED_FIELD) {
+ System.err.println("UNEXPECTED ERROR in testConcurrencyThreadLocal()");
+ e.printStackTrace();
+ }
}
}
}, "ICIQL-" + i);
\r
@Test\r
public void testDefaultObjectValues() {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
\r
// insert random model\r
DefaultValuesModel model = new DefaultValuesModel();\r
\r
@Before\r
public void setUp() {\r
- db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ db = IciqlSuite.openDb();\r
db.insertAll(EnumIdModel.createList());\r
db.insertAll(EnumOrdinalModel.createList());\r
db.insertAll(EnumStringModel.createList());\r
*/\r
package com.iciql.test;\r
\r
+import java.sql.SQLException;\r
+import java.text.MessageFormat;\r
+import java.util.concurrent.atomic.AtomicInteger;\r
+\r
import org.junit.Assert;\r
+import org.junit.runner.JUnitCore;\r
+import org.junit.runner.Result;\r
import org.junit.runner.RunWith;\r
+import org.junit.runner.notification.Failure;\r
import org.junit.runners.Suite;\r
import org.junit.runners.Suite.SuiteClasses;\r
\r
+import com.iciql.Db;\r
+\r
/**\r
* JUnit 4 iciql test suite.\r
* \r
+ * By default this test suite will run against the H2 database. You can change\r
+ * this by switching the DEFAULT_TEST_DB value.\r
+ * <p>\r
+ * Alternatively, you can run this class an application which will run all tests\r
+ * for all tested databases.\r
+ * \r
*/\r
@RunWith(Suite.class)\r
@SuiteClasses({ AliasMapTest.class, AnnotationsTest.class, BooleanModelTest.class, ClobTest.class,\r
ConcurrencyTest.class, EnumsTest.class, ModelsTest.class, PrimitivesTest.class,\r
- RuntimeQueryTest.class, SamplesTest.class, StatementLoggerTest.class, UpdateTest.class,\r
- UUIDTest.class })\r
+ RuntimeQueryTest.class, SamplesTest.class, UpdateTest.class, UUIDTest.class })\r
public class IciqlSuite {\r
\r
- public static void assertStartsWith(String a, String b) {\r
- Assert.assertTrue(a.startsWith(b));\r
+ private static final TestDb[] TEST_DBS = { \r
+ new TestDb("H2", "jdbc:h2:mem:"),\r
+ new TestDb("HSQL", "jdbc:hsqldb:mem:db{0,number,000}") };\r
+\r
+ private static final TestDb DEFAULT_TEST_DB = TEST_DBS[0];\r
+\r
+ private static AtomicInteger openCount = new AtomicInteger(0);\r
+\r
+ public static void assertStartsWith(String value, String startsWith) {\r
+ Assert.assertTrue(MessageFormat.format("Expected \"{0}\", got: \"{1}\"", startsWith, value),\r
+ value.startsWith(startsWith));\r
+ }\r
+\r
+ public static Db openDb() {\r
+ String testUrl = System.getProperty("iciql.url");\r
+ if (testUrl == null) {\r
+ testUrl = DEFAULT_TEST_DB.url;\r
+ }\r
+ testUrl = MessageFormat.format(testUrl, openCount.incrementAndGet());\r
+ return Db.open(testUrl, "sa", "sa");\r
+ }\r
+\r
+ public static String getDatabaseName(Db db) {\r
+ String database = "";\r
+ try {\r
+ database = db.getConnection().getMetaData().getDatabaseProductName();\r
+ } catch (SQLException s) {\r
+ }\r
+ return database;\r
+ }\r
+\r
+ public static void main(String... args) {\r
+ SuiteClasses suiteClasses = IciqlSuite.class.getAnnotation(SuiteClasses.class);\r
+ for (TestDb testDb : TEST_DBS) {\r
+ System.out.println("*********************************************");\r
+ System.out.println("Testing " + testDb.name + " " + testDb.getVersion());\r
+ System.out.println("*********************************************");\r
+ System.setProperty("iciql.url", testDb.url);\r
+ Result result = JUnitCore.runClasses(suiteClasses.value());\r
+ System.out.println(MessageFormat.format("{0} runs, {1} failures, {2} ignores in {3} msecs",\r
+ result.getRunCount(), result.getFailureCount(), result.getIgnoreCount(),\r
+ result.getRunTime()));\r
+ for (Failure failure : result.getFailures()) {\r
+ System.out.println(MessageFormat.format("{0}: {1}", failure.getTestHeader(),\r
+ failure.getMessage()));\r
+ }\r
+ System.out.println();\r
+ }\r
+ }\r
+\r
+ /**\r
+ * Represents a test database url.\r
+ */\r
+ private static class TestDb {\r
+ final String name;\r
+ final String url;\r
+\r
+ TestDb(String name, String url) {\r
+ this.name = name;\r
+ this.url = url;\r
+ }\r
+\r
+ String getVersion() {\r
+ try {\r
+ Db db = Db.open(url, "sa", "sa");\r
+ String version = db.getConnection().getMetaData().getDatabaseProductVersion();\r
+ db.close();\r
+ return version;\r
+ } catch (SQLException s) {\r
+ }\r
+ return "";\r
+ }\r
}\r
}\r
@Before
public void setUp() {
- db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ db = IciqlSuite.openDb();
db.insertAll(Product.getList());
db.insertAll(ProductAnnotationOnly.getList());
db.insertAll(ProductMixedAnnotation.getList());
@Test
public void testValidateModels() {
+ boolean isH2 = IciqlSuite.getDatabaseName(db).equals("H2");
DbInspector inspector = new DbInspector(db);
- validateModel(inspector, new Product());
- validateModel(inspector, new ProductAnnotationOnly());
- validateModel(inspector, new ProductMixedAnnotation());
+ validateModel(inspector, new Product(), 3);
+ validateModel(inspector, new ProductAnnotationOnly(), isH2 ? 2 : 3);
+ validateModel(inspector, new ProductMixedAnnotation(), isH2 ? 3 : 4);
}
- private void validateModel(DbInspector inspector, Object o) {
+ private void validateModel(DbInspector inspector, Object o, int expected) {
List<ValidationRemark> remarks = inspector.validateModel(o, false);
- assertTrue("Validation remarks are null for " + o.getClass().getName(), remarks != null);
- log("Validation remarks for " + o.getClass().getName());
+ assertTrue("validation remarks are null for " + o.getClass().getName(), remarks != null);
+ StringBuilder sb = new StringBuilder();
+ sb.append("validation remarks for " + o.getClass().getName());
+ sb.append('\n');
for (ValidationRemark remark : remarks) {
- log(remark.toString());
+ sb.append(remark.toString());
+ sb.append('\n');
if (remark.isError()) {
errorCollector.addError(new SQLException(remark.toString()));
}
}
+ assertTrue(remarks.get(0).message.equals("@IQSchema(name=PUBLIC)"));
+ assertEquals(sb.toString(), expected, remarks.size());
}
@Test
true);
assertEquals(1, models.size());
// a poor test, but a start
- assertEquals(1456, models.get(0).length());
+ String dbName = IciqlSuite.getDatabaseName(db);
+ if (dbName.equals("H2")) {
+ assertEquals(1478, models.get(0).length());
+ } else if (dbName.startsWith("HSQL")) {
+ // HSQL uses Double instead of Float
+ assertEquals(1479, models.get(0).length());
+ }
}
@Test
@Test
public void testTableUpgrade() {
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ Db db = IciqlSuite.openDb();
// insert first, this will create version record automatically
List<SupportedTypes> original = SupportedTypes.createList();
\r
@Test\r
public void testPrimitives() {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
\r
// insert random model\r
PrimitivesModel model = new PrimitivesModel();\r
\r
@Test\r
public void testRuntimeQuery() {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
db.insertAll(Product.getList());\r
\r
Product p = new Product();\r
\r
@Test\r
public void testExecuteQuery() throws SQLException {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
db.insertAll(Product.getList());\r
\r
// test plain statement\r
\r
@Test\r
public void testBuildObjects() throws SQLException {\r
- Db db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ Db db = IciqlSuite.openDb();\r
db.insertAll(Product.getList());\r
\r
// test plain statement\r
import static org.junit.Assert.assertTrue;\r
\r
import java.math.BigDecimal;\r
+import java.util.Collections;\r
import java.util.HashSet;\r
import java.util.List;\r
import java.util.Set;\r
\r
@Before\r
public void setUp() {\r
- db = Db.open("jdbc:h2:mem:", "sa", "sa");\r
+ db = IciqlSuite.openDb();\r
db.insertAll(Product.getList());\r
db.insertAll(Customer.getList());\r
db.insertAll(Order.getList());\r
\r
@Test\r
public void testReverseColumns() {\r
- db.executeUpdate("create table TestReverse(id int, name varchar, additional varchar)");\r
+ db.executeUpdate("create table TestReverse(id int, name varchar(10), additional varchar(10))");\r
TestReverse t = new TestReverse();\r
t.id = 10;\r
t.name = "Hello";\r
final Customer c = new Customer();\r
final Order o = new Order();\r
List<CustOrder> orders = db.from(c).innerJoin(o).on(c.customerId).is(o.customerId).where(o.total)\r
- .lessThan(new BigDecimal("100.00")).orderBy(1).select(new CustOrder() {\r
+ .lessThan(new BigDecimal("100.00")).orderBy(c.customerId).select(new CustOrder() {\r
{\r
customerId = c.customerId;\r
orderId = o.orderId;\r
@Test\r
public void testLength() {\r
Product p = new Product();\r
- List<Integer> lengths = db.from(p).where(length(p.productName)).lessThan(10).orderBy(1)\r
+ List<Integer> lengths = db.from(p).where(length(p.productName)).lessThan(10)\r
.selectDistinct(length(p.productName));\r
+ // Formerly used orderBy(1) here, but that is not portable across DBs\r
+ Collections.sort(lengths);\r
assertEquals("[4, 5]", lengths.toString());\r
}\r
\r
ComplexObject co = new ComplexObject();\r
String sql = db.from(co).where(co.id).is(1).and(co.amount).is(1L).and(co.birthday)\r
.lessThan(new java.util.Date()).and(co.created)\r
- .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello").and(co.time)\r
- .lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value).is(new BigDecimal("1")).getSQL();\r
- assertEquals("SELECT * FROM ComplexObject " + "WHERE id = ? " + "AND amount = ? " + "AND birthday < ? "\r
- + "AND created < ? " + "AND name = ? " + "AND time < ? " + "AND value = ?", sql);\r
+ .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello")\r
+ .and(co.time).lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value)\r
+ .is(new BigDecimal("1")).getSQL();\r
+ assertEquals("SELECT * FROM ComplexObject WHERE id = ? AND amount = ? "\r
+ + "AND birthday < ? AND created < ? AND name = ? AND time < ? AND value = ?", sql);\r
\r
long count = db.from(co).where(co.id).is(1).and(co.amount).is(1L).and(co.birthday)\r
.lessThan(new java.util.Date()).and(co.created)\r
- .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello").and(co.time)\r
- .lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value).is(new BigDecimal("1")).selectCount();\r
+ .lessThan(java.sql.Timestamp.valueOf("2005-05-05 05:05:05")).and(co.name).is("hello")\r
+ .and(co.time).lessThan(java.sql.Time.valueOf("23:23:23")).and(co.value)\r
+ .is(new BigDecimal("1")).selectCount();\r
assertEquals(1, count);\r
}\r
\r
return co.id == x && co.name.equals(name) && co.name.equals("hello");\r
}\r
}).getSQL();\r
- assertEquals("SELECT * FROM ComplexObject " + "WHERE id=? " + "AND ?=name " + "AND 'hello'=name", sql);\r
+ assertEquals("SELECT * FROM ComplexObject WHERE id=? AND ?=name AND 'hello'=name", sql);\r
\r
long count = db.from(co).where(new Filter() {\r
public boolean where() {\r
// };\r
\r
final Product p = new Product();\r
- List<ProductGroup> list = db.from(p).groupBy(p.category).orderBy(1).select(new ProductGroup() {\r
- {\r
- category = p.category;\r
- productCount = count();\r
- }\r
- });\r
+ List<ProductGroup> list = db.from(p).groupBy(p.category).orderBy(p.category)\r
+ .select(new ProductGroup() {\r
+ {\r
+ category = p.category;\r
+ productCount = count();\r
+ }\r
+ });\r
\r
- assertEquals("[Beverages:2, Condiments:5, " + "Meat/Poultry:1, Produce:1, Seafood:1]", list.toString());\r
+ assertEquals("[Beverages:2, Condiments:5, Meat/Poultry:1, Produce:1, Seafood:1]", list.toString());\r
}\r
\r
}\r
import com.iciql.Iciql.IQTable;
/**
- * Tests if UUID type.
+ * Tests of UUID type.
+ * <p>
+ * H2 only.
*/
public class UUIDTest {
@Before
public void setUp() throws Exception {
- db = Db.open("jdbc:h2:mem:", "sa", "sa");
+ db = IciqlSuite.openDb();
db.insertAll(Product.getList());
db.insertAll(Customer.getList());
db.insertAll(Order.getList());
import java.util.Arrays;\r
import java.util.List;\r
\r
+import com.iciql.Iciql.IQColumn;\r
+import com.iciql.Iciql.IQTable;\r
+\r
/**\r
* A table containing customer data.\r
*/\r
+@IQTable\r
public class Customer {\r
\r
+ @IQColumn(length = 25)\r
public String customerId;\r
+ \r
+ @IQColumn(length = 2)\r
public String region;\r
\r
public Customer() {\r
}\r
\r
public static List<Customer> getList() {\r
- Customer[] list = { new Customer("ALFKI", "WA"), new Customer("ANATR", "WA"), new Customer("ANTON", "CA") };\r
+ Customer[] list = { new Customer("ALFKI", "WA"), new Customer("ANATR", "WA"),\r
+ new Customer("ANTON", "CA") };\r
return Arrays.asList(list);\r
}\r
\r
\r
package com.iciql.test.models;\r
\r
+import static com.iciql.Define.length;\r
import static com.iciql.Define.primaryKey;\r
+import static com.iciql.Define.scale;\r
import static com.iciql.Define.tableName;\r
\r
import java.math.BigDecimal;\r
import java.util.Date;\r
import java.util.List;\r
\r
+\r
import com.iciql.Iciql;\r
\r
/**\r
public class Order implements Iciql {\r
public String customerId;\r
public Integer orderId;\r
- public Date orderDate;\r
+ public Date orderDate; \r
public BigDecimal total;\r
\r
public Order(String customerId, Integer orderId, String total, String orderDate) {\r
\r
public void defineIQ() {\r
tableName("Orders");\r
+ length(customerId, 25);\r
+ length(total, 10);\r
+ scale(total, 2);\r
primaryKey(customerId, orderId);\r
}\r
\r
public void defineIQ() {\r
tableName("Product");\r
primaryKey(productId);\r
+ length(productName, 255);\r
length(category, 255);\r
index(productName, category);\r
}\r
@IQColumn(name = "cat", length = 15, trim = true)
public String category;
- @IQColumn(name = "name")
- private String productName;
+ @IQColumn(name = "name", length = 50)
+ public String productName;
@SuppressWarnings("unused")
@IQColumn
@IQColumn(name = "id", primaryKey = true)
private Integer productId;
- @IQColumn(name = "name")
+ @IQColumn(name = "name", length = 255)
private String productName;
public ProductMixedAnnotation() {
package com.iciql.test.models;
import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.List;
import java.util.Random;
@IQColumn
private Double myDouble;
- @IQColumn
+ // scale change must match the test value scale
+ @IQColumn(length = 10, scale = 5)
private BigDecimal myBigDecimal;
- @IQColumn
+ @IQColumn(length = 40)
private String myString;
@IQColumn
s.myFloat = new Float(rand.nextFloat());
s.myDouble = new Double(rand.nextDouble());
s.myBigDecimal = new BigDecimal(rand.nextDouble());
+ // scale must match annotation
+ s.myBigDecimal = s.myBigDecimal.setScale(5, RoundingMode.UP);
s.myString = Long.toHexString(rand.nextLong());
s.myUtilDate = new java.util.Date(rand.nextLong());
s.mySqlDate = new java.sql.Date(rand.nextLong());
same &= myLong.equals(s.myLong);
same &= myFloat.equals(s.myFloat);
same &= myDouble.equals(s.myDouble);
- same &= myBigDecimal.equals(s.myBigDecimal);
- same &= myUtilDate.getTime() == s.myUtilDate.getTime();
- same &= mySqlTimestamp.getTime() == s.mySqlTimestamp.getTime();
+ same &= myBigDecimal.compareTo(s.myBigDecimal) == 0;
+ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ same &= df.format(myUtilDate).equals(df.format(s.myUtilDate));
+ same &= df.format(mySqlTimestamp).equals(df.format(s.mySqlTimestamp));
same &= mySqlDate.toString().equals(s.mySqlDate.toString());
same &= mySqlTime.toString().equals(s.mySqlTime.toString());
same &= myString.equals(s.myString);
- same &= compare(myBlob, s.myBlob);
+ same &= Arrays.equals(myBlob, s.myBlob);
same &= myDefaultFlower.equals(s.myDefaultFlower);
same &= myFavoriteFlower.equals(s.myFavoriteFlower);
same &= myOtherFavoriteFlower.equals(s.myOtherFavoriteFlower);
same &= myOtherFavoriteTree.equals(s.myOtherFavoriteTree);
return same;
}
-
- private boolean compare(byte[] a, byte[] b) {
- if (b == null) {
- return false;
- }
- if (a.length != b.length) {
- return false;
- }
- for (int i = 0; i < a.length; i++) {
- if (a[i] != b[i]) {
- return false;
- }
- }
- return true;
- }
-
+
/**
* This class demonstrates the table upgrade.
*/