Source Code Cross Referenced for TestUpdateOracle.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » database » queries » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » rife 1.6.1 » com.uwyn.rife.database.queries 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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: TestUpdateOracle.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 TestUpdateOracle extends TestUpdate {
0024:            public TestUpdateOracle(String name) {
0025:                super (name);
0026:            }
0027:
0028:            public void testInstantiationOracle() {
0029:                Update query = new Update(mOracle);
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 testIncompleteQueryOracle() {
0040:                Update query = new Update(mOracle);
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 testClearOracle() {
0059:                Update query = new Update(mOracle);
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 testHintOracle() {
0072:                Update query = new Update(mOracle).hint("NO_INDEX").table(
0073:                        "tablename").field("propertyInt", 34);
0074:                assertEquals(query.getSql(),
0075:                        "UPDATE /*+ NO_INDEX */ tablename SET propertyInt = 34");
0076:                assertTrue(execute(query));
0077:            }
0078:
0079:            public void testFieldOracle() {
0080:                Calendar cal = Calendar.getInstance();
0081:                cal.set(2002, 7, 19, 12, 17, 52);
0082:                Update query = new Update(mOracle);
0083:                query.table("tablename").where("propertyByte = 89").field(
0084:                        "nullColumn", SqlNull.NULL).field("propertyBigDecimal",
0085:                        new BigDecimal("98347.876438637")).field(
0086:                        "propertyBoolean", true).field("propertyByte",
0087:                        (byte) 16).field("propertyCalendar", cal.getTime())
0088:                        .field("propertyChar", 'M').field("propertyDate", cal)
0089:                        .field("propertyDouble", 12.3d).field("propertyFloat",
0090:                                13.4f).field("propertyInt", 34).field(
0091:                                "propertyLong", 45L).field("propertyShort",
0092:                                (short) 12).field("propertySqlDate",
0093:                                new java.sql.Date(cal.getTime().getTime()))
0094:                        .field("propertyString", "string'value").field(
0095:                                "propertyStringbuffer",
0096:                                new StringBuffer("stringbuffer'value")).field(
0097:                                "propertyTime",
0098:                                new Time(cal.getTime().getTime())).field(
0099:                                "propertyTimestamp",
0100:                                new Timestamp(cal.getTime().getTime()));
0101:                assertEquals(
0102:                        query.getSql(),
0103:                        "UPDATE tablename SET nullColumn = NULL, propertyBigDecimal = 98347.876438637, propertyBoolean = 1, propertyByte = 16, propertyCalendar = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = 'M', propertyDate = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyDouble = 12.3, propertyFloat = 13.4, propertyInt = 34, propertyLong = 45, propertyShort = 12, propertySqlDate = TO_DATE('2002/08/19 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), propertyString = 'string''value', propertyStringbuffer = 'stringbuffer''value', propertyTime = TO_DATE('12:17:52', 'HH24:MI:SS'), propertyTimestamp = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS') WHERE propertyByte = 89");
0104:                assertTrue(execute(query));
0105:            }
0106:
0107:            public void testFieldCustomOracle() {
0108:                Update query = new Update(mOracle);
0109:                query.table("tablename").fieldCustom("propertySqlDate",
0110:                        "(SELECT sysdate FROM dual)");
0111:                assertEquals(query.getSql(),
0112:                        "UPDATE tablename SET propertySqlDate = (SELECT sysdate FROM dual)");
0113:                assertTrue(execute(query));
0114:            }
0115:
0116:            public void testFieldParametersOracle() {
0117:                Update query = new Update(mOracle);
0118:                query.table("tablename");
0119:
0120:                assertNull(query.getParameters());
0121:
0122:                query.fieldParameter("nullColumn").fieldParameter(
0123:                        "propertyBigDecimal").fieldParameter("propertyBoolean")
0124:                        .fieldParameter("propertyByte").fieldParameter(
0125:                                "propertyCalendar").fieldParameter(
0126:                                "propertyChar").fieldParameter("propertyDate")
0127:                        .fieldParameter("propertyDouble").fieldParameter(
0128:                                "propertyFloat").fieldParameter("propertyInt")
0129:                        .fieldParameter("propertyLong").fieldParameter(
0130:                                "propertyShort").fieldParameter(
0131:                                "propertySqlDate").fieldParameter(
0132:                                "propertyString").fieldParameter(
0133:                                "propertyStringbuffer").fieldParameter(
0134:                                "propertyTime").fieldParameter(
0135:                                "propertyTimestamp");
0136:
0137:                assertEquals(query.getParameters().getOrderedNames().size(), 17);
0138:                assertEquals(query.getParameters().getOrderedNames().get(0),
0139:                        "nullColumn");
0140:                assertEquals(query.getParameters().getOrderedNames().get(1),
0141:                        "propertyBigDecimal");
0142:                assertEquals(query.getParameters().getOrderedNames().get(2),
0143:                        "propertyBoolean");
0144:                assertEquals(query.getParameters().getOrderedNames().get(3),
0145:                        "propertyByte");
0146:                assertEquals(query.getParameters().getOrderedNames().get(4),
0147:                        "propertyCalendar");
0148:                assertEquals(query.getParameters().getOrderedNames().get(5),
0149:                        "propertyChar");
0150:                assertEquals(query.getParameters().getOrderedNames().get(6),
0151:                        "propertyDate");
0152:                assertEquals(query.getParameters().getOrderedNames().get(7),
0153:                        "propertyDouble");
0154:                assertEquals(query.getParameters().getOrderedNames().get(8),
0155:                        "propertyFloat");
0156:                assertEquals(query.getParameters().getOrderedNames().get(9),
0157:                        "propertyInt");
0158:                assertEquals(query.getParameters().getOrderedNames().get(10),
0159:                        "propertyLong");
0160:                assertEquals(query.getParameters().getOrderedNames().get(11),
0161:                        "propertyShort");
0162:                assertEquals(query.getParameters().getOrderedNames().get(12),
0163:                        "propertySqlDate");
0164:                assertEquals(query.getParameters().getOrderedNames().get(13),
0165:                        "propertyString");
0166:                assertEquals(query.getParameters().getOrderedNames().get(14),
0167:                        "propertyStringbuffer");
0168:                assertEquals(query.getParameters().getOrderedNames().get(15),
0169:                        "propertyTime");
0170:                assertEquals(query.getParameters().getOrderedNames().get(16),
0171:                        "propertyTimestamp");
0172:                assertTrue(Arrays.equals(query.getParameters()
0173:                        .getOrderedNamesArray(), new String[] { "nullColumn",
0174:                        "propertyBigDecimal", "propertyBoolean",
0175:                        "propertyByte", "propertyCalendar", "propertyChar",
0176:                        "propertyDate", "propertyDouble", "propertyFloat",
0177:                        "propertyInt", "propertyLong", "propertyShort",
0178:                        "propertySqlDate", "propertyString",
0179:                        "propertyStringbuffer", "propertyTime",
0180:                        "propertyTimestamp" }));
0181:
0182:                assertEquals(
0183:                        query.getSql(),
0184:                        "UPDATE tablename SET nullColumn = ?, propertyBigDecimal = ?, propertyBoolean = ?, propertyByte = ?, propertyCalendar = ?, propertyChar = ?, propertyDate = ?, propertyDouble = ?, propertyFloat = ?, propertyInt = ?, propertyLong = ?, propertyShort = ?, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = ?, propertyTime = ?, propertyTimestamp = ?");
0185:
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 testFieldParametersMixedOracle() {
0215:                Update query = new Update(mOracle);
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 = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = ?, propertyDate = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyDouble = 12.3, propertyFloat = ?, propertyInt = ?, propertyLong = 45, propertyShort = 12, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = 'stringbuffer''value', propertyTime = TO_DATE('12:17:52', 'HH24:MI:SS'), propertyTimestamp = ?");
0267:
0268:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0269:                    public void setParameters(DbPreparedStatement statement) {
0270:                        statement.setString(1, null).setBoolean(2, true)
0271:                                .setByte(3, (byte) 16).setString(4, "M")
0272:                                .setFloat(5, 13.4f).setInt(6, 34).setDate(
0273:                                        7,
0274:                                        new java.sql.Date(cal.getTime()
0275:                                                .getTime())).setString(8,
0276:                                        "string'value").setTimestamp(9,
0277:                                        new Timestamp(cal.getTime().getTime()));
0278:                    }
0279:                }));
0280:            }
0281:
0282:            public void testFieldsOracle() {
0283:                Calendar cal = Calendar.getInstance();
0284:                cal.set(2002, 7, 19, 12, 17, 52);
0285:                Update query = new Update(mOracle);
0286:                query.table("tablename").where("propertyByte = 89").fields(
0287:                        new Object[] { "nullColumn", SqlNull.NULL,
0288:                                "propertyBigDecimal",
0289:                                new BigDecimal("98347.876438637"),
0290:                                "propertyBoolean", new Boolean(true),
0291:                                "propertyByte", new Byte((byte) 16),
0292:                                "propertyCalendar", cal.getTime(),
0293:                                "propertyChar", new Character('M'),
0294:                                "propertyDate", cal, "propertyDouble",
0295:                                new Double(12.3d), "propertyFloat",
0296:                                new Float(13.4f), "propertyInt",
0297:                                new Integer(34), "propertyLong", new Long(45L),
0298:                                "propertyShort", new Short((short) 12),
0299:                                "propertySqlDate",
0300:                                new java.sql.Date(cal.getTime().getTime()),
0301:                                "propertyString", new String("string'value"),
0302:                                "propertyStringbuffer",
0303:                                new StringBuffer("stringbuffer'value"),
0304:                                "propertyTime",
0305:                                new Time(cal.getTime().getTime()),
0306:                                "propertyTimestamp",
0307:                                new Timestamp(cal.getTime().getTime()) });
0308:                assertEquals(
0309:                        query.getSql(),
0310:                        "UPDATE tablename SET nullColumn = NULL, propertyBigDecimal = 98347.876438637, propertyBoolean = 1, propertyByte = 16, propertyCalendar = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = 'M', propertyDate = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS'), propertyDouble = 12.3, propertyFloat = 13.4, propertyInt = 34, propertyLong = 45, propertyShort = 12, propertySqlDate = TO_DATE('2002/08/19 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), propertyString = 'string''value', propertyStringbuffer = 'stringbuffer''value', propertyTime = TO_DATE('12:17:52', 'HH24:MI:SS'), propertyTimestamp = TO_DATE('2002/08/19 12:17:52', 'YYYY/MM/DD HH24:MI:SS') WHERE propertyByte = 89");
0311:                assertTrue(execute(query));
0312:            }
0313:
0314:            public void testWhereConstructionOracle() {
0315:                Update query = new Update(mOracle);
0316:                query.table("tablename").field("propertyBoolean", true).field(
0317:                        "propertyByte", (byte) 16).where("propertyInt = 545")
0318:                        .whereAnd("propertyLong < 50000").whereOr(
0319:                                "propertyChar = 'v'");
0320:                assertEquals(
0321:                        query.getSql(),
0322:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545 AND propertyLong < 50000 OR propertyChar = 'v'");
0323:                assertTrue(execute(query));
0324:            }
0325:
0326:            public void testWhereConstructionGroupOracle() {
0327:                Update query = new Update(mOracle);
0328:                query.table("tablename").field("propertyBoolean", true).field(
0329:                        "propertyByte", (byte) 16).where("propertyInt = 545")
0330:                        .whereAnd("propertyLong < 50000").startWhereOr()
0331:                        .whereParameter("propertyString", "=").whereAnd(
0332:                                "propertyByte", "<=", (byte) 0).startWhereAnd()
0333:                        .where("propertyBoolean", "!=", true).whereParameterOr(
0334:                                "propertyStringbuffer", "LIKE").end().end()
0335:                        .whereOr("propertyChar = 'v'");
0336:
0337:                assertEquals(query.getParameters().getOrderedNames().get(0),
0338:                        "propertyString");
0339:                assertEquals(query.getParameters().getOrderedNames().get(1),
0340:                        "propertyStringbuffer");
0341:                assertTrue(Arrays.equals(query.getParameters()
0342:                        .getOrderedNamesArray(), new String[] {
0343:                        "propertyString", "propertyStringbuffer" }));
0344:
0345:                assertEquals(
0346:                        query.getSql(),
0347:                        "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'");
0348:
0349:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0350:                    public void setParameters(DbPreparedStatement statement) {
0351:                        statement
0352:                                .setString("propertyString", "someotherstring")
0353:                                .setString("propertyStringbuffer", "stringbuff");
0354:                    }
0355:                }));
0356:            }
0357:
0358:            public void testWhereTypedOracle() {
0359:                Update query = new Update(mOracle);
0360:                query.table("tablename").field("propertyBoolean", true).field(
0361:                        "propertyByte", (byte) 16);
0362:
0363:                Calendar cal = Calendar.getInstance();
0364:                cal.set(2003, 2, 3, 10, 1, 28);
0365:                cal.set(Calendar.MILLISECOND, 154);
0366:
0367:                query.where("propertyBigDecimal", ">=",
0368:                        new BigDecimal("53443433.9784567")).whereAnd(
0369:                        "propertyBoolean", "=", false).whereOr("propertyByte",
0370:                        "=", (byte) 54).whereAnd("propertyCalendar", "<=", cal)
0371:                        .whereOr("propertyChar", "=", 'f').whereAnd(
0372:                                "propertyDate", "=", cal.getTime()).whereAnd(
0373:                                "propertyDouble", "!=", 73453.71d).whereOr(
0374:                                "propertyFloat", ">=", 1987.14f).whereAnd(
0375:                                "propertyInt", "=", 973).whereAnd(
0376:                                "propertyLong", "<", 347678L).whereAnd(
0377:                                "propertyShort", "=", (short) 78).whereOr(
0378:                                "propertySqlDate", "=",
0379:                                new java.sql.Date(cal.getTime().getTime()))
0380:                        .whereAnd("propertyString", "LIKE", "someotherstring%")
0381:                        .whereAnd("propertyStringbuffer", "=",
0382:                                new StringBuffer("someotherstringbuff"))
0383:                        .whereOr("propertyTime", "=",
0384:                                new Time(cal.getTime().getTime())).whereAnd(
0385:                                "propertyTimestamp", "<=",
0386:                                new Timestamp(cal.getTime().getTime()));
0387:
0388:                assertEquals(
0389:                        query.getSql(),
0390:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') AND propertyDouble != 73453.71 OR propertyFloat >= 1987.14 AND propertyInt = 973 AND propertyLong < 347678 AND propertyShort = 78 OR propertySqlDate = TO_DATE('2003/03/03 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString LIKE 'someotherstring%' AND propertyStringbuffer = 'someotherstringbuff' OR propertyTime = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
0391:                assertFalse(execute(query));
0392:            }
0393:
0394:            public void testWhereTypedMixedOracle() {
0395:                Update query = new Update(mOracle);
0396:                query.table("tablename").field("propertyBoolean", true).field(
0397:                        "propertyByte", (byte) 16);
0398:
0399:                final Calendar cal = Calendar.getInstance();
0400:                cal.set(2003, 2, 3, 10, 1, 28);
0401:                cal.set(Calendar.MILLISECOND, 154);
0402:
0403:                query.where("propertyBigDecimal", ">=",
0404:                        new BigDecimal("53443433.9784567")).whereAnd(
0405:                        "propertyBoolean", "=", false).whereOr(
0406:                        "propertyByte = 54").whereAnd("propertyCalendar", "<=",
0407:                        cal).whereOr("propertyChar", "=", 'f').whereAnd(
0408:                        "propertyDate", "=", cal.getTime()).whereAnd(
0409:                        "propertyDouble", "!=", 73453.71d).whereOr(
0410:                        "propertyFloat >= 1987.14").whereAnd("propertyInt",
0411:                        "=", 973).whereAnd("propertyLong", "<", 347678L)
0412:                        .whereAnd("propertyShort", "=", (short) 78)
0413:                        .whereParameterOr("propertySqlDate", "=").whereAnd(
0414:                                "propertyString", "LIKE", "someotherstring%")
0415:                        .whereAnd("propertyStringbuffer", "=",
0416:                                new StringBuffer("someotherstringbuff"))
0417:                        .whereOr("propertyTime", "=",
0418:                                new Time(cal.getTime().getTime())).whereAnd(
0419:                                "propertyTimestamp", "<=",
0420:                                new Timestamp(cal.getTime().getTime()));
0421:
0422:                assertEquals(
0423:                        query.getSql(),
0424:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal >= 53443433.9784567 AND propertyBoolean = 0 OR propertyByte = 54 AND propertyCalendar <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') OR propertyChar = 'f' AND propertyDate = TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS') 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 = TO_DATE('10:01:28', 'HH24:MI:SS') AND propertyTimestamp <= TO_DATE('2003/03/03 10:01:28', 'YYYY/MM/DD HH24:MI:SS')");
0425:
0426:                assertFalse(execute(query, new DbPreparedStatementHandler() {
0427:                    public void setParameters(DbPreparedStatement statement) {
0428:                        statement.setDate("propertySqlDate", new java.sql.Date(
0429:                                cal.getTime().getTime()));
0430:                    }
0431:                }));
0432:            }
0433:
0434:            public void testWhereParametersOracle() {
0435:                Update query = new Update(mOracle);
0436:                query.table("tablename").field("propertyBoolean", true).field(
0437:                        "propertyByte", (byte) 16);
0438:
0439:                assertNull(query.getParameters());
0440:
0441:                query.whereParameter("propertyInt", "=").whereParameterAnd(
0442:                        "propertyLong", "<").whereParameterOr("propertyChar",
0443:                        "=");
0444:
0445:                assertEquals(query.getParameters().getOrderedNames().size(), 3);
0446:                assertEquals(query.getParameters().getOrderedNames().get(0),
0447:                        "propertyInt");
0448:                assertEquals(query.getParameters().getOrderedNames().get(1),
0449:                        "propertyLong");
0450:                assertEquals(query.getParameters().getOrderedNames().get(2),
0451:                        "propertyChar");
0452:                assertTrue(Arrays.equals(query.getParameters()
0453:                        .getOrderedNamesArray(), new String[] { "propertyInt",
0454:                        "propertyLong", "propertyChar" }));
0455:
0456:                assertEquals(
0457:                        query.getSql(),
0458:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
0459:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0460:                    public void setParameters(DbPreparedStatement statement) {
0461:                        statement.setInt(1, 545).setLong(2, 50000).setString(3,
0462:                                "v");
0463:                    }
0464:                }));
0465:
0466:                query.where("propertyInt = 545");
0467:
0468:                assertNull(query.getParameters());
0469:                assertEquals(
0470:                        query.getSql(),
0471:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545");
0472:            }
0473:
0474:            public void testWhereParametersMixedOracle() {
0475:                Update query = new Update(mOracle);
0476:                query.table("tablename").field("propertyBoolean", true).field(
0477:                        "propertyByte", (byte) 16).where("propertyInt = 545")
0478:                        .whereParameterAnd("propertyLong", "<")
0479:                        .whereParameterOr("propertyChar", "=");
0480:
0481:                assertEquals(query.getParameters().getOrderedNames().get(0),
0482:                        "propertyLong");
0483:                assertEquals(query.getParameters().getOrderedNames().get(1),
0484:                        "propertyChar");
0485:                assertTrue(Arrays.equals(query.getParameters()
0486:                        .getOrderedNamesArray(), new String[] { "propertyLong",
0487:                        "propertyChar" }));
0488:
0489:                assertEquals(
0490:                        query.getSql(),
0491:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545 AND propertyLong < ? OR propertyChar = ?");
0492:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0493:                    public void setParameters(DbPreparedStatement statement) {
0494:                        statement.setLong(1, 50000).setString(2, "v");
0495:                    }
0496:                }));
0497:
0498:                query.where("propertyInt = 545");
0499:
0500:                assertNull(query.getParameters());
0501:                assertEquals(
0502:                        query.getSql(),
0503:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyInt = 545");
0504:            }
0505:
0506:            public void testFieldWhereParametersOracle() {
0507:                Update query = new Update(mOracle);
0508:                query.table("tablename");
0509:
0510:                assertNull(query.getParameters());
0511:
0512:                query.fieldParameter("propertyBoolean").fieldParameter(
0513:                        "propertyByte");
0514:
0515:                assertEquals(query.getParameters().getOrderedNames().size(), 2);
0516:                assertEquals(query.getParameters().getOrderedNames().get(0),
0517:                        "propertyBoolean");
0518:                assertEquals(query.getParameters().getOrderedNames().get(1),
0519:                        "propertyByte");
0520:                assertTrue(Arrays.equals(query.getParameters()
0521:                        .getOrderedNamesArray(), new String[] {
0522:                        "propertyBoolean", "propertyByte" }));
0523:
0524:                query.whereParameter("propertyInt", "=").whereParameterAnd(
0525:                        "propertyLong", "<").whereParameterOr("propertyChar",
0526:                        "=");
0527:
0528:                assertEquals(query.getParameters().getOrderedNames().size(), 5);
0529:                assertEquals(query.getParameters().getOrderedNames().get(0),
0530:                        "propertyBoolean");
0531:                assertEquals(query.getParameters().getOrderedNames().get(1),
0532:                        "propertyByte");
0533:                assertEquals(query.getParameters().getOrderedNames().get(2),
0534:                        "propertyInt");
0535:                assertEquals(query.getParameters().getOrderedNames().get(3),
0536:                        "propertyLong");
0537:                assertEquals(query.getParameters().getOrderedNames().get(4),
0538:                        "propertyChar");
0539:                assertTrue(Arrays.equals(query.getParameters()
0540:                        .getOrderedNamesArray(), new String[] {
0541:                        "propertyBoolean", "propertyByte", "propertyInt",
0542:                        "propertyLong", "propertyChar" }));
0543:
0544:                assertEquals(
0545:                        query.getSql(),
0546:                        "UPDATE tablename SET propertyBoolean = ?, propertyByte = ? WHERE propertyInt = ? AND propertyLong < ? OR propertyChar = ?");
0547:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0548:                    public void setParameters(DbPreparedStatement statement) {
0549:                        statement.setBoolean(1, true).setByte(2, (byte) 16)
0550:                                .setInt(3, 545).setLong(4, 50000).setString(5,
0551:                                        "v");
0552:                    }
0553:                }));
0554:
0555:                query.where("propertyInt = 545");
0556:
0557:                assertEquals(query.getParameters().getOrderedNames().size(), 2);
0558:                assertEquals(
0559:                        query.getParameters().getOrderedNamesArray().length, 2);
0560:                assertEquals(query.getParameters().getOrderedNames().get(0),
0561:                        "propertyBoolean");
0562:                assertEquals(query.getParameters().getOrderedNames().get(1),
0563:                        "propertyByte");
0564:                assertTrue(Arrays.equals(query.getParameters()
0565:                        .getOrderedNamesArray(), new String[] {
0566:                        "propertyBoolean", "propertyByte" }));
0567:                assertEquals(
0568:                        query.getSql(),
0569:                        "UPDATE tablename SET propertyBoolean = ?, propertyByte = ? WHERE propertyInt = 545");
0570:            }
0571:
0572:            public void testFieldsBeanOracle() {
0573:                Update query = new Update(mOracle);
0574:                query.table("tablename").where("propertyInt = 545").fields(
0575:                        BeanImpl.getPopulatedBean());
0576:                assertEquals(
0577:                        query.getSql(),
0578:                        "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByte = 89, propertyByteObject = 34, propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), 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 = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), propertyString = 'someotherstring', propertyStringbuffer = 'someotherstringbuff', propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS'), propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') WHERE propertyInt = 545");
0579:                assertTrue(execute(query));
0580:            }
0581:
0582:            public void testFieldsBeanConstrainedOracle() {
0583:                Update query = new Update(mOracle);
0584:                query.table("tablename").where("propertyInt = 545").fields(
0585:                        BeanImplConstrained.getPopulatedBean());
0586:                assertEquals(
0587:                        query.getSql(),
0588:                        "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByteObject = 34, propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), propertyDouble = 53348.34, propertyDoubleObject = 143298.692, propertyFloat = 98634.2, propertyFloatObject = 8734.7, propertyInt = 545, propertyIntegerObject = 968, propertyLongObject = 66875, propertyShort = 43, propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), propertyString = 'someotherstring', propertyStringbuffer = 'someotherstringbuff', propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS'), propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') WHERE propertyInt = 545");
0589:                assertTrue(execute(query));
0590:            }
0591:
0592:            public void testFieldsBeanNullValuesOracle() {
0593:                Update query = new Update(mOracle);
0594:                query.table("tablename").where("propertyInt = 545").fields(
0595:                        BeanImpl.getNullBean());
0596:                assertEquals(
0597:                        query.getSql(),
0598:                        "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");
0599:                assertTrue(execute(query));
0600:            }
0601:
0602:            public void testFieldsBeanIncludedOracle() {
0603:                Update query = new Update(mOracle);
0604:                query
0605:                        .table("tablename")
0606:                        .where("propertyInt = 545")
0607:                        .fieldsIncluded(
0608:                                BeanImpl.getPopulatedBean(),
0609:                                new String[] { "propertyByte",
0610:                                        "propertyDouble", "propertyShort",
0611:                                        "propertyStringbuffer", "propertyTime" });
0612:                assertEquals(
0613:                        query.getSql(),
0614:                        "UPDATE tablename SET propertyByte = 89, propertyDouble = 53348.34, propertyShort = 43, propertyStringbuffer = 'someotherstringbuff', propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') WHERE propertyInt = 545");
0615:                assertTrue(execute(query));
0616:            }
0617:
0618:            public void testFieldsBeanExcludedOracle() {
0619:                Update query = new Update(mOracle);
0620:                query
0621:                        .table("tablename")
0622:                        .where("propertyInt = 545")
0623:                        .fieldsExcluded(
0624:                                BeanImpl.getPopulatedBean(),
0625:                                new String[] { "propertyByte",
0626:                                        "propertyDouble", "propertyShort",
0627:                                        "propertyStringbuffer", "propertyTime" });
0628:                assertEquals(
0629:                        query.getSql(),
0630:                        "UPDATE tablename SET propertyBigDecimal = 219038743.392874, propertyBoolean = 1, propertyBooleanObject = 0, propertyByteObject = 34, propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), propertyChar = 'v', propertyCharacterObject = 'r', propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS'), propertyDoubleObject = 143298.692, propertyEnum = 'VALUE_THREE', propertyFloat = 98634.2, propertyFloatObject = 8734.7, propertyInt = 545, propertyIntegerObject = 968, propertyLong = 34563, propertyLongObject = 66875, propertyShortObject = 68, propertySqlDate = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS'), propertyString = 'someotherstring', propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') WHERE propertyInt = 545");
0631:                assertTrue(execute(query));
0632:            }
0633:
0634:            public void testFieldsBeanFilteredOracle() {
0635:                Update query = new Update(mOracle);
0636:                query
0637:                        .table("tablename")
0638:                        .where("propertyInt = 545")
0639:                        .fieldsFiltered(
0640:                                BeanImpl.getPopulatedBean(),
0641:                                new String[] { "propertyByte",
0642:                                        "propertyDouble", "propertyShort",
0643:                                        "propertyStringbuffer", "propertyTime" },
0644:                                new String[] { "propertyByte", "propertyShort",
0645:                                        "propertyTime" });
0646:                assertEquals(
0647:                        query.getSql(),
0648:                        "UPDATE tablename SET propertyDouble = 53348.34, propertyStringbuffer = 'someotherstringbuff' WHERE propertyInt = 545");
0649:                assertTrue(execute(query));
0650:            }
0651:
0652:            public void testFieldsParametersBeanOracle() {
0653:                Update query = new Update(mOracle);
0654:                query.table("tablename").fieldsParameters(BeanImpl.class);
0655:                assertEquals(
0656:                        query.getSql(),
0657:                        "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 = ?");
0658:
0659:                assertEquals(query.getParameters().getOrderedNames().size(), 25);
0660:                assertEquals(query.getParameters().getOrderedNames().get(0),
0661:                        "propertyBigDecimal");
0662:                assertEquals(query.getParameters().getOrderedNames().get(1),
0663:                        "propertyBoolean");
0664:                assertEquals(query.getParameters().getOrderedNames().get(2),
0665:                        "propertyBooleanObject");
0666:                assertEquals(query.getParameters().getOrderedNames().get(3),
0667:                        "propertyByte");
0668:                assertEquals(query.getParameters().getOrderedNames().get(4),
0669:                        "propertyByteObject");
0670:                assertEquals(query.getParameters().getOrderedNames().get(5),
0671:                        "propertyCalendar");
0672:                assertEquals(query.getParameters().getOrderedNames().get(6),
0673:                        "propertyChar");
0674:                assertEquals(query.getParameters().getOrderedNames().get(7),
0675:                        "propertyCharacterObject");
0676:                assertEquals(query.getParameters().getOrderedNames().get(8),
0677:                        "propertyDate");
0678:                assertEquals(query.getParameters().getOrderedNames().get(9),
0679:                        "propertyDouble");
0680:                assertEquals(query.getParameters().getOrderedNames().get(10),
0681:                        "propertyDoubleObject");
0682:                assertEquals(query.getParameters().getOrderedNames().get(11),
0683:                        "propertyEnum");
0684:                assertEquals(query.getParameters().getOrderedNames().get(12),
0685:                        "propertyFloat");
0686:                assertEquals(query.getParameters().getOrderedNames().get(13),
0687:                        "propertyFloatObject");
0688:                assertEquals(query.getParameters().getOrderedNames().get(14),
0689:                        "propertyInt");
0690:                assertEquals(query.getParameters().getOrderedNames().get(15),
0691:                        "propertyIntegerObject");
0692:                assertEquals(query.getParameters().getOrderedNames().get(16),
0693:                        "propertyLong");
0694:                assertEquals(query.getParameters().getOrderedNames().get(17),
0695:                        "propertyLongObject");
0696:                assertEquals(query.getParameters().getOrderedNames().get(18),
0697:                        "propertyShort");
0698:                assertEquals(query.getParameters().getOrderedNames().get(19),
0699:                        "propertyShortObject");
0700:                assertEquals(query.getParameters().getOrderedNames().get(20),
0701:                        "propertySqlDate");
0702:                assertEquals(query.getParameters().getOrderedNames().get(21),
0703:                        "propertyString");
0704:                assertEquals(query.getParameters().getOrderedNames().get(22),
0705:                        "propertyStringbuffer");
0706:                assertEquals(query.getParameters().getOrderedNames().get(23),
0707:                        "propertyTime");
0708:                assertEquals(query.getParameters().getOrderedNames().get(24),
0709:                        "propertyTimestamp");
0710:                assertTrue(Arrays.equals(query.getParameters()
0711:                        .getOrderedNamesArray(), new String[] {
0712:                        "propertyBigDecimal", "propertyBoolean",
0713:                        "propertyBooleanObject", "propertyByte",
0714:                        "propertyByteObject", "propertyCalendar",
0715:                        "propertyChar", "propertyCharacterObject",
0716:                        "propertyDate", "propertyDouble",
0717:                        "propertyDoubleObject", "propertyEnum",
0718:                        "propertyFloat", "propertyFloatObject", "propertyInt",
0719:                        "propertyIntegerObject", "propertyLong",
0720:                        "propertyLongObject", "propertyShort",
0721:                        "propertyShortObject", "propertySqlDate",
0722:                        "propertyString", "propertyStringbuffer",
0723:                        "propertyTime", "propertyTimestamp" }));
0724:
0725:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0726:                    public void setParameters(DbPreparedStatement statement) {
0727:                        Calendar cal = Calendar.getInstance();
0728:                        cal.set(2002, 7, 19, 12, 17, 52);
0729:                        cal.set(Calendar.MILLISECOND, 462);
0730:                        statement.setBigDecimal(1,
0731:                                new BigDecimal("98347.876438637")).setBoolean(
0732:                                2, false).setBoolean(3, true).setByte(4,
0733:                                (byte) 16).setByte(5, (byte) 72)
0734:                                .setTimestamp(
0735:                                        6,
0736:                                        new java.sql.Timestamp(cal.getTime()
0737:                                                .getTime())).setString(7, "M")
0738:                                .setString(8, "p").setTimestamp(
0739:                                        9,
0740:                                        new java.sql.Timestamp(cal.getTime()
0741:                                                .getTime())).setDouble(10,
0742:                                        12.3d).setDouble(11, 68.7d).setString(
0743:                                        12, "VALUE_THREE").setFloat(13, 13.4f)
0744:                                .setFloat(14, 42.1f).setInt(15, 92).setInt(16,
0745:                                        34).setLong(17, 687L).setLong(18, 92)
0746:                                .setShort(19, (short) 7).setShort(20,
0747:                                        (short) 12).setDate(
0748:                                        21,
0749:                                        new java.sql.Date(cal.getTime()
0750:                                                .getTime())).setString(22,
0751:                                        "string'value").setString(23,
0752:                                        "string'value2").setTime(24,
0753:                                        new Time(cal.getTime().getTime()))
0754:                                .setTimestamp(25,
0755:                                        new Timestamp(cal.getTime().getTime()));
0756:                    }
0757:                }));
0758:            }
0759:
0760:            public void testFieldsParametersBeanConstrainedOracle() {
0761:                Update query = new Update(mOracle);
0762:                query.table("tablename").fieldsParameters(
0763:                        BeanImplConstrained.class);
0764:                assertEquals(
0765:                        query.getSql(),
0766:                        "UPDATE tablename SET propertyBigDecimal = ?, propertyBoolean = ?, propertyBooleanObject = ?, propertyByteObject = ?, propertyCalendar = ?, propertyChar = ?, propertyCharacterObject = ?, propertyDate = ?, propertyDouble = ?, propertyDoubleObject = ?, propertyFloat = ?, propertyFloatObject = ?, propertyInt = ?, propertyIntegerObject = ?, propertyLongObject = ?, propertyShort = ?, propertySqlDate = ?, propertyString = ?, propertyStringbuffer = ?, propertyTime = ?, propertyTimestamp = ?");
0767:
0768:                assertEquals(query.getParameters().getOrderedNames().size(), 21);
0769:                assertEquals(query.getParameters().getOrderedNames().get(0),
0770:                        "propertyBigDecimal");
0771:                assertEquals(query.getParameters().getOrderedNames().get(1),
0772:                        "propertyBoolean");
0773:                assertEquals(query.getParameters().getOrderedNames().get(2),
0774:                        "propertyBooleanObject");
0775:                assertEquals(query.getParameters().getOrderedNames().get(3),
0776:                        "propertyByteObject");
0777:                assertEquals(query.getParameters().getOrderedNames().get(4),
0778:                        "propertyCalendar");
0779:                assertEquals(query.getParameters().getOrderedNames().get(5),
0780:                        "propertyChar");
0781:                assertEquals(query.getParameters().getOrderedNames().get(6),
0782:                        "propertyCharacterObject");
0783:                assertEquals(query.getParameters().getOrderedNames().get(7),
0784:                        "propertyDate");
0785:                assertEquals(query.getParameters().getOrderedNames().get(8),
0786:                        "propertyDouble");
0787:                assertEquals(query.getParameters().getOrderedNames().get(9),
0788:                        "propertyDoubleObject");
0789:                assertEquals(query.getParameters().getOrderedNames().get(10),
0790:                        "propertyFloat");
0791:                assertEquals(query.getParameters().getOrderedNames().get(11),
0792:                        "propertyFloatObject");
0793:                assertEquals(query.getParameters().getOrderedNames().get(12),
0794:                        "propertyInt");
0795:                assertEquals(query.getParameters().getOrderedNames().get(13),
0796:                        "propertyIntegerObject");
0797:                assertEquals(query.getParameters().getOrderedNames().get(14),
0798:                        "propertyLongObject");
0799:                assertEquals(query.getParameters().getOrderedNames().get(15),
0800:                        "propertyShort");
0801:                assertEquals(query.getParameters().getOrderedNames().get(16),
0802:                        "propertySqlDate");
0803:                assertEquals(query.getParameters().getOrderedNames().get(17),
0804:                        "propertyString");
0805:                assertEquals(query.getParameters().getOrderedNames().get(18),
0806:                        "propertyStringbuffer");
0807:                assertEquals(query.getParameters().getOrderedNames().get(19),
0808:                        "propertyTime");
0809:                assertEquals(query.getParameters().getOrderedNames().get(20),
0810:                        "propertyTimestamp");
0811:                assertTrue(Arrays.equals(query.getParameters()
0812:                        .getOrderedNamesArray(), new String[] {
0813:                        "propertyBigDecimal", "propertyBoolean",
0814:                        "propertyBooleanObject", "propertyByteObject",
0815:                        "propertyCalendar", "propertyChar",
0816:                        "propertyCharacterObject", "propertyDate",
0817:                        "propertyDouble", "propertyDoubleObject",
0818:                        "propertyFloat", "propertyFloatObject", "propertyInt",
0819:                        "propertyIntegerObject", "propertyLongObject",
0820:                        "propertyShort", "propertySqlDate", "propertyString",
0821:                        "propertyStringbuffer", "propertyTime",
0822:                        "propertyTimestamp" }));
0823:
0824:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0825:                    public void setParameters(DbPreparedStatement statement) {
0826:                        Calendar cal = Calendar.getInstance();
0827:                        cal.set(2002, 7, 19, 12, 17, 52);
0828:                        cal.set(Calendar.MILLISECOND, 462);
0829:                        statement.setBigDecimal(1,
0830:                                new BigDecimal("98347.876438637")).setBoolean(
0831:                                2, false).setBoolean(3, true).setByte(4,
0832:                                (byte) 72)
0833:                                .setTimestamp(
0834:                                        5,
0835:                                        new java.sql.Timestamp(cal.getTime()
0836:                                                .getTime())).setString(6, "M")
0837:                                .setString(7, "p").setTimestamp(
0838:                                        8,
0839:                                        new java.sql.Timestamp(cal.getTime()
0840:                                                .getTime()))
0841:                                .setDouble(9, 12.3d).setDouble(10, 68.7d)
0842:                                .setFloat(11, 13.4f).setFloat(12, 42.1f)
0843:                                .setInt(13, 92).setInt(14, 34).setLong(15, 92)
0844:                                .setShort(16, (short) 7).setDate(
0845:                                        17,
0846:                                        new java.sql.Date(cal.getTime()
0847:                                                .getTime())).setString(18,
0848:                                        "string'value").setString(19,
0849:                                        "string'value2").setTime(20,
0850:                                        new Time(cal.getTime().getTime()))
0851:                                .setTimestamp(21,
0852:                                        new Timestamp(cal.getTime().getTime()));
0853:                    }
0854:                }));
0855:            }
0856:
0857:            public void testFieldsParametersBeanExcludedOracle() {
0858:                Update query = new Update(mOracle);
0859:                query.table("tablename").fieldsParametersExcluded(
0860:                        BeanImpl.class,
0861:                        new String[] { "propertyBoolean", "propertyByte",
0862:                                "propertyChar", "propertyDouble",
0863:                                "propertyInt", "propertyLong",
0864:                                "propertySqlDate", "propertyStringbuffer",
0865:                                "propertyTimestamp" });
0866:                assertEquals(
0867:                        query.getSql(),
0868:                        "UPDATE tablename SET propertyBigDecimal = ?, propertyBooleanObject = ?, propertyByteObject = ?, propertyCalendar = ?, propertyCharacterObject = ?, propertyDate = ?, propertyDoubleObject = ?, propertyEnum = ?, propertyFloat = ?, propertyFloatObject = ?, propertyIntegerObject = ?, propertyLongObject = ?, propertyShort = ?, propertyShortObject = ?, propertyString = ?, propertyTime = ?");
0869:
0870:                assertEquals(query.getParameters().getOrderedNames().size(), 16);
0871:                assertEquals(query.getParameters().getOrderedNames().get(0),
0872:                        "propertyBigDecimal");
0873:                assertEquals(query.getParameters().getOrderedNames().get(1),
0874:                        "propertyBooleanObject");
0875:                assertEquals(query.getParameters().getOrderedNames().get(2),
0876:                        "propertyByteObject");
0877:                assertEquals(query.getParameters().getOrderedNames().get(3),
0878:                        "propertyCalendar");
0879:                assertEquals(query.getParameters().getOrderedNames().get(4),
0880:                        "propertyCharacterObject");
0881:                assertEquals(query.getParameters().getOrderedNames().get(5),
0882:                        "propertyDate");
0883:                assertEquals(query.getParameters().getOrderedNames().get(6),
0884:                        "propertyDoubleObject");
0885:                assertEquals(query.getParameters().getOrderedNames().get(7),
0886:                        "propertyEnum");
0887:                assertEquals(query.getParameters().getOrderedNames().get(8),
0888:                        "propertyFloat");
0889:                assertEquals(query.getParameters().getOrderedNames().get(9),
0890:                        "propertyFloatObject");
0891:                assertEquals(query.getParameters().getOrderedNames().get(10),
0892:                        "propertyIntegerObject");
0893:                assertEquals(query.getParameters().getOrderedNames().get(11),
0894:                        "propertyLongObject");
0895:                assertEquals(query.getParameters().getOrderedNames().get(12),
0896:                        "propertyShort");
0897:                assertEquals(query.getParameters().getOrderedNames().get(13),
0898:                        "propertyShortObject");
0899:                assertEquals(query.getParameters().getOrderedNames().get(14),
0900:                        "propertyString");
0901:                assertEquals(query.getParameters().getOrderedNames().get(15),
0902:                        "propertyTime");
0903:                assertTrue(Arrays.equals(query.getParameters()
0904:                        .getOrderedNamesArray(), new String[] {
0905:                        "propertyBigDecimal", "propertyBooleanObject",
0906:                        "propertyByteObject", "propertyCalendar",
0907:                        "propertyCharacterObject", "propertyDate",
0908:                        "propertyDoubleObject", "propertyEnum",
0909:                        "propertyFloat", "propertyFloatObject",
0910:                        "propertyIntegerObject", "propertyLongObject",
0911:                        "propertyShort", "propertyShortObject",
0912:                        "propertyString", "propertyTime" }));
0913:
0914:                assertTrue(execute(query, new DbPreparedStatementHandler() {
0915:                    public void setParameters(DbPreparedStatement statement) {
0916:                        Calendar cal = Calendar.getInstance();
0917:                        cal.set(2002, 7, 19, 12, 17, 52);
0918:                        cal.set(Calendar.MILLISECOND, 462);
0919:                        statement.setBigDecimal(1,
0920:                                new BigDecimal("98347.876438637")).setBoolean(
0921:                                2, true).setByte(3, (byte) 72)
0922:                                .setTimestamp(
0923:                                        4,
0924:                                        new java.sql.Timestamp(cal.getTime()
0925:                                                .getTime())).setString(5, "o")
0926:                                .setTimestamp(
0927:                                        6,
0928:                                        new java.sql.Timestamp(cal.getTime()
0929:                                                .getTime()))
0930:                                .setDouble(7, 86.7d)
0931:                                .setString(8, "VALUE_THREE").setFloat(9, 13.4f)
0932:                                .setFloat(10, 32.8f).setInt(11, 358).setLong(
0933:                                        12, 9680L).setShort(13, (short) 12)
0934:                                .setShort(14, (short) 78).setString(15,
0935:                                        "string'value").setTime(16,
0936:                                        new Time(cal.getTime().getTime()));
0937:                    }
0938:                }));
0939:            }
0940:
0941:            public void testWhereBeanOracle() {
0942:                Update query = new Update(mOracle);
0943:                query.table("tablename").field("propertyBoolean", true).field(
0944:                        "propertyByte", (byte) 16).where(
0945:                        BeanImpl.getPopulatedBean());
0946:                assertEquals(
0947:                        query.getSql(),
0948:                        "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 = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') 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 = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
0949:                assertTrue(execute(query));
0950:            }
0951:
0952:            public void testWhereBeanConstrainedOracle() {
0953:                Update query = new Update(mOracle);
0954:                query.table("tablename").field("propertyBoolean", true).field(
0955:                        "propertyByte", (byte) 16).where(
0956:                        BeanImplConstrained.getPopulatedBean());
0957:                assertEquals(
0958:                        query.getSql(),
0959:                        "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 = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') 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 = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS') AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
0960:                assertTrue(execute(query));
0961:            }
0962:
0963:            public void testWhereBeanNullValuesOracle() {
0964:                Update query = new Update(mOracle);
0965:                query.table("tablename").field("propertyBoolean", true).field(
0966:                        "propertyByte", (byte) 16)
0967:                        .where(BeanImpl.getNullBean());
0968:                assertEquals(
0969:                        query.getSql(),
0970:                        "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");
0971:                assertTrue(execute(query));
0972:            }
0973:
0974:            public void testWhereBeanIncludedOracle() {
0975:                Update query = new Update(mOracle);
0976:                query.table("tablename").field("propertyBoolean", true).field(
0977:                        "propertyByte", (byte) 16).whereIncluded(
0978:                        BeanImpl.getPopulatedBean(),
0979:                        new String[] { "propertyByte", "propertyDouble",
0980:                                "propertyShort", "propertyStringbuffer",
0981:                                "propertyTime" });
0982:                assertEquals(
0983:                        query.getSql(),
0984:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyByte = 89 AND propertyDouble = 53348.34 AND propertyShort = 43 AND propertyStringbuffer = 'someotherstringbuff' AND propertyTime = TO_DATE('15:26:14', 'HH24:MI:SS')");
0985:                assertTrue(execute(query));
0986:            }
0987:
0988:            public void testWhereBeanExcludedOracle() {
0989:                Update query = new Update(mOracle);
0990:                query.table("tablename").field("propertyBoolean", true).field(
0991:                        "propertyByte", (byte) 16).whereExcluded(
0992:                        BeanImpl.getPopulatedBean(),
0993:                        new String[] { "propertyByte", "propertyDouble",
0994:                                "propertyShort", "propertyStringbuffer",
0995:                                "propertyTime" });
0996:                assertEquals(
0997:                        query.getSql(),
0998:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = 219038743.392874 AND propertyBoolean = 1 AND propertyBooleanObject = 0 AND propertyByteObject = 34 AND propertyCalendar = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') AND propertyChar = 'v' AND propertyCharacterObject = 'r' AND propertyDate = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS') 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 = TO_DATE('2002/06/18 00:00:00', 'YYYY/MM/DD HH24:MI:SS') AND propertyString = 'someotherstring' AND propertyTimestamp = TO_DATE('2002/06/18 15:26:14', 'YYYY/MM/DD HH24:MI:SS')");
0999:                assertTrue(execute(query));
1000:            }
1001:
1002:            public void testWhereBeanFilteredOracle() {
1003:                Update query = new Update(mOracle);
1004:                query.table("tablename").field("propertyBoolean", true).field(
1005:                        "propertyByte", (byte) 16).whereFiltered(
1006:                        BeanImpl.getPopulatedBean(),
1007:                        new String[] { "propertyByte", "propertyDouble",
1008:                                "propertyShort", "propertyStringbuffer",
1009:                                "propertyTime" },
1010:                        new String[] { "propertyByte", "propertyShort",
1011:                                "propertyTime" });
1012:                assertEquals(
1013:                        query.getSql(),
1014:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyDouble = 53348.34 AND propertyStringbuffer = 'someotherstringbuff'");
1015:                assertTrue(execute(query));
1016:            }
1017:
1018:            public void testWhereParametersBeanOracle() {
1019:                Update query = new Update(mOracle);
1020:                query.table("tablename").field("propertyBoolean", true).field(
1021:                        "propertyByte", (byte) 16).whereParameters(
1022:                        BeanImpl.class);
1023:                assertEquals(
1024:                        query.getSql(),
1025:                        "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 = ?");
1026:
1027:                assertEquals(query.getParameters().getOrderedNames().size(), 25);
1028:                assertEquals(query.getParameters().getOrderedNames().get(0),
1029:                        "propertyBigDecimal");
1030:                assertEquals(query.getParameters().getOrderedNames().get(1),
1031:                        "propertyBoolean");
1032:                assertEquals(query.getParameters().getOrderedNames().get(2),
1033:                        "propertyBooleanObject");
1034:                assertEquals(query.getParameters().getOrderedNames().get(3),
1035:                        "propertyByte");
1036:                assertEquals(query.getParameters().getOrderedNames().get(4),
1037:                        "propertyByteObject");
1038:                assertEquals(query.getParameters().getOrderedNames().get(5),
1039:                        "propertyCalendar");
1040:                assertEquals(query.getParameters().getOrderedNames().get(6),
1041:                        "propertyChar");
1042:                assertEquals(query.getParameters().getOrderedNames().get(7),
1043:                        "propertyCharacterObject");
1044:                assertEquals(query.getParameters().getOrderedNames().get(8),
1045:                        "propertyDate");
1046:                assertEquals(query.getParameters().getOrderedNames().get(9),
1047:                        "propertyDouble");
1048:                assertEquals(query.getParameters().getOrderedNames().get(10),
1049:                        "propertyDoubleObject");
1050:                assertEquals(query.getParameters().getOrderedNames().get(11),
1051:                        "propertyEnum");
1052:                assertEquals(query.getParameters().getOrderedNames().get(12),
1053:                        "propertyFloat");
1054:                assertEquals(query.getParameters().getOrderedNames().get(13),
1055:                        "propertyFloatObject");
1056:                assertEquals(query.getParameters().getOrderedNames().get(14),
1057:                        "propertyInt");
1058:                assertEquals(query.getParameters().getOrderedNames().get(15),
1059:                        "propertyIntegerObject");
1060:                assertEquals(query.getParameters().getOrderedNames().get(16),
1061:                        "propertyLong");
1062:                assertEquals(query.getParameters().getOrderedNames().get(17),
1063:                        "propertyLongObject");
1064:                assertEquals(query.getParameters().getOrderedNames().get(18),
1065:                        "propertyShort");
1066:                assertEquals(query.getParameters().getOrderedNames().get(19),
1067:                        "propertyShortObject");
1068:                assertEquals(query.getParameters().getOrderedNames().get(20),
1069:                        "propertySqlDate");
1070:                assertEquals(query.getParameters().getOrderedNames().get(21),
1071:                        "propertyString");
1072:                assertEquals(query.getParameters().getOrderedNames().get(22),
1073:                        "propertyStringbuffer");
1074:                assertEquals(query.getParameters().getOrderedNames().get(23),
1075:                        "propertyTime");
1076:                assertEquals(query.getParameters().getOrderedNames().get(24),
1077:                        "propertyTimestamp");
1078:                assertTrue(Arrays.equals(query.getParameters()
1079:                        .getOrderedNamesArray(), new String[] {
1080:                        "propertyBigDecimal", "propertyBoolean",
1081:                        "propertyBooleanObject", "propertyByte",
1082:                        "propertyByteObject", "propertyCalendar",
1083:                        "propertyChar", "propertyCharacterObject",
1084:                        "propertyDate", "propertyDouble",
1085:                        "propertyDoubleObject", "propertyEnum",
1086:                        "propertyFloat", "propertyFloatObject", "propertyInt",
1087:                        "propertyIntegerObject", "propertyLong",
1088:                        "propertyLongObject", "propertyShort",
1089:                        "propertyShortObject", "propertySqlDate",
1090:                        "propertyString", "propertyStringbuffer",
1091:                        "propertyTime", "propertyTimestamp" }));
1092:
1093:                // don't check if actual rows were returned, since Oracle doesn't
1094:                // match on the date types
1095:                execute(query, new DbPreparedStatementHandler() {
1096:                    public void setParameters(DbPreparedStatement statement) {
1097:                        Calendar cal = Calendar.getInstance();
1098:                        cal.set(2002, 5, 18, 15, 26, 14);
1099:                        cal.set(Calendar.MILLISECOND, 764);
1100:                        statement.setBigDecimal(1,
1101:                                new BigDecimal("219038743.392874")).setBoolean(
1102:                                2, true).setBoolean(3, false).setByte(4,
1103:                                (byte) 89).setByte(5, (byte) 34)
1104:                                .setTimestamp(
1105:                                        6,
1106:                                        new java.sql.Timestamp(cal.getTime()
1107:                                                .getTime())).setString(7, "v")
1108:                                .setString(8, "r").setTimestamp(
1109:                                        9,
1110:                                        new java.sql.Timestamp(cal.getTime()
1111:                                                .getTime())).setDouble(10,
1112:                                        53348.34d).setDouble(11, 143298.692d)
1113:                                .setString(12, "VALUE_THREE").setDouble(13,
1114:                                        98634.2d).setDouble(14, 8734.7d)
1115:                                .setInt(15, 545).setInt(16, 968).setLong(17,
1116:                                        34563L).setLong(18, 66875L).setShort(
1117:                                        19, (short) 43)
1118:                                .setShort(20, (short) 68).setDate(
1119:                                        21,
1120:                                        new java.sql.Date(cal.getTime()
1121:                                                .getTime())).setString(22,
1122:                                        "someotherstring").setString(23,
1123:                                        "someotherstringbuff").setTime(24,
1124:                                        new Time(15, 26, 14)).setTimestamp(25,
1125:                                        new Timestamp(cal.getTime().getTime()));
1126:                    }
1127:                });
1128:            }
1129:
1130:            public void testWhereParametersBeanConstrainedOracle() {
1131:                Update query = new Update(mOracle);
1132:                query.table("tablename").field("propertyBoolean", true).field(
1133:                        "propertyByte", (byte) 16).whereParameters(
1134:                        BeanImplConstrained.class);
1135:                assertEquals(
1136:                        query.getSql(),
1137:                        "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 = ?");
1138:
1139:                assertEquals(query.getParameters().getOrderedNames().size(), 22);
1140:                assertEquals(query.getParameters().getOrderedNames().get(0),
1141:                        "propertyBigDecimal");
1142:                assertEquals(query.getParameters().getOrderedNames().get(1),
1143:                        "propertyBoolean");
1144:                assertEquals(query.getParameters().getOrderedNames().get(2),
1145:                        "propertyBooleanObject");
1146:                assertEquals(query.getParameters().getOrderedNames().get(3),
1147:                        "propertyByte");
1148:                assertEquals(query.getParameters().getOrderedNames().get(4),
1149:                        "propertyByteObject");
1150:                assertEquals(query.getParameters().getOrderedNames().get(5),
1151:                        "propertyCalendar");
1152:                assertEquals(query.getParameters().getOrderedNames().get(6),
1153:                        "propertyChar");
1154:                assertEquals(query.getParameters().getOrderedNames().get(7),
1155:                        "propertyCharacterObject");
1156:                assertEquals(query.getParameters().getOrderedNames().get(8),
1157:                        "propertyDate");
1158:                assertEquals(query.getParameters().getOrderedNames().get(9),
1159:                        "propertyDouble");
1160:                assertEquals(query.getParameters().getOrderedNames().get(10),
1161:                        "propertyDoubleObject");
1162:                assertEquals(query.getParameters().getOrderedNames().get(11),
1163:                        "propertyFloat");
1164:                assertEquals(query.getParameters().getOrderedNames().get(12),
1165:                        "propertyFloatObject");
1166:                assertEquals(query.getParameters().getOrderedNames().get(13),
1167:                        "propertyInt");
1168:                assertEquals(query.getParameters().getOrderedNames().get(14),
1169:                        "propertyIntegerObject");
1170:                assertEquals(query.getParameters().getOrderedNames().get(15),
1171:                        "propertyLongObject");
1172:                assertEquals(query.getParameters().getOrderedNames().get(16),
1173:                        "propertyShort");
1174:                assertEquals(query.getParameters().getOrderedNames().get(17),
1175:                        "propertySqlDate");
1176:                assertEquals(query.getParameters().getOrderedNames().get(18),
1177:                        "propertyString");
1178:                assertEquals(query.getParameters().getOrderedNames().get(19),
1179:                        "propertyStringbuffer");
1180:                assertEquals(query.getParameters().getOrderedNames().get(20),
1181:                        "propertyTime");
1182:                assertEquals(query.getParameters().getOrderedNames().get(21),
1183:                        "propertyTimestamp");
1184:                assertTrue(Arrays.equals(query.getParameters()
1185:                        .getOrderedNamesArray(), new String[] {
1186:                        "propertyBigDecimal", "propertyBoolean",
1187:                        "propertyBooleanObject", "propertyByte",
1188:                        "propertyByteObject", "propertyCalendar",
1189:                        "propertyChar", "propertyCharacterObject",
1190:                        "propertyDate", "propertyDouble",
1191:                        "propertyDoubleObject", "propertyFloat",
1192:                        "propertyFloatObject", "propertyInt",
1193:                        "propertyIntegerObject", "propertyLongObject",
1194:                        "propertyShort", "propertySqlDate", "propertyString",
1195:                        "propertyStringbuffer", "propertyTime",
1196:                        "propertyTimestamp" }));
1197:
1198:                // don't check if actual rows were returned, since Oracle doesn't
1199:                // match on the date types
1200:                execute(query, new DbPreparedStatementHandler() {
1201:                    public void setParameters(DbPreparedStatement statement) {
1202:                        Calendar cal = Calendar.getInstance();
1203:                        cal.set(2002, 5, 18, 15, 26, 14);
1204:                        cal.set(Calendar.MILLISECOND, 764);
1205:                        statement.setBigDecimal(1,
1206:                                new BigDecimal("219038743.392874")).setBoolean(
1207:                                2, true).setBoolean(3, false).setByte(4,
1208:                                (byte) 89).setByte(5, (byte) 34)
1209:                                .setTimestamp(
1210:                                        6,
1211:                                        new java.sql.Timestamp(cal.getTime()
1212:                                                .getTime())).setString(7, "v")
1213:                                .setString(8, "r").setTimestamp(
1214:                                        9,
1215:                                        new java.sql.Timestamp(cal.getTime()
1216:                                                .getTime())).setDouble(10,
1217:                                        53348.34d).setDouble(11, 143298.692d)
1218:                                .setFloat(12, 98634.2f).setFloat(13, 8734.7f)
1219:                                .setInt(14, 545).setInt(15, 968).setLong(16,
1220:                                        66875L).setShort(17, (short) 43)
1221:                                .setDate(
1222:                                        18,
1223:                                        new java.sql.Date(cal.getTime()
1224:                                                .getTime())).setString(19,
1225:                                        "someotherstring").setString(20,
1226:                                        "someotherstringbuff").setTime(21,
1227:                                        new Time(cal.getTime().getTime()))
1228:                                .setTimestamp(22,
1229:                                        new Timestamp(cal.getTime().getTime()));
1230:                    }
1231:                });
1232:            }
1233:
1234:            public void testWhereParametersBeanExcludedOracle() {
1235:                Update query = new Update(mOracle);
1236:                query.table("tablename").field("propertyBoolean", true).field(
1237:                        "propertyByte", (byte) 16).whereParametersExcluded(
1238:                        BeanImpl.class,
1239:                        new String[] { "propertyBoolean", "propertyByte",
1240:                                "propertyChar", "propertyDouble",
1241:                                "propertyInt", "propertyLong",
1242:                                "propertySqlDate", "propertyStringbuffer",
1243:                                "propertyTimestamp", "propertyCalendar",
1244:                                "propertyDate", "propertyTime" });
1245:                assertEquals(
1246:                        query.getSql(),
1247:                        "UPDATE tablename SET propertyBoolean = 1, propertyByte = 16 WHERE propertyBigDecimal = ? AND propertyBooleanObject = ? AND propertyByteObject = ? AND propertyCharacterObject = ? AND propertyDoubleObject = ? AND propertyEnum = ? AND propertyFloat = ? AND propertyFloatObject = ? AND propertyIntegerObject = ? AND propertyLongObject = ? AND propertyShort = ? AND propertyShortObject = ? AND propertyString = ?");
1248:
1249:                assertEquals(query.getParameters().getOrderedNames().size(), 13);
1250:                assertEquals(query.getParameters().getOrderedNames().get(0),
1251:                        "propertyBigDecimal");
1252:                assertEquals(query.getParameters().getOrderedNames().get(1),
1253:                        "propertyBooleanObject");
1254:                assertEquals(query.getParameters().getOrderedNames().get(2),
1255:                        "propertyByteObject");
1256:                assertEquals(query.getParameters().getOrderedNames().get(3),
1257:                        "propertyCharacterObject");
1258:                assertEquals(query.getParameters().getOrderedNames().get(4),
1259:                        "propertyDoubleObject");
1260:                assertEquals(query.getParameters().getOrderedNames().get(5),
1261:                        "propertyEnum");
1262:                assertEquals(query.getParameters().getOrderedNames().get(6),
1263:                        "propertyFloat");
1264:                assertEquals(query.getParameters().getOrderedNames().get(7),
1265:                        "propertyFloatObject");
1266:                assertEquals(query.getParameters().getOrderedNames().get(8),
1267:                        "propertyIntegerObject");
1268:                assertEquals(query.getParameters().getOrderedNames().get(9),
1269:                        "propertyLongObject");
1270:                assertEquals(query.getParameters().getOrderedNames().get(10),
1271:                        "propertyShort");
1272:                assertEquals(query.getParameters().getOrderedNames().get(11),
1273:                        "propertyShortObject");
1274:                assertEquals(query.getParameters().getOrderedNames().get(12),
1275:                        "propertyString");
1276:                assertTrue(Arrays.equals(query.getParameters()
1277:                        .getOrderedNamesArray(), new String[] {
1278:                        "propertyBigDecimal", "propertyBooleanObject",
1279:                        "propertyByteObject", "propertyCharacterObject",
1280:                        "propertyDoubleObject", "propertyEnum",
1281:                        "propertyFloat", "propertyFloatObject",
1282:                        "propertyIntegerObject", "propertyLongObject",
1283:                        "propertyShort", "propertyShortObject",
1284:                        "propertyString" }));
1285:
1286:                assertTrue(execute(query, new DbPreparedStatementHandler() {
1287:                    public void setParameters(DbPreparedStatement statement) {
1288:                        Calendar cal = Calendar.getInstance();
1289:                        cal.set(2002, 5, 18, 15, 26, 14);
1290:                        cal.set(Calendar.MILLISECOND, 764);
1291:                        statement.setBigDecimal(1,
1292:                                new BigDecimal("219038743.392874")).setBoolean(
1293:                                2, false).setByte(3, (byte) 34).setString(4,
1294:                                "r").setDouble(5, 143298.692d).setString(6,
1295:                                "VALUE_THREE").setFloat(7, 98634.2f).setFloat(
1296:                                8, 8734.7f).setInt(9, 968).setLong(10, 66875L)
1297:                                .setShort(11, (short) 43).setShort(12,
1298:                                        (short) 68).setString(13,
1299:                                        "someotherstring");
1300:                    }
1301:                }));
1302:            }
1303:
1304:            public void testSubselectParamsOracle() {
1305:                Select fieldquery = new Select(mOracle);
1306:                fieldquery.from("table2").field("max(propertyLong)")
1307:                        .whereParameter("propertyInt", ">");
1308:                Select wherequery = new Select(mOracle);
1309:                wherequery.from("table2").field("max(propertyShort)")
1310:                        .whereParameter("propertyShort", "!=");
1311:                Update query = new Update(mOracle);
1312:                // shuffled the structure around a bit to test the correct order usage
1313:                query.where("propertyShort >= (" + wherequery + ")")
1314:                        .whereSubselect(wherequery).whereParameterOr(
1315:                                "propertyString", "propertyString2", "=")
1316:                        .table("tablename").fieldParameter("propertyString")
1317:                        .fieldCustom("propertyLong", "(" + fieldquery + ")")
1318:                        .fieldSubselect(fieldquery);
1319:                assertEquals(
1320:                        query.getSql(),
1321:                        "UPDATE tablename SET propertyString = ?, propertyLong = (SELECT max(propertyLong) FROM table2 WHERE propertyInt > ?) WHERE propertyShort >= (SELECT max(propertyShort) FROM table2 WHERE propertyShort != ?) OR propertyString = ?");
1322:                String[] parameters = query.getParameters()
1323:                        .getOrderedNamesArray();
1324:                assertEquals(4, parameters.length);
1325:                assertEquals(parameters[0], "propertyString");
1326:                assertEquals(parameters[1], "propertyInt");
1327:                assertEquals(parameters[2], "propertyShort");
1328:                assertEquals(parameters[3], "propertyString2");
1329:
1330:                assertTrue(execute(query, new DbPreparedStatementHandler() {
1331:                    public void setParameters(DbPreparedStatement statement) {
1332:                        statement.setString("propertyString", "thestring")
1333:                                .setInt("propertyInt", 1).setShort(
1334:                                        "propertyShort", (short) 5).setString(
1335:                                        "propertyString2", "anotherstring");
1336:                    }
1337:                }));
1338:
1339:                // Automated subselect creation
1340:                query = new Update(mOracle);
1341:                // shuffled the structure around a bit to test the correct order usage
1342:                query.where("propertyShort", ">=", wherequery)
1343:                        .whereParameterOr("propertyString", "propertyString2",
1344:                                "=").whereOr(
1345:                                "tablename.propertyFloat",
1346:                                ">",
1347:                                new Select(mOracle).from("table2").field(
1348:                                        "max(propertyLong)").whereParameter(
1349:                                        "propertyLong", "!=")).whereAnd(
1350:                                "tablename.propertyDouble",
1351:                                "<=",
1352:                                new Select(mOracle).from("table2").field(
1353:                                        "max(propertyFloat)").whereParameter(
1354:                                        "propertyFloat", "!=")).table(
1355:                                "tablename").fieldParameter("propertyString")
1356:                        .field("propertyLong", fieldquery);
1357:                assertEquals(
1358:                        query.getSql(),
1359:                        "UPDATE tablename SET propertyString = ?, propertyLong = (SELECT max(propertyLong) FROM table2 WHERE propertyInt > ?) WHERE propertyShort >= (SELECT max(propertyShort) FROM table2 WHERE propertyShort != ?) OR propertyString = ? OR tablename.propertyFloat > (SELECT max(propertyLong) FROM table2 WHERE propertyLong != ?) AND tablename.propertyDouble <= (SELECT max(propertyFloat) FROM table2 WHERE propertyFloat != ?)");
1360:                parameters = query.getParameters().getOrderedNamesArray();
1361:                assertEquals(6, parameters.length);
1362:                assertEquals(parameters[0], "propertyString");
1363:                assertEquals(parameters[1], "propertyInt");
1364:                assertEquals(parameters[2], "propertyShort");
1365:                assertEquals(parameters[3], "propertyString2");
1366:
1367:                assertTrue(execute(query, new DbPreparedStatementHandler() {
1368:                    public void setParameters(DbPreparedStatement statement) {
1369:                        statement.setString("propertyString", "thestring")
1370:                                .setInt("propertyInt", 1).setShort(
1371:                                        "propertyShort", (short) 5).setString(
1372:                                        "propertyString2", "anotherstring")
1373:                                .setLong("propertyLong", 99999999).setFloat(
1374:                                        "propertyFloat", -1f);
1375:                    }
1376:                }));
1377:            }
1378:
1379:            public void testCloneOracle() {
1380:                Select fieldquery = new Select(mOracle);
1381:                fieldquery.from("table2").field("max(propertyLong)")
1382:                        .whereParameter("propertyInt", ">");
1383:                Select wherequery = new Select(mOracle);
1384:                wherequery.from("table2").field("max(propertyShort)")
1385:                        .whereParameter("propertyShort", "!=");
1386:
1387:                final Calendar cal = Calendar.getInstance();
1388:                cal.set(2002, 7, 19, 12, 17, 52);
1389:                cal.set(Calendar.MILLISECOND, 462);
1390:                Update query = new Update(mOracle);
1391:                query.table("tablename").hint("NO_INDEX").fieldParameter(
1392:                        "nullColumn").field("propertyBigDecimal",
1393:                        new BigDecimal("98347.876438637")).fieldParameter(
1394:                        "propertyBoolean").fieldParameter("propertyByte")
1395:                        .field("propertyCalendar", cal.getTime())
1396:                        .fieldParameter("propertyChar").field("propertyDate",
1397:                                cal).field("propertyDouble", 12.3d)
1398:                        .fieldParameter("propertyFloat").fieldParameter(
1399:                                "propertyInt").field("propertyShort",
1400:                                (short) 12).fieldParameter("propertySqlDate")
1401:                        .fieldParameter("propertyString").field(
1402:                                "propertyStringbuffer",
1403:                                new StringBuffer("stringbuffer'value")).field(
1404:                                "propertyTime",
1405:                                new Time(cal.getTime().getTime()))
1406:                        .fieldParameter("propertyTimestamp").fieldCustom(
1407:                                "propertyLong", "(" + fieldquery + ")")
1408:                        .fieldSubselect(fieldquery).where(
1409:                                "tablename.propertyShort >= (" + wherequery
1410:                                        + ")").whereSubselect(wherequery)
1411:                        .whereParameterOr("tablename.propertyString",
1412:                                "propertyString", "=").whereOr(
1413:                                "tablename.propertyByte", "=", (byte) 54)
1414:                        .whereAnd("tablename.propertyDouble", "!=", 73453.71d)
1415:                        .whereParameterOr("tablename.propertyInt",
1416:                                "propertyInt", "=").whereParameterAnd(
1417:                                "tablename.propertyLong", "propertyLong", "<")
1418:                        .whereParameterOr("tablename.propertyChar",
1419:                                "propertyChar", "=");
1420:
1421:                Update query_clone = query.clone();
1422:                assertEquals(query.getSql(), query_clone.getSql());
1423:                assertTrue(query != query_clone);
1424:                execute(query, new DbPreparedStatementHandler() {
1425:                    public void setParameters(DbPreparedStatement statement) {
1426:                        statement.setString("nullColumn", null).setBoolean(
1427:                                "propertyBoolean", true).setByte(
1428:                                "propertyByte", (byte) 16).setString(
1429:                                "propertyChar", "M").setFloat("propertyFloat",
1430:                                13.4f).setInt("propertyInt", 34).setDate(
1431:                                "propertySqlDate",
1432:                                new java.sql.Date(cal.getTime().getTime()))
1433:                                .setString("propertyString", "string'value")
1434:                                .setTimestamp("propertyTimestamp",
1435:                                        new Timestamp(cal.getTime().getTime()))
1436:                                .setShort("propertyShort", (short) 4).setLong(
1437:                                        "propertyLong", 34543);
1438:                    }
1439:                });
1440:            }
1441:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.