0001: /*
0002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003: * Distributed under the terms of either:
0004: * - the common development and distribution license (CDDL), v1.0; or
0005: * - the GNU Lesser General Public License, v2.1 or later
0006: * $Id: TestUpdateMysql.java 3695 2007-03-16 09:26:50Z gbevin $
0007: */
0008: package com.uwyn.rife.database.queries;
0009:
0010: import com.uwyn.rife.database.BeanImpl;
0011: import com.uwyn.rife.database.BeanImplConstrained;
0012: import com.uwyn.rife.database.DbPreparedStatement;
0013: import com.uwyn.rife.database.DbPreparedStatementHandler;
0014: import com.uwyn.rife.database.exceptions.FieldsRequiredException;
0015: import com.uwyn.rife.database.exceptions.TableNameRequiredException;
0016: import com.uwyn.rife.database.types.SqlNull;
0017: import java.math.BigDecimal;
0018: import java.sql.Time;
0019: import java.sql.Timestamp;
0020: import java.util.Arrays;
0021: import java.util.Calendar;
0022:
0023: public class TestUpdateMysql extends TestUpdate {
0024: public TestUpdateMysql(String name) {
0025: super (name);
0026: }
0027:
0028: public void testInstantiationMysql() {
0029: Update query = new Update(mMysql);
0030: assertNotNull(query);
0031: try {
0032: query.getSql();
0033: fail();
0034: } catch (TableNameRequiredException e) {
0035: assertEquals(e.getQueryName(), "Update");
0036: }
0037: }
0038:
0039: public void testIncompleteQueryMysql() {
0040: Update query = new Update(mMysql);
0041: try {
0042: query.getSql();
0043: fail();
0044: } catch (TableNameRequiredException e) {
0045: assertEquals(e.getQueryName(), "Update");
0046: }
0047: query.table("tablename4");
0048: try {
0049: query.getSql();
0050: fail();
0051: } catch (FieldsRequiredException e) {
0052: assertEquals(e.getQueryName(), "Update");
0053: }
0054: query.field("col1", "val1");
0055: assertNotNull(query.getSql());
0056: }
0057:
0058: public void testClearMysql() {
0059: Update query = new Update(mMysql);
0060: query.table("tablename4").field("col1", "val1");
0061: assertNotNull(query.getSql());
0062: query.clear();
0063: try {
0064: query.getSql();
0065: fail();
0066: } catch (TableNameRequiredException e) {
0067: assertEquals(e.getQueryName(), "Update");
0068: }
0069: }
0070:
0071: public void testHintMysql() {
0072: Update query = new Update(mMysql);
0073: query.hint("LOW_PRIORITY").table("tablename").field(
0074: "propertyLong", 45L);
0075: assertEquals(query.getSql(),
0076: "UPDATE LOW_PRIORITY tablename SET propertyLong = 45");
0077: assertTrue(execute(query));
0078: }
0079:
0080: public void testFieldMysql() {
0081: Calendar cal = Calendar.getInstance();
0082: cal.set(2002, 7, 19, 12, 17, 52);
0083: Update query = new Update(mMysql);
0084: query.table("tablename").where("propertyByte = 89").field(
0085: "nullColumn", SqlNull.NULL).field("propertyBigDecimal",
0086: new BigDecimal("98347.876438637")).field(
0087: "propertyBoolean", true).field("propertyByte",
0088: (byte) 16).field("propertyCalendar", cal.getTime())
0089: .field("propertyChar", 'M').field("propertyDate", cal)
0090: .field("propertyDouble", 12.3d).field("propertyFloat",
0091: 13.4f).field("propertyInt", 34).field(
0092: "propertyLong", 45L).field("propertyShort",
0093: (short) 12).field("propertySqlDate",
0094: new java.sql.Date(cal.getTime().getTime()))
0095: .field("propertyString", "string'value").field(
0096: "propertyStringbuffer",
0097: new StringBuffer("stringbuffer'value")).field(
0098: "propertyTime",
0099: new Time(cal.getTime().getTime())).field(
0100: "propertyTimestamp",
0101: new Timestamp(cal.getTime().getTime()));
0102: assertEquals(
0103: query.getSql(),
0104: "UPDATE tablename SET nullColumn = NULL, propertyBigDecimal = 98347.876438637, propertyBoolean = 1, propertyByte = 16, propertyCalendar = '2002-08-19 12:17:52.0', propertyChar = 'M', propertyDate = '2002-08-19 12:17:52.0', propertyDouble = 12.3, propertyFloat = 13.4, propertyInt = 34, propertyLong = 45, propertyShort = 12, propertySqlDate = '2002-08-19', propertyString = 'string''value', propertyStringbuffer = 'stringbuffer''value', propertyTime = '12:17:52', propertyTimestamp = '2002-08-19 12:17:52.0' WHERE propertyByte = 89");
0105: assertTrue(execute(query));
0106: }
0107:
0108: public void testFieldCustomMysql() {
0109: Update query = new Update(mMysql);
0110: query.table("tablename")
0111: .fieldCustom("propertySqlDate", "now()");
0112: assertEquals(query.getSql(),
0113: "UPDATE tablename SET propertySqlDate = now()");
0114: assertTrue(execute(query));
0115: }
0116:
0117: public void testFieldParametersMysql() {
0118: Update query = new Update(mMysql);
0119: query.table("tablename");
0120:
0121: assertNull(query.getParameters());
0122:
0123: query.fieldParameter("nullColumn").fieldParameter(
0124: "propertyBigDecimal").fieldParameter("propertyBoolean")
0125: .fieldParameter("propertyByte").fieldParameter(
0126: "propertyCalendar").fieldParameter(
0127: "propertyChar").fieldParameter("propertyDate")
0128: .fieldParameter("propertyDouble").fieldParameter(
0129: "propertyFloat").fieldParameter("propertyInt")
0130: .fieldParameter("propertyLong").fieldParameter(
0131: "propertyShort").fieldParameter(
0132: "propertySqlDate").fieldParameter(
0133: "propertyString").fieldParameter(
0134: "propertyStringbuffer").fieldParameter(
0135: "propertyTime").fieldParameter(
0136: "propertyTimestamp");
0137:
0138: assertEquals(query.getParameters().getOrderedNames().size(), 17);
0139: assertEquals(query.getParameters().getOrderedNames().get(0),
0140: "nullColumn");
0141: assertEquals(query.getParameters().getOrderedNames().get(1),
0142: "propertyBigDecimal");
0143: assertEquals(query.getParameters().getOrderedNames().get(2),
0144: "propertyBoolean");
0145: assertEquals(query.getParameters().getOrderedNames().get(3),
0146: "propertyByte");
0147: assertEquals(query.getParameters().getOrderedNames().get(4),
0148: "propertyCalendar");
0149: assertEquals(query.getParameters().getOrderedNames().get(5),
0150: "propertyChar");
0151: assertEquals(query.getParameters().getOrderedNames().get(6),
0152: "propertyDate");
0153: assertEquals(query.getParameters().getOrderedNames().get(7),
0154: "propertyDouble");
0155: assertEquals(query.getParameters().getOrderedNames().get(8),
0156: "propertyFloat");
0157: assertEquals(query.getParameters().getOrderedNames().get(9),
0158: "propertyInt");
0159: assertEquals(query.getParameters().getOrderedNames().get(10),
0160: "propertyLong");
0161: assertEquals(query.getParameters().getOrderedNames().get(11),
0162: "propertyShort");
0163: assertEquals(query.getParameters().getOrderedNames().get(12),
0164: "propertySqlDate");
0165: assertEquals(query.getParameters().getOrderedNames().get(13),
0166: "propertyString");
0167: assertEquals(query.getParameters().getOrderedNames().get(14),
0168: "propertyStringbuffer");
0169: assertEquals(query.getParameters().getOrderedNames().get(15),
0170: "propertyTime");
0171: assertEquals(query.getParameters().getOrderedNames().get(16),
0172: "propertyTimestamp");
0173: assertTrue(Arrays.equals(query.getParameters()
0174: .getOrderedNamesArray(), new String[] { "nullColumn",
0175: "propertyBigDecimal", "propertyBoolean",
0176: "propertyByte", "propertyCalendar", "propertyChar",
0177: "propertyDate", "propertyDouble", "propertyFloat",
0178: "propertyInt", "propertyLong", "propertyShort",
0179: "propertySqlDate", "propertyString",
0180: "propertyStringbuffer", "propertyTime",
0181: "propertyTimestamp" }));
0182:
0183: assertEquals(
0184: query.getSql(),
0185: "UPDATE tablename SET nullColumn = ?, propertyBigDecimal = ?, propertyBoolean = ?, propertyByte = ?, propertyCalendar = ?, propertyChar = ?, propertyDate = ?, propertyDouble = ?, propertyFloat = ?, propertyInt = ?, propertyLong = ?, propertyShort = ?, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = ?, propertyTime = ?, propertyTimestamp = ?");
0186: assertTrue(execute(query, new DbPreparedStatementHandler() {
0187: public void setParameters(DbPreparedStatement statement) {
0188: Calendar cal = Calendar.getInstance();
0189: cal.set(2002, 7, 19, 12, 17, 52);
0190: cal.set(Calendar.MILLISECOND, 462);
0191: statement.setString(1, null).setBigDecimal(2,
0192: new BigDecimal("98347.876438637")).setBoolean(
0193: 3, true).setByte(4, (byte) 16).setDate(5,
0194: new java.sql.Date(cal.getTime().getTime()))
0195: .setString(6, "M").setDate(
0196: 7,
0197: new java.sql.Date(cal.getTime()
0198: .getTime()))
0199: .setDouble(8, 12.3d).setFloat(9, 13.4f).setInt(
0200: 10, 34).setLong(11, 45L).setShort(12,
0201: (short) 12).setDate(
0202: 13,
0203: new java.sql.Date(cal.getTime()
0204: .getTime())).setString(14,
0205: "string'value").setString(15,
0206: "string'value2").setTime(16,
0207: new Time(cal.getTime().getTime()))
0208: .setTimestamp(17,
0209: new Timestamp(cal.getTime().getTime()));
0210: }
0211: }));
0212: }
0213:
0214: public void testFieldParametersMixedMysql() {
0215: Update query = new Update(mMysql);
0216: query.table("tablename");
0217:
0218: assertNull(query.getParameters());
0219:
0220: final Calendar cal = Calendar.getInstance();
0221: cal.set(2002, 7, 19, 12, 17, 52);
0222: cal.set(Calendar.MILLISECOND, 462);
0223: query.fieldParameter("nullColumn").field("propertyBigDecimal",
0224: new BigDecimal("98347.876438637")).fieldParameter(
0225: "propertyBoolean").fieldParameter("propertyByte")
0226: .field("propertyCalendar", cal.getTime())
0227: .fieldParameter("propertyChar").field("propertyDate",
0228: cal).field("propertyDouble", 12.3d)
0229: .fieldParameter("propertyFloat").fieldParameter(
0230: "propertyInt").field("propertyLong", 45L)
0231: .field("propertyShort", (short) 12).fieldParameter(
0232: "propertySqlDate").fieldParameter(
0233: "propertyString").field("propertyStringbuffer",
0234: new StringBuffer("stringbuffer'value")).field(
0235: "propertyTime",
0236: new Time(cal.getTime().getTime()))
0237: .fieldParameter("propertyTimestamp");
0238:
0239: assertEquals(query.getParameters().getOrderedNames().size(), 9);
0240: assertEquals(query.getParameters().getOrderedNames().get(0),
0241: "nullColumn");
0242: assertEquals(query.getParameters().getOrderedNames().get(1),
0243: "propertyBoolean");
0244: assertEquals(query.getParameters().getOrderedNames().get(2),
0245: "propertyByte");
0246: assertEquals(query.getParameters().getOrderedNames().get(3),
0247: "propertyChar");
0248: assertEquals(query.getParameters().getOrderedNames().get(4),
0249: "propertyFloat");
0250: assertEquals(query.getParameters().getOrderedNames().get(5),
0251: "propertyInt");
0252: assertEquals(query.getParameters().getOrderedNames().get(6),
0253: "propertySqlDate");
0254: assertEquals(query.getParameters().getOrderedNames().get(7),
0255: "propertyString");
0256: assertEquals(query.getParameters().getOrderedNames().get(8),
0257: "propertyTimestamp");
0258: assertTrue(Arrays.equals(query.getParameters()
0259: .getOrderedNamesArray(), new String[] { "nullColumn",
0260: "propertyBoolean", "propertyByte", "propertyChar",
0261: "propertyFloat", "propertyInt", "propertySqlDate",
0262: "propertyString", "propertyTimestamp" }));
0263:
0264: assertEquals(
0265: query.getSql(),
0266: "UPDATE tablename SET nullColumn = ?, propertyBigDecimal = 98347.876438637, propertyBoolean = ?, propertyByte = ?, propertyCalendar = '2002-08-19 12:17:52.0', propertyChar = ?, propertyDate = '2002-08-19 12:17:52.0', propertyDouble = 12.3, propertyFloat = ?, propertyInt = ?, propertyLong = 45, propertyShort = 12, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = 'stringbuffer''value', propertyTime = '12:17:52', propertyTimestamp = ?");
0267: assertTrue(execute(query, new DbPreparedStatementHandler() {
0268: public void setParameters(DbPreparedStatement statement) {
0269: statement.setString(1, null).setBoolean(2, true)
0270: .setByte(3, (byte) 16).setString(4, "M")
0271: .setFloat(5, 13.4f).setInt(6, 34).setDate(
0272: 7,
0273: new java.sql.Date(cal.getTime()
0274: .getTime())).setString(8,
0275: "string'value").setTimestamp(9,
0276: new Timestamp(cal.getTime().getTime()));
0277: }
0278: }));
0279: }
0280:
0281: public void testFieldsMysql() {
0282: Calendar cal = Calendar.getInstance();
0283: cal.set(2002, 7, 19, 12, 17, 52);
0284: Update query = new Update(mMysql);
0285: query.table("tablename").where("propertyByte = 89").fields(
0286: new Object[] { "nullColumn", SqlNull.NULL,
0287: "propertyBigDecimal",
0288: new BigDecimal("98347.876438637"),
0289: "propertyBoolean", new Boolean(true),
0290: "propertyByte", new Byte((byte) 16),
0291: "propertyCalendar", cal.getTime(),
0292: "propertyChar", new Character('M'),
0293: "propertyDate", cal, "propertyDouble",
0294: new Double(12.3d), "propertyFloat",
0295: new Float(13.4f), "propertyInt",
0296: new Integer(34), "propertyLong", new Long(45L),
0297: "propertyShort", new Short((short) 12),
0298: "propertySqlDate",
0299: new java.sql.Date(cal.getTime().getTime()),
0300: "propertyString", new String("string'value"),
0301: "propertyStringbuffer",
0302: new StringBuffer("stringbuffer'value"),
0303: "propertyTime",
0304: new Time(cal.getTime().getTime()),
0305: "propertyTimestamp",
0306: new Timestamp(cal.getTime().getTime()) });
0307: assertEquals(
0308: query.getSql(),
0309: "UPDATE tablename SET nullColumn = NULL, propertyBigDecimal = 98347.876438637, propertyBoolean = 1, propertyByte = 16, propertyCalendar = '2002-08-19 12:17:52.0', propertyChar = 'M', propertyDate = '2002-08-19 12:17:52.0', propertyDouble = 12.3, propertyFloat = 13.4, propertyInt = 34, propertyLong = 45, propertyShort = 12, propertySqlDate = '2002-08-19', propertyString = 'string''value', propertyStringbuffer = 'stringbuffer''value', propertyTime = '12:17:52', propertyTimestamp = '2002-08-19 12:17:52.0' WHERE propertyByte = 89");
0310: assertTrue(execute(query));
0311: }
0312:
0313: public void testWhereConstructionMysql() {
0314: Update query = new Update(mMysql);
0315: query.table("tablename").field("propertyBoolean", true).field(
0316: "propertyByte", (byte) 16).where("propertyInt = 545")
0317: .whereAnd("propertyLong < 50000").whereOr(
0318: "propertyChar = 'v'");
0319: assertEquals(
0320: query.getSql(),
0321: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545 AND propertyLong < 50000 OR propertyChar = 'v'");
0322: assertTrue(execute(query));
0323: }
0324:
0325: public void testWhereConstructionGroupMysql() {
0326: Update query = new Update(mMysql);
0327: query.table("tablename").field("propertyBoolean", true).field(
0328: "propertyByte", (byte) 16).where("propertyInt = 545")
0329: .whereAnd("propertyLong < 50000").startWhereOr()
0330: .whereParameter("propertyString", "=").whereAnd(
0331: "propertyByte", "<=", (byte) 0).startWhereAnd()
0332: .where("propertyBoolean", "!=", true).whereParameterOr(
0333: "propertyStringbuffer", "LIKE").end().end()
0334: .whereOr("propertyChar = 'v'");
0335:
0336: assertEquals(query.getParameters().getOrderedNames().get(0),
0337: "propertyString");
0338: assertEquals(query.getParameters().getOrderedNames().get(1),
0339: "propertyStringbuffer");
0340: assertTrue(Arrays.equals(query.getParameters()
0341: .getOrderedNamesArray(), new String[] {
0342: "propertyString", "propertyStringbuffer" }));
0343:
0344: assertEquals(
0345: query.getSql(),
0346: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545 AND propertyLong < 50000 OR (propertyString = ? AND propertyByte <= 0 AND (propertyBoolean != 1 OR propertyStringbuffer LIKE ?)) OR propertyChar = 'v'");
0347:
0348: assertTrue(execute(query, new DbPreparedStatementHandler() {
0349: public void setParameters(DbPreparedStatement statement) {
0350: statement
0351: .setString("propertyString", "someotherstring")
0352: .setString("propertyStringbuffer", "stringbuff");
0353: }
0354: }));
0355: }
0356:
0357: public void testWhereTypedMysql() {
0358: Update query = new Update(mMysql);
0359: query.table("tablename").field("propertyBoolean", true).field(
0360: "propertyByte", (byte) 16);
0361:
0362: Calendar cal = Calendar.getInstance();
0363: cal.set(2003, 2, 3, 10, 1, 28);
0364: cal.set(Calendar.MILLISECOND, 154);
0365:
0366: query.where("propertyBigDecimal", ">=",
0367: new BigDecimal("53443433.9784567")).whereAnd(
0368: "propertyBoolean", "=", false).whereOr("propertyByte",
0369: "=", (byte) 54).whereAnd("propertyCalendar", "<=", cal)
0370: .whereOr("propertyChar", "=", 'f').whereAnd(
0371: "propertyDate", "=", cal.getTime()).whereAnd(
0372: "propertyDouble", "!=", 73453.71d).whereOr(
0373: "propertyFloat", ">=", 1987.14f).whereAnd(
0374: "propertyInt", "=", 973).whereAnd(
0375: "propertyLong", "<", 347678L).whereAnd(
0376: "propertyShort", "=", (short) 78).whereOr(
0377: "propertySqlDate", "=",
0378: new java.sql.Date(cal.getTime().getTime()))
0379: .whereAnd("propertyString", "LIKE", "someotherstring%")
0380: .whereAnd("propertyStringbuffer", "=",
0381: new StringBuffer("someotherstringbuff"))
0382: .whereOr("propertyTime", "=",
0383: new Time(cal.getTime().getTime())).whereAnd(
0384: "propertyTimestamp", "<=",
0385: new Timestamp(cal.getTime().getTime()));
0386:
0387: assertEquals(
0388: query.getSql(),
0389: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= '2003-03-03 10:01:28.0' OR propertyChar = 'f' AND propertyDate = '2003-03-03 10:01:28.0' AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = '2003-03-03' AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = '10:01:28' AND propertyTimestamp <= '2003-03-03 10:01:28.0'");
0390: assertFalse(execute(query));
0391: }
0392:
0393: public void testWhereTypedMixedMysql() {
0394: Update query = new Update(mMysql);
0395: query.table("tablename").field("propertyBoolean", true).field(
0396: "propertyByte", (byte) 16);
0397:
0398: final Calendar cal = Calendar.getInstance();
0399: cal.set(2003, 2, 3, 10, 1, 28);
0400: cal.set(Calendar.MILLISECOND, 154);
0401:
0402: query.where("propertyBigDecimal", ">=",
0403: new BigDecimal("53443433.9784567")).whereAnd(
0404: "propertyBoolean", "=", false).whereOr(
0405: "propertyByte = 54").whereAnd("propertyCalendar", "<=",
0406: cal).whereOr("propertyChar", "=", 'f').whereAnd(
0407: "propertyDate", "=", cal.getTime()).whereAnd(
0408: "propertyDouble", "!=", 73453.71d).whereOr(
0409: "propertyFloat >= 1987.14").whereAnd("propertyInt",
0410: "=", 973).whereAnd("propertyLong", "<", 347678L)
0411: .whereAnd("propertyShort", "=", (short) 78)
0412: .whereParameterOr("propertySqlDate", "=").whereAnd(
0413: "propertyString", "LIKE", "someotherstring%")
0414: .whereAnd("propertyStringbuffer", "=",
0415: new StringBuffer("someotherstringbuff"))
0416: .whereOr("propertyTime", "=",
0417: new Time(cal.getTime().getTime())).whereAnd(
0418: "propertyTimestamp", "<=",
0419: new Timestamp(cal.getTime().getTime()));
0420:
0421: assertEquals(
0422: query.getSql(),
0423: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= '2003-03-03 10:01:28.0' OR propertyChar = 'f' AND propertyDate = '2003-03-03 10:01:28.0' AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = ? AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = '10:01:28' AND propertyTimestamp <= '2003-03-03 10:01:28.0'");
0424:
0425: assertFalse(execute(query, new DbPreparedStatementHandler() {
0426: public void setParameters(DbPreparedStatement statement) {
0427: statement.setDate("propertySqlDate", new java.sql.Date(
0428: cal.getTime().getTime()));
0429: }
0430: }));
0431: }
0432:
0433: public void testWhereParametersMysql() {
0434: Update query = new Update(mMysql);
0435: query.table("tablename").field("propertyBoolean", true).field(
0436: "propertyByte", (byte) 16);
0437:
0438: assertNull(query.getParameters());
0439:
0440: query.whereParameter("propertyInt", "=").whereParameterAnd(
0441: "propertyLong", "<").whereParameterOr("propertyChar",
0442: "=");
0443:
0444: assertEquals(query.getParameters().getOrderedNames().size(), 3);
0445: assertEquals(query.getParameters().getOrderedNames().get(0),
0446: "propertyInt");
0447: assertEquals(query.getParameters().getOrderedNames().get(1),
0448: "propertyLong");
0449: assertEquals(query.getParameters().getOrderedNames().get(2),
0450: "propertyChar");
0451: assertTrue(Arrays.equals(query.getParameters()
0452: .getOrderedNamesArray(), new String[] { "propertyInt",
0453: "propertyLong", "propertyChar" }));
0454:
0455: assertEquals(
0456: query.getSql(),
0457: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
0458: assertTrue(execute(query, new DbPreparedStatementHandler() {
0459: public void setParameters(DbPreparedStatement statement) {
0460: statement.setInt(1, 545).setLong(2, 50000).setString(3,
0461: "v");
0462: }
0463: }));
0464:
0465: query.where("propertyInt = 545");
0466:
0467: assertNull(query.getParameters());
0468: assertEquals(
0469: query.getSql(),
0470: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545");
0471: }
0472:
0473: public void testWhereParametersMixedMysql() {
0474: Update query = new Update(mMysql);
0475: query.table("tablename").field("propertyBoolean", true).field(
0476: "propertyByte", (byte) 16).where("propertyInt = 545")
0477: .whereParameterAnd("propertyLong", "<")
0478: .whereParameterOr("propertyChar", "=");
0479:
0480: assertEquals(query.getParameters().getOrderedNames().get(0),
0481: "propertyLong");
0482: assertEquals(query.getParameters().getOrderedNames().get(1),
0483: "propertyChar");
0484: assertTrue(Arrays.equals(query.getParameters()
0485: .getOrderedNamesArray(), new String[] { "propertyLong",
0486: "propertyChar" }));
0487:
0488: assertEquals(
0489: query.getSql(),
0490: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545 AND propertyLong < ? OR propertyChar = ?");
0491: assertTrue(execute(query, new DbPreparedStatementHandler() {
0492: public void setParameters(DbPreparedStatement statement) {
0493: statement.setLong(1, 50000).setString(2, "v");
0494: }
0495: }));
0496:
0497: query.where("propertyInt = 545");
0498:
0499: assertNull(query.getParameters());
0500: assertEquals(
0501: query.getSql(),
0502: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545");
0503: }
0504:
0505: public void testFieldWhereParametersMysql() {
0506: Update query = new Update(mMysql);
0507: query.table("tablename");
0508:
0509: assertNull(query.getParameters());
0510:
0511: query.fieldParameter("propertyBoolean").fieldParameter(
0512: "propertyByte");
0513:
0514: assertEquals(query.getParameters().getOrderedNames().size(), 2);
0515: assertEquals(query.getParameters().getOrderedNames().get(0),
0516: "propertyBoolean");
0517: assertEquals(query.getParameters().getOrderedNames().get(1),
0518: "propertyByte");
0519: assertTrue(Arrays.equals(query.getParameters()
0520: .getOrderedNamesArray(), new String[] {
0521: "propertyBoolean", "propertyByte" }));
0522:
0523: query.whereParameter("propertyInt", "=").whereParameterAnd(
0524: "propertyLong", "<").whereParameterOr("propertyChar",
0525: "=");
0526:
0527: assertEquals(query.getParameters().getOrderedNames().size(), 5);
0528: assertEquals(query.getParameters().getOrderedNames().get(0),
0529: "propertyBoolean");
0530: assertEquals(query.getParameters().getOrderedNames().get(1),
0531: "propertyByte");
0532: assertEquals(query.getParameters().getOrderedNames().get(2),
0533: "propertyInt");
0534: assertEquals(query.getParameters().getOrderedNames().get(3),
0535: "propertyLong");
0536: assertEquals(query.getParameters().getOrderedNames().get(4),
0537: "propertyChar");
0538: assertTrue(Arrays.equals(query.getParameters()
0539: .getOrderedNamesArray(), new String[] {
0540: "propertyBoolean", "propertyByte", "propertyInt",
0541: "propertyLong", "propertyChar" }));
0542:
0543: assertEquals(
0544: query.getSql(),
0545: "UPDATE tablename SET propertyBoolean = ?, propertyByte = ? WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
0546: assertTrue(execute(query, new DbPreparedStatementHandler() {
0547: public void setParameters(DbPreparedStatement statement) {
0548: statement.setBoolean(1, true).setByte(2, (byte) 16)
0549: .setInt(3, 545).setLong(4, 50000).setString(5,
0550: "v");
0551: }
0552: }));
0553:
0554: query.where("propertyInt = 545");
0555:
0556: assertEquals(query.getParameters().getOrderedNames().size(), 2);
0557: assertEquals(
0558: query.getParameters().getOrderedNamesArray().length, 2);
0559: assertEquals(query.getParameters().getOrderedNames().get(0),
0560: "propertyBoolean");
0561: assertEquals(query.getParameters().getOrderedNames().get(1),
0562: "propertyByte");
0563: assertTrue(Arrays.equals(query.getParameters()
0564: .getOrderedNamesArray(), new String[] {
0565: "propertyBoolean", "propertyByte" }));
0566: assertEquals(
0567: query.getSql(),
0568: "UPDATE tablename SET propertyBoolean = ?, propertyByte = ? WHERE propertyInt = 545");
0569: }
0570:
0571: public void testFieldsBeanMysql() {
0572: Update query = new Update(mMysql);
0573: query.table("tablename").where("propertyInt = 545").fields(
0574: BeanImpl.getPopulatedBean());
0575: assertEquals(
0576: query.getSql(),
0577: "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByte = 89, propertyByteObject = 34, propertyCalendar = '2002-06-18 15:26:14.0', propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = '2002-06-18 15:26:14.0', propertyDouble = 53348.34, propertyDoubleObject = 143298.692, propertyEnum = 'VALUE_THREE', propertyFloat = 98634.2, propertyFloatObject = 8734.7, propertyInt = 545, propertyIntegerObject = 968, propertyLong = 34563, propertyLongObject = 66875, propertyShort = 43, propertyShortObject = 68, propertySqlDate = '2002-06-18', propertyString = 'someotherstring', propertyStringbuffer = 'someotherstringbuff', propertyTime = '15:26:14', propertyTimestamp = '2002-06-18 15:26:14.0' WHERE propertyInt = 545");
0578: assertTrue(execute(query));
0579: }
0580:
0581: public void testFieldsBeanConstrainedMysql() {
0582: Update query = new Update(mMysql);
0583: query.table("tablename").where("propertyInt = 545").fields(
0584: BeanImplConstrained.getPopulatedBean());
0585: assertEquals(
0586: query.getSql(),
0587: "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByteObject = 34, propertyCalendar = '2002-06-18 15:26:14.0', propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = '2002-06-18 15:26:14.0', propertyDouble = 53348.34, propertyDoubleObject = 143298.692, propertyFloat = 98634.2, propertyFloatObject = 8734.7, propertyInt = 545, propertyIntegerObject = 968, propertyLongObject = 66875, propertyShort = 43, propertySqlDate = '2002-06-18', propertyString = 'someotherstring', propertyStringbuffer = 'someotherstringbuff', propertyTime = '15:26:14', propertyTimestamp = '2002-06-18 15:26:14.0' WHERE propertyInt = 545");
0588: assertTrue(execute(query));
0589: }
0590:
0591: public void testFieldsBeanNullValuesMysql() {
0592: Update query = new Update(mMysql);
0593: query.table("tablename").where("propertyInt = 545").fields(
0594: BeanImpl.getNullBean());
0595: assertEquals(
0596: query.getSql(),
0597: "UPDATE tablename SET propertyBoolean = 0, propertyBooleanObject = 0, propertyByte = 0, propertyByteObject = 0, propertyDouble = 0.0, propertyDoubleObject = 0.0, propertyFloat = 0.0, propertyFloatObject = 0.0, propertyInt = 0, propertyIntegerObject = 0, propertyLong = 0, propertyLongObject = 0, propertyShort = 0, propertyShortObject = 0 WHERE propertyInt = 545");
0598: assertTrue(execute(query));
0599: }
0600:
0601: public void testFieldsBeanIncludedMysql() {
0602: Update query = new Update(mMysql);
0603: query
0604: .table("tablename")
0605: .where("propertyInt = 545")
0606: .fieldsIncluded(
0607: BeanImpl.getPopulatedBean(),
0608: new String[] { "propertyByte",
0609: "propertyDouble", "propertyShort",
0610: "propertyStringbuffer", "propertyTime" });
0611: assertEquals(
0612: query.getSql(),
0613: "UPDATE tablename SET propertyByte = 89, propertyDouble = 53348.34, propertyShort = 43, propertyStringbuffer = 'someotherstringbuff', propertyTime = '15:26:14' WHERE propertyInt = 545");
0614: assertTrue(execute(query));
0615: }
0616:
0617: public void testFieldsBeanExcludedMysql() {
0618: Update query = new Update(mMysql);
0619: query
0620: .table("tablename")
0621: .where("propertyInt = 545")
0622: .fieldsExcluded(
0623: BeanImpl.getPopulatedBean(),
0624: new String[] { "propertyByte",
0625: "propertyDouble", "propertyShort",
0626: "propertyStringbuffer", "propertyTime" });
0627: assertEquals(
0628: query.getSql(),
0629: "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByteObject = 34, propertyCalendar = '2002-06-18 15:26:14.0', propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = '2002-06-18 15:26:14.0', propertyDoubleObject = 143298.692, propertyEnum = 'VALUE_THREE', propertyFloat = 98634.2, propertyFloatObject = 8734.7, propertyInt = 545, propertyIntegerObject = 968, propertyLong = 34563, propertyLongObject = 66875, propertyShortObject = 68, propertySqlDate = '2002-06-18', propertyString = 'someotherstring', propertyTimestamp = '2002-06-18 15:26:14.0' WHERE propertyInt = 545");
0630: assertTrue(execute(query));
0631: }
0632:
0633: public void testFieldsBeanFilteredMysql() {
0634: Update query = new Update(mMysql);
0635: query
0636: .table("tablename")
0637: .where("propertyInt = 545")
0638: .fieldsFiltered(
0639: BeanImpl.getPopulatedBean(),
0640: new String[] { "propertyByte",
0641: "propertyDouble", "propertyShort",
0642: "propertyStringbuffer", "propertyTime" },
0643: new String[] { "propertyByte", "propertyShort",
0644: "propertyTime" });
0645: assertEquals(
0646: query.getSql(),
0647: "UPDATE tablename SET propertyDouble = 53348.34, propertyStringbuffer = 'someotherstringbuff' WHERE propertyInt = 545");
0648: assertTrue(execute(query));
0649: }
0650:
0651: public void testFieldsParametersBeanMysql() {
0652: Update query = new Update(mMysql);
0653: query.table("tablename").fieldsParameters(BeanImpl.class);
0654: assertEquals(
0655: query.getSql(),
0656: "UPDATE tablename SET propertyBigDecimal = ?, propertyBoolean = ?, propertyBooleanObject = ?, propertyByte = ?, propertyByteObject = ?, propertyCalendar = ?, propertyChar = ?, propertyCharacterObject = ?, propertyDate = ?, propertyDouble = ?, propertyDoubleObject = ?, propertyEnum = ?, propertyFloat = ?, propertyFloatObject = ?, propertyInt = ?, propertyIntegerObject = ?, propertyLong = ?, propertyLongObject = ?, propertyShort = ?, propertyShortObject = ?, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = ?, propertyTime = ?, propertyTimestamp = ?");
0657:
0658: assertEquals(query.getParameters().getOrderedNames().size(), 25);
0659: assertEquals(query.getParameters().getOrderedNames().get(0),
0660: "propertyBigDecimal");
0661: assertEquals(query.getParameters().getOrderedNames().get(1),
0662: "propertyBoolean");
0663: assertEquals(query.getParameters().getOrderedNames().get(2),
0664: "propertyBooleanObject");
0665: assertEquals(query.getParameters().getOrderedNames().get(3),
0666: "propertyByte");
0667: assertEquals(query.getParameters().getOrderedNames().get(4),
0668: "propertyByteObject");
0669: assertEquals(query.getParameters().getOrderedNames().get(5),
0670: "propertyCalendar");
0671: assertEquals(query.getParameters().getOrderedNames().get(6),
0672: "propertyChar");
0673: assertEquals(query.getParameters().getOrderedNames().get(7),
0674: "propertyCharacterObject");
0675: assertEquals(query.getParameters().getOrderedNames().get(8),
0676: "propertyDate");
0677: assertEquals(query.getParameters().getOrderedNames().get(9),
0678: "propertyDouble");
0679: assertEquals(query.getParameters().getOrderedNames().get(10),
0680: "propertyDoubleObject");
0681: assertEquals(query.getParameters().getOrderedNames().get(11),
0682: "propertyEnum");
0683: assertEquals(query.getParameters().getOrderedNames().get(12),
0684: "propertyFloat");
0685: assertEquals(query.getParameters().getOrderedNames().get(13),
0686: "propertyFloatObject");
0687: assertEquals(query.getParameters().getOrderedNames().get(14),
0688: "propertyInt");
0689: assertEquals(query.getParameters().getOrderedNames().get(15),
0690: "propertyIntegerObject");
0691: assertEquals(query.getParameters().getOrderedNames().get(16),
0692: "propertyLong");
0693: assertEquals(query.getParameters().getOrderedNames().get(17),
0694: "propertyLongObject");
0695: assertEquals(query.getParameters().getOrderedNames().get(18),
0696: "propertyShort");
0697: assertEquals(query.getParameters().getOrderedNames().get(19),
0698: "propertyShortObject");
0699: assertEquals(query.getParameters().getOrderedNames().get(20),
0700: "propertySqlDate");
0701: assertEquals(query.getParameters().getOrderedNames().get(21),
0702: "propertyString");
0703: assertEquals(query.getParameters().getOrderedNames().get(22),
0704: "propertyStringbuffer");
0705: assertEquals(query.getParameters().getOrderedNames().get(23),
0706: "propertyTime");
0707: assertEquals(query.getParameters().getOrderedNames().get(24),
0708: "propertyTimestamp");
0709: assertTrue(Arrays.equals(query.getParameters()
0710: .getOrderedNamesArray(), new String[] {
0711: "propertyBigDecimal", "propertyBoolean",
0712: "propertyBooleanObject", "propertyByte",
0713: "propertyByteObject", "propertyCalendar",
0714: "propertyChar", "propertyCharacterObject",
0715: "propertyDate", "propertyDouble",
0716: "propertyDoubleObject", "propertyEnum",
0717: "propertyFloat", "propertyFloatObject", "propertyInt",
0718: "propertyIntegerObject", "propertyLong",
0719: "propertyLongObject", "propertyShort",
0720: "propertyShortObject", "propertySqlDate",
0721: "propertyString", "propertyStringbuffer",
0722: "propertyTime", "propertyTimestamp" }));
0723:
0724: assertTrue(execute(query, new DbPreparedStatementHandler() {
0725: public void setParameters(DbPreparedStatement statement) {
0726: Calendar cal = Calendar.getInstance();
0727: cal.set(2002, 7, 19, 12, 17, 52);
0728: cal.set(Calendar.MILLISECOND, 462);
0729: statement.setBigDecimal(1,
0730: new BigDecimal("98347.876438637")).setBoolean(
0731: 2, false).setBoolean(3, true).setByte(4,
0732: (byte) 16).setByte(5, (byte) 72)
0733: .setTimestamp(
0734: 6,
0735: new java.sql.Timestamp(cal.getTime()
0736: .getTime())).setString(7, "M")
0737: .setString(8, "p").setTimestamp(
0738: 9,
0739: new java.sql.Timestamp(cal.getTime()
0740: .getTime())).setDouble(10,
0741: 12.3d).setDouble(11, 68.7d).setString(
0742: 12, "VALUE_THREE").setFloat(13, 13.4f)
0743: .setFloat(14, 42.1f).setInt(15, 92).setInt(16,
0744: 34).setLong(17, 687L).setLong(18, 92)
0745: .setShort(19, (short) 7).setShort(20,
0746: (short) 12).setDate(
0747: 21,
0748: new java.sql.Date(cal.getTime()
0749: .getTime())).setString(22,
0750: "string'value").setString(23,
0751: "string'value2").setTime(24,
0752: new Time(cal.getTime().getTime()))
0753: .setTimestamp(25,
0754: new Timestamp(cal.getTime().getTime()));
0755: }
0756: }));
0757: }
0758:
0759: public void testFieldsParametersBeanConstrainedMysql() {
0760: Update query = new Update(mMysql);
0761: query.table("tablename").fieldsParameters(
0762: BeanImplConstrained.class);
0763: assertEquals(
0764: query.getSql(),
0765: "UPDATE tablename SET propertyBigDecimal = ?, propertyBoolean = ?, propertyBooleanObject = ?, propertyByteObject = ?, propertyCalendar = ?, propertyChar = ?, propertyCharacterObject = ?, propertyDate = ?, propertyDouble = ?, propertyDoubleObject = ?, propertyFloat = ?, propertyFloatObject = ?, propertyInt = ?, propertyIntegerObject = ?, propertyLongObject = ?, propertyShort = ?, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = ?, propertyTime = ?, propertyTimestamp = ?");
0766:
0767: assertEquals(query.getParameters().getOrderedNames().size(), 21);
0768: assertEquals(query.getParameters().getOrderedNames().get(0),
0769: "propertyBigDecimal");
0770: assertEquals(query.getParameters().getOrderedNames().get(1),
0771: "propertyBoolean");
0772: assertEquals(query.getParameters().getOrderedNames().get(2),
0773: "propertyBooleanObject");
0774: assertEquals(query.getParameters().getOrderedNames().get(3),
0775: "propertyByteObject");
0776: assertEquals(query.getParameters().getOrderedNames().get(4),
0777: "propertyCalendar");
0778: assertEquals(query.getParameters().getOrderedNames().get(5),
0779: "propertyChar");
0780: assertEquals(query.getParameters().getOrderedNames().get(6),
0781: "propertyCharacterObject");
0782: assertEquals(query.getParameters().getOrderedNames().get(7),
0783: "propertyDate");
0784: assertEquals(query.getParameters().getOrderedNames().get(8),
0785: "propertyDouble");
0786: assertEquals(query.getParameters().getOrderedNames().get(9),
0787: "propertyDoubleObject");
0788: assertEquals(query.getParameters().getOrderedNames().get(10),
0789: "propertyFloat");
0790: assertEquals(query.getParameters().getOrderedNames().get(11),
0791: "propertyFloatObject");
0792: assertEquals(query.getParameters().getOrderedNames().get(12),
0793: "propertyInt");
0794: assertEquals(query.getParameters().getOrderedNames().get(13),
0795: "propertyIntegerObject");
0796: assertEquals(query.getParameters().getOrderedNames().get(14),
0797: "propertyLongObject");
0798: assertEquals(query.getParameters().getOrderedNames().get(15),
0799: "propertyShort");
0800: assertEquals(query.getParameters().getOrderedNames().get(16),
0801: "propertySqlDate");
0802: assertEquals(query.getParameters().getOrderedNames().get(17),
0803: "propertyString");
0804: assertEquals(query.getParameters().getOrderedNames().get(18),
0805: "propertyStringbuffer");
0806: assertEquals(query.getParameters().getOrderedNames().get(19),
0807: "propertyTime");
0808: assertEquals(query.getParameters().getOrderedNames().get(20),
0809: "propertyTimestamp");
0810: assertTrue(Arrays.equals(query.getParameters()
0811: .getOrderedNamesArray(), new String[] {
0812: "propertyBigDecimal", "propertyBoolean",
0813: "propertyBooleanObject", "propertyByteObject",
0814: "propertyCalendar", "propertyChar",
0815: "propertyCharacterObject", "propertyDate",
0816: "propertyDouble", "propertyDoubleObject",
0817: "propertyFloat", "propertyFloatObject", "propertyInt",
0818: "propertyIntegerObject", "propertyLongObject",
0819: "propertyShort", "propertySqlDate", "propertyString",
0820: "propertyStringbuffer", "propertyTime",
0821: "propertyTimestamp" }));
0822:
0823: assertTrue(execute(query, new DbPreparedStatementHandler() {
0824: public void setParameters(DbPreparedStatement statement) {
0825: Calendar cal = Calendar.getInstance();
0826: cal.set(2002, 7, 19, 12, 17, 52);
0827: cal.set(Calendar.MILLISECOND, 462);
0828: statement.setBigDecimal(1,
0829: new BigDecimal("98347.876438637")).setBoolean(
0830: 2, false).setBoolean(3, true).setByte(4,
0831: (byte) 72)
0832: .setTimestamp(
0833: 5,
0834: new java.sql.Timestamp(cal.getTime()
0835: .getTime())).setString(6, "M")
0836: .setString(7, "p").setTimestamp(
0837: 8,
0838: new java.sql.Timestamp(cal.getTime()
0839: .getTime()))
0840: .setDouble(9, 12.3d).setDouble(10, 68.7d)
0841: .setFloat(11, 13.4f).setFloat(12, 42.1f)
0842: .setInt(13, 92).setInt(14, 34).setLong(15, 92)
0843: .setShort(16, (short) 7).setDate(
0844: 17,
0845: new java.sql.Date(cal.getTime()
0846: .getTime())).setString(18,
0847: "string'value").setString(19,
0848: "string'value2").setTime(20,
0849: new Time(cal.getTime().getTime()))
0850: .setTimestamp(21,
0851: new Timestamp(cal.getTime().getTime()));
0852: }
0853: }));
0854: }
0855:
0856: public void testFieldsParametersBeanExcludedMysql() {
0857: Update query = new Update(mMysql);
0858: query.table("tablename").fieldsParametersExcluded(
0859: BeanImpl.class,
0860: new String[] { "propertyBoolean", "propertyByte",
0861: "propertyChar", "propertyDouble",
0862: "propertyInt", "propertyLong",
0863: "propertySqlDate", "propertyStringbuffer",
0864: "propertyTimestamp" });
0865: assertEquals(
0866: query.getSql(),
0867: "UPDATE tablename SET propertyBigDecimal = ?, propertyBooleanObject = ?, propertyByteObject = ?, propertyCalendar = ?, propertyCharacterObject = ?, propertyDate = ?, propertyDoubleObject = ?, propertyEnum = ?, propertyFloat = ?, propertyFloatObject = ?, propertyIntegerObject = ?, propertyLongObject = ?, propertyShort = ?, propertyShortObject = ?, propertyString = ?, propertyTime = ?");
0868:
0869: assertEquals(query.getParameters().getOrderedNames().size(), 16);
0870: assertEquals(query.getParameters().getOrderedNames().get(0),
0871: "propertyBigDecimal");
0872: assertEquals(query.getParameters().getOrderedNames().get(1),
0873: "propertyBooleanObject");
0874: assertEquals(query.getParameters().getOrderedNames().get(2),
0875: "propertyByteObject");
0876: assertEquals(query.getParameters().getOrderedNames().get(3),
0877: "propertyCalendar");
0878: assertEquals(query.getParameters().getOrderedNames().get(4),
0879: "propertyCharacterObject");
0880: assertEquals(query.getParameters().getOrderedNames().get(5),
0881: "propertyDate");
0882: assertEquals(query.getParameters().getOrderedNames().get(6),
0883: "propertyDoubleObject");
0884: assertEquals(query.getParameters().getOrderedNames().get(7),
0885: "propertyEnum");
0886: assertEquals(query.getParameters().getOrderedNames().get(8),
0887: "propertyFloat");
0888: assertEquals(query.getParameters().getOrderedNames().get(9),
0889: "propertyFloatObject");
0890: assertEquals(query.getParameters().getOrderedNames().get(10),
0891: "propertyIntegerObject");
0892: assertEquals(query.getParameters().getOrderedNames().get(11),
0893: "propertyLongObject");
0894: assertEquals(query.getParameters().getOrderedNames().get(12),
0895: "propertyShort");
0896: assertEquals(query.getParameters().getOrderedNames().get(13),
0897: "propertyShortObject");
0898: assertEquals(query.getParameters().getOrderedNames().get(14),
0899: "propertyString");
0900: assertEquals(query.getParameters().getOrderedNames().get(15),
0901: "propertyTime");
0902: assertTrue(Arrays.equals(query.getParameters()
0903: .getOrderedNamesArray(), new String[] {
0904: "propertyBigDecimal", "propertyBooleanObject",
0905: "propertyByteObject", "propertyCalendar",
0906: "propertyCharacterObject", "propertyDate",
0907: "propertyDoubleObject", "propertyEnum",
0908: "propertyFloat", "propertyFloatObject",
0909: "propertyIntegerObject", "propertyLongObject",
0910: "propertyShort", "propertyShortObject",
0911: "propertyString", "propertyTime" }));
0912:
0913: assertTrue(execute(query, new DbPreparedStatementHandler() {
0914: public void setParameters(DbPreparedStatement statement) {
0915: Calendar cal = Calendar.getInstance();
0916: cal.set(2002, 7, 19, 12, 17, 52);
0917: cal.set(Calendar.MILLISECOND, 462);
0918: statement.setBigDecimal(1,
0919: new BigDecimal("98347.876438637")).setBoolean(
0920: 2, true).setByte(3, (byte) 72)
0921: .setTimestamp(
0922: 4,
0923: new java.sql.Timestamp(cal.getTime()
0924: .getTime())).setString(5, "o")
0925: .setTimestamp(
0926: 6,
0927: new java.sql.Timestamp(cal.getTime()
0928: .getTime()))
0929: .setDouble(7, 86.7d)
0930: .setString(8, "VALUE_THREE").setFloat(9, 13.4f)
0931: .setFloat(10, 32.8f).setInt(11, 358).setLong(
0932: 12, 9680L).setShort(13, (short) 12)
0933: .setShort(14, (short) 78).setString(15,
0934: "string'value").setTime(16,
0935: new Time(cal.getTime().getTime()));
0936: }
0937: }));
0938: }
0939:
0940: public void testWhereBeanMysql() {
0941: Update query = new Update(mMysql);
0942: query.table("tablename").field("propertyBoolean", true).field(
0943: "propertyByte", (byte) 16).where(
0944: BeanImpl.getPopulatedBean());
0945: assertEquals(
0946: query.getSql(),
0947: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = '2002-06-18 15:26:14.0' AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = '2002-06-18 15:26:14.0' AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertyShortObject = 68 AND propertySqlDate = '2002-06-18' AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = '15:26:14' AND propertyTimestamp = '2002-06-18 15:26:14.0'");
0948: // mysql doesn't compare correctly on floats, thus don't execute
0949: }
0950:
0951: public void testWhereBeanConstrainedMysql() {
0952: Update query = new Update(mMysql);
0953: query.table("tablename").field("propertyBoolean", true).field(
0954: "propertyByte", (byte) 16).where(
0955: BeanImplConstrained.getPopulatedBean());
0956: assertEquals(
0957: query.getSql(),
0958: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByte = 89 AND propertyByteObject = 34 AND propertyCalendar = '2002-06-18 15:26:14.0' AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = '2002-06-18 15:26:14.0' AND propertyDouble = 53348.34 AND propertyDoubleObject = 143298.692 AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLongObject = 66875 AND propertyShort = 43 AND propertySqlDate = '2002-06-18' AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = '15:26:14' AND propertyTimestamp = '2002-06-18 15:26:14.0'");
0959: // mysql doesn't compare correctly on floats, thus don't execute
0960: }
0961:
0962: public void testWhereBeanNullValuesMysql() {
0963: Update query = new Update(mMysql);
0964: query.table("tablename").field("propertyBoolean", true).field(
0965: "propertyByte", (byte) 16)
0966: .where(BeanImpl.getNullBean());
0967: assertEquals(
0968: query.getSql(),
0969: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBoolean = 0 AND propertyBooleanObject = 0 AND propertyByte = 0 AND propertyByteObject = 0 AND propertyDouble = 0.0 AND propertyDoubleObject = 0.0 AND propertyFloat = 0.0 AND propertyFloatObject = 0.0 AND propertyInt = 0 AND propertyIntegerObject = 0 AND propertyLong = 0 AND propertyLongObject = 0 AND propertyShort = 0 AND propertyShortObject = 0");
0970: assertTrue(execute(query));
0971: }
0972:
0973: public void testWhereBeanIncludedMysql() {
0974: Update query = new Update(mMysql);
0975: query.table("tablename").field("propertyBoolean", true).field(
0976: "propertyByte", (byte) 16).whereIncluded(
0977: BeanImpl.getPopulatedBean(),
0978: new String[] { "propertyByte", "propertyDouble",
0979: "propertyShort", "propertyStringbuffer",
0980: "propertyTime" });
0981: assertEquals(
0982: query.getSql(),
0983: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyByte = 89 AND propertyDouble = 53348.34 AND propertyShort = 43 AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = '15:26:14'");
0984: assertTrue(execute(query));
0985: }
0986:
0987: public void testWhereBeanExcludedMysql() {
0988: Update query = new Update(mMysql);
0989: query.table("tablename").field("propertyBoolean", true).field(
0990: "propertyByte", (byte) 16).whereExcluded(
0991: BeanImpl.getPopulatedBean(),
0992: new String[] { "propertyByte", "propertyDouble",
0993: "propertyShort", "propertyStringbuffer",
0994: "propertyTime" });
0995: assertEquals(
0996: query.getSql(),
0997: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByteObject = 34 AND propertyCalendar = '2002-06-18 15:26:14.0' AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = '2002-06-18 15:26:14.0' AND propertyDoubleObject = 143298.692 AND propertyEnum = 'VALUE_THREE' AND propertyFloat = 98634.2 AND propertyFloatObject = 8734.7 AND propertyInt = 545 AND propertyIntegerObject = 968 AND propertyLong = 34563 AND propertyLongObject = 66875 AND propertyShortObject = 68 AND propertySqlDate = '2002-06-18' AND propertyString = 'someotherstring' AND propertyTimestamp = '2002-06-18 15:26:14.0'");
0998: // mysql doesn't compare correctly on floats, thus don't execute
0999: }
1000:
1001: public void testWhereBeanFilteredMysql() {
1002: Update query = new Update(mMysql);
1003: query.table("tablename").field("propertyBoolean", true).field(
1004: "propertyByte", (byte) 16).whereFiltered(
1005: BeanImpl.getPopulatedBean(),
1006: new String[] { "propertyByte", "propertyDouble",
1007: "propertyShort", "propertyStringbuffer",
1008: "propertyTime" },
1009: new String[] { "propertyByte", "propertyShort",
1010: "propertyTime" });
1011: assertEquals(
1012: query.getSql(),
1013: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyDouble = 53348.34 AND propertyStringbuffer = 'someotherstringbuff'");
1014: assertTrue(execute(query));
1015: }
1016:
1017: public void testWhereParametersBeanMysql() {
1018: Update query = new Update(mMysql);
1019: query.table("tablename").field("propertyBoolean", true).field(
1020: "propertyByte", (byte) 16).whereParameters(
1021: BeanImpl.class);
1022: assertEquals(
1023: query.getSql(),
1024: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLong = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
1025:
1026: assertEquals(query.getParameters().getOrderedNames().size(), 25);
1027: assertEquals(query.getParameters().getOrderedNames().get(0),
1028: "propertyBigDecimal");
1029: assertEquals(query.getParameters().getOrderedNames().get(1),
1030: "propertyBoolean");
1031: assertEquals(query.getParameters().getOrderedNames().get(2),
1032: "propertyBooleanObject");
1033: assertEquals(query.getParameters().getOrderedNames().get(3),
1034: "propertyByte");
1035: assertEquals(query.getParameters().getOrderedNames().get(4),
1036: "propertyByteObject");
1037: assertEquals(query.getParameters().getOrderedNames().get(5),
1038: "propertyCalendar");
1039: assertEquals(query.getParameters().getOrderedNames().get(6),
1040: "propertyChar");
1041: assertEquals(query.getParameters().getOrderedNames().get(7),
1042: "propertyCharacterObject");
1043: assertEquals(query.getParameters().getOrderedNames().get(8),
1044: "propertyDate");
1045: assertEquals(query.getParameters().getOrderedNames().get(9),
1046: "propertyDouble");
1047: assertEquals(query.getParameters().getOrderedNames().get(10),
1048: "propertyDoubleObject");
1049: assertEquals(query.getParameters().getOrderedNames().get(11),
1050: "propertyEnum");
1051: assertEquals(query.getParameters().getOrderedNames().get(12),
1052: "propertyFloat");
1053: assertEquals(query.getParameters().getOrderedNames().get(13),
1054: "propertyFloatObject");
1055: assertEquals(query.getParameters().getOrderedNames().get(14),
1056: "propertyInt");
1057: assertEquals(query.getParameters().getOrderedNames().get(15),
1058: "propertyIntegerObject");
1059: assertEquals(query.getParameters().getOrderedNames().get(16),
1060: "propertyLong");
1061: assertEquals(query.getParameters().getOrderedNames().get(17),
1062: "propertyLongObject");
1063: assertEquals(query.getParameters().getOrderedNames().get(18),
1064: "propertyShort");
1065: assertEquals(query.getParameters().getOrderedNames().get(19),
1066: "propertyShortObject");
1067: assertEquals(query.getParameters().getOrderedNames().get(20),
1068: "propertySqlDate");
1069: assertEquals(query.getParameters().getOrderedNames().get(21),
1070: "propertyString");
1071: assertEquals(query.getParameters().getOrderedNames().get(22),
1072: "propertyStringbuffer");
1073: assertEquals(query.getParameters().getOrderedNames().get(23),
1074: "propertyTime");
1075: assertEquals(query.getParameters().getOrderedNames().get(24),
1076: "propertyTimestamp");
1077: assertTrue(Arrays.equals(query.getParameters()
1078: .getOrderedNamesArray(), new String[] {
1079: "propertyBigDecimal", "propertyBoolean",
1080: "propertyBooleanObject", "propertyByte",
1081: "propertyByteObject", "propertyCalendar",
1082: "propertyChar", "propertyCharacterObject",
1083: "propertyDate", "propertyDouble",
1084: "propertyDoubleObject", "propertyEnum",
1085: "propertyFloat", "propertyFloatObject", "propertyInt",
1086: "propertyIntegerObject", "propertyLong",
1087: "propertyLongObject", "propertyShort",
1088: "propertyShortObject", "propertySqlDate",
1089: "propertyString", "propertyStringbuffer",
1090: "propertyTime", "propertyTimestamp" }));
1091:
1092: // don't check if actual rows were returned, since Mysql doesn't
1093: // match on the float
1094: execute(query, new DbPreparedStatementHandler() {
1095: public void setParameters(DbPreparedStatement statement) {
1096: Calendar cal = Calendar.getInstance();
1097: cal.set(2002, 5, 18, 15, 26, 14);
1098: cal.set(Calendar.MILLISECOND, 764);
1099: statement.setBigDecimal(1,
1100: new BigDecimal("219038743.392874")).setBoolean(
1101: 2, true).setBoolean(3, false).setByte(4,
1102: (byte) 89).setByte(5, (byte) 34)
1103: .setTimestamp(
1104: 6,
1105: new java.sql.Timestamp(cal.getTime()
1106: .getTime())).setString(7, "v")
1107: .setString(8, "r").setTimestamp(
1108: 9,
1109: new java.sql.Timestamp(cal.getTime()
1110: .getTime())).setDouble(10,
1111: 53348.34d).setDouble(11, 143298.692d)
1112: .setString(12, "VALUE_THREE").setDouble(13,
1113: 98634.2d).setDouble(14, 8734.7d)
1114: .setInt(15, 545).setInt(16, 968).setLong(17,
1115: 34563L).setLong(18, 66875L).setShort(
1116: 19, (short) 43)
1117: .setShort(20, (short) 68).setDate(
1118: 21,
1119: new java.sql.Date(cal.getTime()
1120: .getTime())).setString(22,
1121: "someotherstring").setString(23,
1122: "someotherstringbuff").setTime(24,
1123: new Time(15, 26, 14)).setTimestamp(25,
1124: new Timestamp(cal.getTime().getTime()));
1125: }
1126: });
1127: }
1128:
1129: public void testWhereParametersBeanConstrainedMysql() {
1130: Update query = new Update(mMysql);
1131: query.table("tablename").field("propertyBoolean", true).field(
1132: "propertyByte", (byte) 16).whereParameters(
1133: BeanImplConstrained.class);
1134: assertEquals(
1135: query.getSql(),
1136: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = ? AND propertyBoolean = ? AND propertyBooleanObject = ? AND propertyByte = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyChar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyDouble = ? AND propertyDoubleObject = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyInt = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertySqlDate = ? AND propertyString = ? AND propertyStringbuffer = ? AND propertyTime = ? AND propertyTimestamp = ?");
1137:
1138: assertEquals(query.getParameters().getOrderedNames().size(), 22);
1139: assertEquals(query.getParameters().getOrderedNames().get(0),
1140: "propertyBigDecimal");
1141: assertEquals(query.getParameters().getOrderedNames().get(1),
1142: "propertyBoolean");
1143: assertEquals(query.getParameters().getOrderedNames().get(2),
1144: "propertyBooleanObject");
1145: assertEquals(query.getParameters().getOrderedNames().get(3),
1146: "propertyByte");
1147: assertEquals(query.getParameters().getOrderedNames().get(4),
1148: "propertyByteObject");
1149: assertEquals(query.getParameters().getOrderedNames().get(5),
1150: "propertyCalendar");
1151: assertEquals(query.getParameters().getOrderedNames().get(6),
1152: "propertyChar");
1153: assertEquals(query.getParameters().getOrderedNames().get(7),
1154: "propertyCharacterObject");
1155: assertEquals(query.getParameters().getOrderedNames().get(8),
1156: "propertyDate");
1157: assertEquals(query.getParameters().getOrderedNames().get(9),
1158: "propertyDouble");
1159: assertEquals(query.getParameters().getOrderedNames().get(10),
1160: "propertyDoubleObject");
1161: assertEquals(query.getParameters().getOrderedNames().get(11),
1162: "propertyFloat");
1163: assertEquals(query.getParameters().getOrderedNames().get(12),
1164: "propertyFloatObject");
1165: assertEquals(query.getParameters().getOrderedNames().get(13),
1166: "propertyInt");
1167: assertEquals(query.getParameters().getOrderedNames().get(14),
1168: "propertyIntegerObject");
1169: assertEquals(query.getParameters().getOrderedNames().get(15),
1170: "propertyLongObject");
1171: assertEquals(query.getParameters().getOrderedNames().get(16),
1172: "propertyShort");
1173: assertEquals(query.getParameters().getOrderedNames().get(17),
1174: "propertySqlDate");
1175: assertEquals(query.getParameters().getOrderedNames().get(18),
1176: "propertyString");
1177: assertEquals(query.getParameters().getOrderedNames().get(19),
1178: "propertyStringbuffer");
1179: assertEquals(query.getParameters().getOrderedNames().get(20),
1180: "propertyTime");
1181: assertEquals(query.getParameters().getOrderedNames().get(21),
1182: "propertyTimestamp");
1183: assertTrue(Arrays.equals(query.getParameters()
1184: .getOrderedNamesArray(), new String[] {
1185: "propertyBigDecimal", "propertyBoolean",
1186: "propertyBooleanObject", "propertyByte",
1187: "propertyByteObject", "propertyCalendar",
1188: "propertyChar", "propertyCharacterObject",
1189: "propertyDate", "propertyDouble",
1190: "propertyDoubleObject", "propertyFloat",
1191: "propertyFloatObject", "propertyInt",
1192: "propertyIntegerObject", "propertyLongObject",
1193: "propertyShort", "propertySqlDate", "propertyString",
1194: "propertyStringbuffer", "propertyTime",
1195: "propertyTimestamp" }));
1196:
1197: // don't check if actual rows were returned, since Mysql doesn't
1198: // match on the float
1199: execute(query, new DbPreparedStatementHandler() {
1200: public void setParameters(DbPreparedStatement statement) {
1201: Calendar cal = Calendar.getInstance();
1202: cal.set(2002, 5, 18, 15, 26, 14);
1203: cal.set(Calendar.MILLISECOND, 764);
1204: statement.setBigDecimal(1,
1205: new BigDecimal("219038743.392874")).setBoolean(
1206: 2, true).setBoolean(3, false).setByte(4,
1207: (byte) 89).setByte(5, (byte) 34)
1208: .setTimestamp(
1209: 6,
1210: new java.sql.Timestamp(cal.getTime()
1211: .getTime())).setString(7, "v")
1212: .setString(8, "r").setTimestamp(
1213: 9,
1214: new java.sql.Timestamp(cal.getTime()
1215: .getTime())).setDouble(10,
1216: 53348.34d).setDouble(11, 143298.692d)
1217: .setFloat(12, 98634.2f).setFloat(13, 8734.7f)
1218: .setInt(14, 545).setInt(15, 968).setLong(16,
1219: 66875L).setShort(17, (short) 43)
1220: .setDate(
1221: 18,
1222: new java.sql.Date(cal.getTime()
1223: .getTime())).setString(19,
1224: "someotherstring").setString(20,
1225: "someotherstringbuff").setTime(21,
1226: new Time(cal.getTime().getTime()))
1227: .setTimestamp(22,
1228: new Timestamp(cal.getTime().getTime()));
1229: }
1230: });
1231: }
1232:
1233: public void testWhereParametersBeanExcludedMysql() {
1234: Update query = new Update(mMysql);
1235: query.table("tablename").field("propertyBoolean", true).field(
1236: "propertyByte", (byte) 16).whereParametersExcluded(
1237: BeanImpl.class,
1238: new String[] { "propertyBoolean", "propertyByte",
1239: "propertyChar", "propertyDouble",
1240: "propertyDoubleObject", "propertyFloat",
1241: "propertyFloatObject", "propertyInt",
1242: "propertyLong", "propertySqlDate",
1243: "propertyStringbuffer", "propertyTimestamp" });
1244: assertEquals(
1245: query.getSql(),
1246: "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = ? AND propertyBooleanObject = ? AND propertyByteObject = ? AND propertyCalendar = ? AND propertyCharacterObject = ? AND propertyDate = ? AND propertyEnum = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertyString = ? AND propertyTime = ?");
1247:
1248: assertEquals(query.getParameters().getOrderedNames().size(), 13);
1249: assertEquals(query.getParameters().getOrderedNames().get(0),
1250: "propertyBigDecimal");
1251: assertEquals(query.getParameters().getOrderedNames().get(1),
1252: "propertyBooleanObject");
1253: assertEquals(query.getParameters().getOrderedNames().get(2),
1254: "propertyByteObject");
1255: assertEquals(query.getParameters().getOrderedNames().get(3),
1256: "propertyCalendar");
1257: assertEquals(query.getParameters().getOrderedNames().get(4),
1258: "propertyCharacterObject");
1259: assertEquals(query.getParameters().getOrderedNames().get(5),
1260: "propertyDate");
1261: assertEquals(query.getParameters().getOrderedNames().get(6),
1262: "propertyEnum");
1263: assertEquals(query.getParameters().getOrderedNames().get(7),
1264: "propertyIntegerObject");
1265: assertEquals(query.getParameters().getOrderedNames().get(8),
1266: "propertyLongObject");
1267: assertEquals(query.getParameters().getOrderedNames().get(9),
1268: "propertyShort");
1269: assertEquals(query.getParameters().getOrderedNames().get(10),
1270: "propertyShortObject");
1271: assertEquals(query.getParameters().getOrderedNames().get(11),
1272: "propertyString");
1273: assertEquals(query.getParameters().getOrderedNames().get(12),
1274: "propertyTime");
1275: assertTrue(Arrays.equals(query.getParameters()
1276: .getOrderedNamesArray(),
1277: new String[] { "propertyBigDecimal",
1278: "propertyBooleanObject", "propertyByteObject",
1279: "propertyCalendar", "propertyCharacterObject",
1280: "propertyDate", "propertyEnum",
1281: "propertyIntegerObject", "propertyLongObject",
1282: "propertyShort", "propertyShortObject",
1283: "propertyString", "propertyTime" }));
1284:
1285: assertTrue(execute(query, new DbPreparedStatementHandler() {
1286: public void setParameters(DbPreparedStatement statement) {
1287: Calendar cal = Calendar.getInstance();
1288: cal.set(2002, 5, 18, 15, 26, 14);
1289: cal.set(Calendar.MILLISECOND, 764);
1290: statement.setBigDecimal(1,
1291: new BigDecimal("219038743.392874")).setBoolean(
1292: 2, false).setByte(3, (byte) 34)
1293: .setTimestamp(
1294: 4,
1295: new java.sql.Timestamp(cal.getTime()
1296: .getTime())).setString(5, "r")
1297: .setTimestamp(
1298: 6,
1299: new java.sql.Timestamp(cal.getTime()
1300: .getTime())).setString(7,
1301: "VALUE_THREE")
1302:
1303: .setInt(8, 968).setLong(9, 66875L).setShort(10,
1304: (short) 43).setShort(11, (short) 68)
1305: .setString(12, "someotherstring").setTime(13,
1306: new Time(cal.getTime().getTime()));
1307: }
1308: }));
1309: }
1310:
1311: public void testSubselectParamsMysql() {
1312: // mysql doesn't support subqueries
1313: }
1314:
1315: public void testCloneMysql() {
1316: final Calendar cal = Calendar.getInstance();
1317: cal.set(2002, 7, 19, 12, 17, 52);
1318: cal.set(Calendar.MILLISECOND, 462);
1319: Update query = new Update(mMysql);
1320: query.hint("LOW_PRIORITY").table("tablename").fieldParameter(
1321: "nullColumn").field("propertyBigDecimal",
1322: new BigDecimal("98347.876438637")).fieldParameter(
1323: "propertyBoolean").fieldParameter("propertyByte")
1324: .field("propertyCalendar", cal.getTime())
1325: .fieldParameter("propertyChar").field("propertyDate",
1326: cal).field("propertyDouble", 12.3d)
1327: .fieldParameter("propertyFloat").fieldParameter(
1328: "propertyInt").field("propertyShort",
1329: (short) 12).fieldParameter("propertySqlDate")
1330: .fieldParameter("propertyString").field(
1331: "propertyStringbuffer",
1332: new StringBuffer("stringbuffer'value")).field(
1333: "propertyTime",
1334: new Time(cal.getTime().getTime()))
1335: .fieldParameter("propertyTimestamp").whereParameter(
1336: "tablename.propertyString", "propertyString",
1337: "=").whereOr("tablename.propertyByte", "=",
1338: (byte) 54).whereAnd("tablename.propertyDouble",
1339: "!=", 73453.71d).whereParameterOr(
1340: "tablename.propertyInt", "propertyInt", "=")
1341: .whereParameterAnd("tablename.propertyLong",
1342: "propertyLong", "<").whereParameterOr(
1343: "tablename.propertyChar", "propertyChar", "=");
1344:
1345: Update query_clone = query.clone();
1346: assertEquals(query.getSql(), query_clone.getSql());
1347: assertTrue(query != query_clone);
1348:
1349: execute(query, new DbPreparedStatementHandler() {
1350: public void setParameters(DbPreparedStatement statement) {
1351: statement.setString("nullColumn", null).setBoolean(
1352: "propertyBoolean", true).setByte(
1353: "propertyByte", (byte) 16).setString(
1354: "propertyChar", "M").setFloat("propertyFloat",
1355: 13.4f).setInt("propertyInt", 34).setDate(
1356: "propertySqlDate",
1357: new java.sql.Date(cal.getTime().getTime()))
1358: .setString("propertyString", "string'value")
1359: .setTimestamp("propertyTimestamp",
1360: new Timestamp(cal.getTime().getTime()))
1361: .setLong("propertyLong", 34543);
1362: }
1363: });
1364: }
1365: }
|