001: /*
002: * Danet GmbH
003: * Beratung und Software-Entwicklung
004: * Geschäftstelle AN
005: *
006: * $Id: PersMap.java,v 1.3 2007/03/27 21:59:42 mlipp Exp $
007: *
008: * $Log: PersMap.java,v $
009: * Revision 1.3 2007/03/27 21:59:42 mlipp
010: * Fixed lots of checkstyle warnings.
011: *
012: * Revision 1.2 2005/04/22 15:11:07 drmlipp
013: * Merged changes from 1.3 branch up to 1.3p15.
014: *
015: * Revision 1.1.1.3.6.2 2005/04/14 11:45:08 drmlipp
016: * More (minor) optimizations.
017: *
018: * Revision 1.1.1.3.6.1 2005/04/13 16:14:08 drmlipp
019: * Optimized db access.
020: *
021: * Revision 1.1.1.3 2004/08/18 15:18:47 drmlipp
022: * Update to 1.2
023: *
024: * Revision 1.24 2004/06/14 19:37:20 lipp
025: * Fixed assignment functions and cleaned up assignment related
026: * interfaces.
027: *
028: * Revision 1.23 2004/02/13 10:16:20 lipp
029: * Using "standard" table for tests.
030: *
031: * Revision 1.22 2003/11/03 12:40:58 lipp
032: * Added test.
033: *
034: * Revision 1.21 2003/08/27 12:14:41 lipp
035: * Fixed test case.
036: *
037: * Revision 1.20 2003/05/23 14:40:10 lipp
038: * HSQL does not supports column length queries after all.
039: *
040: * Revision 1.19 2003/05/17 20:03:09 lipp
041: * HSQL supports column length queries now.
042: *
043: * Revision 1.18 2003/03/06 18:20:11 schlue
044: * Test cases for batch support separated.
045: *
046: * Revision 1.17 2003/03/06 13:47:46 schlue
047: * Handling of null values fixed.
048: *
049: * Revision 1.16 2003/02/21 16:02:29 lipp
050: * Must use reeeeaaaaally long string to make this a real test case.
051: *
052: * Revision 1.15 2003/02/20 09:37:24 schlue
053: * Using driver name instead of product as criterion for special treatment.
054: *
055: * Revision 1.14 2003/02/18 15:20:38 schlue
056: * svalue handling fixed.
057: *
058: * Revision 1.13 2002/10/09 08:57:30 schlue
059: * Missing import statements added.
060: *
061: * Revision 1.12 2002/10/09 08:48:07 schlue
062: * Style checking errors corrected.
063: *
064: * Revision 1.11 2002/10/08 12:00:55 schlue
065: * Test case for serialization added.
066: * New aspects of test case for setting of connection added.
067: *
068: * Revision 1.10 2002/08/30 07:24:25 schlue
069: * isModified added.
070: *
071: * Revision 1.9 2002/08/23 13:17:09 schlue
072: * Modifications and fixes acc. to code review.
073: *
074: * Revision 1.8 2002/08/22 17:17:26 schlue
075: * Testing of threshold for svalue against DB schema implemented.
076: * New utility operation for determining column length added.
077: * Optional oracle test environment.
078: *
079: * Revision 1.7 2002/08/22 10:58:53 schlue
080: * Utility method to determine column length added.
081: *
082: * Revision 1.6 2002/08/22 08:36:07 schlue
083: * Max key length added.
084: * Garbage collection optimzed.
085: *
086: * Revision 1.5 2002/08/20 08:58:42 lipp
087: * Updated retrieval of jdbc infos.
088: *
089: * Revision 1.4 2002/08/20 08:48:22 schlue
090: * Testcases adapted to new JDBCPersistenceMap code.
091: *
092: * Revision 1.3 2002/02/04 15:31:31 lipp
093: * New special db server properties.
094: *
095: * Revision 1.2 2001/12/11 10:27:01 feldgen
096: * loading jdbc-properties from file
097: *
098: * Revision 1.1 2001/12/07 12:33:17 schlue
099: * Implementation of persistent map finished
100: *
101: *
102: */
103: package util;
104:
105: import java.io.ByteArrayInputStream;
106: import java.io.ByteArrayOutputStream;
107: import java.io.IOException;
108: import java.io.ObjectInputStream;
109: import java.io.ObjectOutputStream;
110:
111: import java.util.Properties;
112:
113: import java.sql.Connection;
114: import java.sql.DriverManager;
115:
116: import de.danet.an.util.JDBCUtil;
117: import de.danet.an.util.persistentmaps.JDBCPersistentMap;
118:
119: import junit.framework.Test;
120: import junit.framework.TestCase;
121: import junit.framework.TestSuite;
122:
123: /**
124: * Tests the SegmentedResourceBundle
125: * @version 1.0
126: */
127: public class PersMap extends TestCase {
128: /**
129: * Properties to use in test cases
130: */
131: private static Properties props = new Properties();
132: /**
133: * Default connection used in test cases.
134: */
135: private static Connection con = null;
136: /**
137: * Optional second connection used in test cases.
138: */
139: private static Connection secondCon = null;
140: /**
141: * Flag if bacth support should be tested separately
142: */
143: private static boolean testBatchSupport = false;
144: /**
145: * Name of DB product.
146: */
147: private static String dbDriver = null;
148:
149: /**
150: * Konstruktor zum Erzeugen eines TestCase.
151: * @param name a <code>String</code> value
152: */
153: public PersMap(String name) {
154: super (name);
155: }
156:
157: /**
158: * Assembling the test suite
159: * @return a <code>Test</code> value
160: * @exception Exception if an error occurs
161: */
162: public static Test suite() throws Exception {
163: TestSuite suite = new TestSuite();
164: // load properties from jdbc.properties
165: props.load(Thread.currentThread().getContextClassLoader()
166: .getResourceAsStream("jdbc.properties"));
167: // register database driver
168: Class.forName(props.getProperty("driver"));
169: con = DriverManager.getConnection(
170: props.getProperty("database"), props
171: .getProperty("user"), props
172: .getProperty("password"));
173: dbDriver = con.getMetaData().getDriverName();
174: System.out.println("First Driver: " + dbDriver);
175: if (JDBCUtil.dbProperties(null, con).supportsBatchUpdates()) {
176: System.out.println("First driver supports batch");
177: testBatchSupport = true;
178: }
179: boolean withSecondCon = false;
180: try {
181: props.load(Thread.currentThread().getContextClassLoader()
182: .getResourceAsStream("jdbc-other.properties"));
183: withSecondCon = true;
184: System.out.println("Testing with two connections");
185: } catch (NullPointerException exc) {
186: // To be ignored
187: }
188: if (withSecondCon) {
189: // register second database driver
190: Class.forName(props.getProperty("driver"));
191: secondCon = DriverManager.getConnection(props
192: .getProperty("database"),
193: props.getProperty("user"), props
194: .getProperty("password"));
195: System.out.println("Second Driver: "
196: + secondCon.getMetaData().getDriverName());
197:
198: if (JDBCUtil.dbProperties(null, secondCon)
199: .supportsBatchUpdates()) {
200: System.out.println("Second driver supports batch");
201: testBatchSupport = !testBatchSupport;
202: }
203: } else {
204: testBatchSupport = false;
205: }
206: System.out.println("Test batch support: " + testBatchSupport);
207:
208: suite.addTest(new PersMap("setConnection"));
209: suite.addTest(new PersMap("setSValueMax"));
210: suite.addTest(new PersMap("setID"));
211: suite.addTest(new PersMap("storeAndLoad"));
212: suite.addTest(new PersMap("modifyAndRemove"));
213: suite.addTest(new PersMap("loadStatement"));
214: suite.addTest(new PersMap("insertStatement"));
215: suite.addTest(new PersMap("updateStatement"));
216: suite.addTest(new PersMap("deleteStatement"));
217: suite.addTest(new PersMap("copyMap"));
218: suite.addTest(new PersMap("cleanTable"));
219: suite.addTest(new PersMap("serialize"));
220: suite.addTest(new PersMap("nullString"));
221:
222: return suite;
223: }
224:
225: /**
226: * Test setting of connections.
227: * This includes support of (two) parallel connections.
228: * @exception Exception if an error occurs
229: */
230: public void setConnection() throws Exception {
231: JDBCPersistentMap testMap = new JDBCPersistentMap(null, "Danet");
232: testMap.setConnection(con);
233: testMap.put("HSc", "Holger Schlüter");
234: testMap.put("MSc", "Matthias Schirm");
235: testMap.setConnection(con);
236: testMap.store();
237: testMap.setConnection(con);
238: testMap.store();
239: if (secondCon != null) {
240: testMap.clear();
241: testMap.setConnection(secondCon);
242: assertTrue(testMap.maxKeyLength() == 50);
243: testMap.put("ALM", "Alex Müller");
244: testMap.store();
245: testMap.clear();
246: assertTrue(testMap.size() == 0);
247: testMap.load();
248: assertTrue(testMap.size() == 1);
249: }
250: testMap.setConnection(null);
251: testMap.setConnection(con);
252: assertTrue(testMap.maxKeyLength() == 50);
253: testMap.load();
254: assertTrue(testMap.size() == 2);
255: if (secondCon != null) {
256: testMap.setConnection(secondCon);
257: testMap.store();
258: testMap.load();
259: assertTrue(testMap.size() == 2);
260: }
261: testMap.setConnection(con);
262: if (secondCon != null) {
263: // Change connection with unsaved modifications
264: testMap.load();
265: assertTrue(testMap.size() == 2);
266: testMap.put("HSc", "Holger Schlueter"); //Update
267: testMap.remove("MSc"); // Delete
268: testMap.put("GB", "Gunnar von der Beck"); // Insert
269: testMap.put("ALM", "Alex Müller");
270: assertTrue(testMap.size() == 3);
271: testMap.setConnection(secondCon);
272: testMap.store();
273: testMap.load();
274: assertTrue(testMap.size() == 3);
275: }
276: testMap.setConnection(con);
277: testMap.clear();
278: testMap.store();
279: if (secondCon != null) {
280: testMap.setConnection(secondCon);
281: testMap.clear();
282: testMap.store();
283: }
284: }
285:
286: /**
287: * Test setting of maximum svalue
288: * @exception Exception if an error occurs
289: */
290: public void setSValueMax() throws Exception {
291: JDBCPersistentMap testMap = new JDBCPersistentMap(null, "Danet");
292: int maxSValue = 0;
293: testMap.setSValueMax(130764);
294: assertTrue(testMap.getSValueMax() == 130764);
295: testMap.setConnection(con);
296: maxSValue = testMap.getSValueMax();
297: testMap.setSValueMax(maxSValue + 1);
298: assertTrue("Expected " + maxSValue + ", got "
299: + testMap.getSValueMax(),
300: testMap.getSValueMax() == maxSValue);
301: testMap.setSValueMax(maxSValue - 1);
302: assertTrue(testMap.getSValueMax() == maxSValue - 1);
303: testMap.setSValueMax(maxSValue);
304: assertTrue(testMap.getSValueMax() == maxSValue);
305: testMap.setConnection(null);
306: assertTrue(testMap.getSValueMax() == maxSValue);
307: testMap.setSValueMax(maxSValue + 1);
308: assertTrue(testMap.getSValueMax() == maxSValue + 1);
309:
310: JDBCPersistentMap testMap2 = new JDBCPersistentMap(null,
311: "Danet2");
312: Connection con2 = null;
313: int maxSValue2 = 0;
314: if (secondCon != null) {
315: con2 = secondCon;
316: testMap2.setConnection(con2);
317: maxSValue2 = testMap2.getSValueMax();
318: testMap2.setSValueMax(maxSValue2 + 1);
319: assertTrue(testMap2.getSValueMax() == maxSValue2);
320: testMap2.setSValueMax(maxSValue2 - 1);
321: assertTrue(testMap2.getSValueMax() == maxSValue2 - 1);
322: testMap2.setSValueMax(maxSValue2);
323: assertTrue(testMap2.getSValueMax() == maxSValue2);
324: } else {
325: con2 = con;
326: maxSValue2 = maxSValue;
327: testMap2.setConnection(con2);
328: testMap2.setSValueMax(maxSValue2);
329: assertTrue(testMap2.getSValueMax() == maxSValue2);
330: }
331: if (maxSValue < maxSValue2) {
332: testMap2.setConnection(con);
333: assertTrue(testMap2.getSValueMax() == maxSValue);
334: } else if (maxSValue2 < maxSValue) {
335: testMap.setConnection(con2);
336: assertTrue(testMap.getSValueMax() == maxSValue2);
337: }
338: testMap.setConnection(null);
339: testMap.setSValueMax(maxSValue + maxSValue2);
340: assertTrue(testMap.getSValueMax() == maxSValue + maxSValue2);
341: assertTrue(testMap2.getSValueMax() != maxSValue + maxSValue2);
342: testMap2.setConnection(null);
343: testMap2.setSValueMax(maxSValue + maxSValue2);
344: assertTrue(testMap2.getSValueMax() == maxSValue + maxSValue2);
345: testMap.setConnection(con);
346: assertTrue(testMap.getSValueMax() == maxSValue + maxSValue2);
347: testMap.setConnection(null);
348: }
349:
350: /**
351: * Test setting of IDs
352: * @exception Exception if an error occurs
353: */
354: public void setID() throws Exception {
355: JDBCPersistentMap testMap = new JDBCPersistentMap(null, "Danet");
356: assertTrue(!testMap.isModified());
357: testMap.setConnection(con);
358: assertTrue(!testMap.isModified());
359: testMap.put("HSc", "Holger Schlüter");
360: assertTrue(testMap.isModified());
361: testMap.put("MSc", "Matthias Schirm");
362: testMap.setConnection(con);
363: assertTrue(testMap.isModified());
364: testMap.store();
365: assertTrue(!testMap.isModified());
366: testMap.setMapId("Dnaet");
367: assertTrue(!testMap.isModified());
368: testMap.load();
369: assertTrue(!testMap.isModified());
370: assertTrue(testMap.size() == 0);
371: testMap.setMapId("Danet");
372: testMap.load();
373: assertTrue(testMap.size() == 2);
374: testMap.clear();
375: testMap.store();
376: }
377:
378: /**
379: * Test storing an reloading of a map. If (exactly) one
380: * connection supports batch commands, test for both connections.
381: * @exception Exception if an error occurs
382: */
383: public void storeAndLoad() throws Exception {
384: storeAndLoadCon(con);
385: if (testBatchSupport) {
386: storeAndLoadCon(secondCon);
387: }
388: }
389:
390: /**
391: * Test storing an reloading of a map for a given connection
392: * @exception Exception if an error occurs
393: * @param usecon connection to be used
394: */
395: private void storeAndLoadCon(Connection useCon) throws Exception {
396: JDBCPersistentMap storeMap = new JDBCPersistentMap(null,
397: "Danet");
398: storeMap.setConnection(useCon);
399: assertTrue(storeMap.maxKeyLength() == 50);
400: assertTrue(!storeMap.isModified());
401: storeMap.put("HSc", "Holger Schlüter");
402: assertTrue(storeMap.isModified());
403: storeMap.put("MSc", "Matthias Schirm");
404: storeMap.put("ML", "Dr. Michael Lipp");
405: storeMap.put("GB", "Gunnar von de Beck");
406: StringBuffer sb = new StringBuffer();
407: for (int i = 0; i < 1600; i++) {
408: sb.append("0123456789");
409: }
410: String longString = sb.toString();
411: storeMap.put("LONG", longString);
412: storeMap.put("INT", new Integer(1307));
413: storeMap.put("NULL", null);
414: boolean exceptionCaught = false;
415: try {
416: storeMap.put(null, null);
417: } catch (IllegalArgumentException exc) {
418: exceptionCaught = true;
419: }
420: assertTrue(exceptionCaught);
421: storeMap.store();
422: storeMap.store();
423: JDBCPersistentMap loadMap = new JDBCPersistentMap(null, "Danet");
424: loadMap.setConnection(useCon);
425: loadMap.load();
426: // Verfiy that maps do match
427: assertTrue(loadMap.size() == 7);
428: // for (Iterator i = loadMap.entrySet().iterator(); i.hasNext ();) {
429: // Map.Entry e = (Map.Entry)i.next ();
430: // assertTrue ("Got: " + e.getValue() + " != Put: "
431: // + storeMap.get (e.getKey()),
432: // e.getValue ().equals (storeMap.get (e.getKey())));
433: // }
434: assertTrue(storeMap.equals(loadMap));
435: }
436:
437: /**
438: * Test modifying and removing map values. If (exactly) one
439: * connection supports batch commands, test for both connections.
440: * @exception Exception if an error occurs
441: */
442: public void modifyAndRemove() throws Exception {
443: modifyAndRemoveCon(con);
444: if (testBatchSupport) {
445: modifyAndRemoveCon(secondCon);
446: }
447: }
448:
449: /**
450: * Test modifying and removing map values.
451: * @param usecon connection to be used
452: * @exception Exception if an error occurs
453: */
454: private void modifyAndRemoveCon(Connection useCon) throws Exception {
455: JDBCPersistentMap storeMap = new JDBCPersistentMap(null,
456: "Danet");
457: storeMap.setConnection(useCon);
458: storeMap.load();
459: assertTrue(!storeMap.isModified());
460: storeMap.remove("HSc");
461: assertTrue(storeMap.isModified());
462: storeMap.remove("MSc");
463: storeMap.remove("RSc");
464: storeMap.put("ML", "Dr. Michael Lipp");
465: storeMap.put("ROt", "Ralf Ott");
466: storeMap.put("HDO", null);
467: storeMap.put("ALM", "Alex Müller");
468: storeMap.put("MSc", "Matthias Schirm");
469: storeMap.put("ALM", "Alexander Müller");
470: StringBuffer sb = new StringBuffer();
471: for (int i = 0; i < 1600; i++) {
472: sb.append("0123456789");
473: }
474: String longString = sb.toString();
475: storeMap.put("GB", longString);
476: storeMap.put("HSc", "Holger Schlueter");
477: storeMap.put("NULL", "NULL");
478: storeMap.remove("HDO");
479: storeMap.remove("HDO");
480: storeMap.put("LONG", "Gunnar von der Beck");
481: storeMap.remove("INT");
482: storeMap.remove("INT");
483: storeMap.remove("ROt");
484: storeMap.store();
485: storeMap.store();
486: JDBCPersistentMap loadMap = new JDBCPersistentMap(null, "Danet");
487: loadMap.setConnection(useCon);
488: loadMap.load();
489: // Verfiy that maps do match
490: assertTrue(loadMap.size() == 7);
491: assertTrue(storeMap.equals(loadMap));
492: }
493:
494: /**
495: * Test setting the loadStatement
496: * @exception Exception if an error occurs
497: */
498: public void loadStatement() throws Exception {
499: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet");
500: map.setConnection(con);
501: String oldStatement = map.getLoadStatement();
502: map.setLoadStatement("ILLEGAL STATEMENT");
503: String newStatement = map.getLoadStatement();
504: // Verfiy that new statement ist used
505: assertTrue(newStatement.equals("ILLEGAL STATEMENT"));
506: boolean exceptionCaught = false;
507: try {
508: map.load();
509: } catch (IOException exc) {
510: exceptionCaught = true;
511: }
512: assertTrue(exceptionCaught);
513: }
514:
515: /**
516: * Test setting the insertStatement
517: * @exception Exception if an error occurs
518: */
519: public void insertStatement() throws Exception {
520: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet");
521: map.setConnection(con);
522: map.load();
523: String oldStatement = map.getInsertStatement();
524: map.setInsertStatement("ILLEGAL STATEMENT");
525: String newStatement = map.getInsertStatement();
526: assertTrue(newStatement.equals("ILLEGAL STATEMENT"));
527: // Verify that nothing is done (optimizing)
528: map.put("HSc", "Holger Schlueter"); // Already existing -> modify
529: map.store();
530: // Verfiy that new statement ist used
531: map.put("HDO", "Dr. O.");
532: boolean exceptionCaught = false;
533: try {
534: map.store();
535: } catch (IOException exc) {
536: exceptionCaught = true;
537: }
538: assertTrue(exceptionCaught);
539: map.setInsertStatement(oldStatement);
540: map.store();
541: }
542:
543: /**
544: * Test setting the updateStatement
545: * @exception Exception if an error occurs
546: */
547: public void updateStatement() throws Exception {
548: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet");
549: map.setConnection(con);
550: map.load();
551: String oldStatement = map.getUpdateStatement();
552: map
553: .setUpdateStatement("ILLEGAL STATEMENT WHERE MAPID = ? AND ITEM = ?");
554: String newStatement = map.getUpdateStatement();
555: assertTrue(newStatement
556: .equals("ILLEGAL STATEMENT WHERE MAPID = ? AND ITEM = ?"));
557: // Verify that nothing is done (optimizing)
558: map.put("HsC", "Holger Schlueter"); // New key -> insert
559: map.store();
560: // Verfiy that new statement ist used
561: map.put("HSc", "Holger Schlüter");
562: boolean exceptionCaught = false;
563: try {
564: map.store();
565: } catch (IOException exc) {
566: exceptionCaught = true;
567: }
568: assertTrue(exceptionCaught);
569: map.setUpdateStatement(oldStatement);
570: map.store();
571: }
572:
573: /**
574: * Test setting the deleteStatement
575: * @exception Exception if an error occurs
576: */
577: public void deleteStatement() throws Exception {
578: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet");
579: map.setConnection(con);
580: map.load();
581: String oldStatement = map.getDeleteStatement();
582: map.setDeleteStatement("ILLEGAL STATEMENT");
583: String newStatement = map.getDeleteStatement();
584: assertTrue(newStatement.equals("ILLEGAL STATEMENT"));
585: // Verify that nothing is done (optimizing)
586: map.remove("HSC"); // Not existing
587: map.store();
588: // Verfiy that new statement ist used
589: map.remove("ALM");
590: boolean exceptionCaught = false;
591: try {
592: map.store();
593: } catch (IOException exc) {
594: exceptionCaught = true;
595: }
596: assertTrue(exceptionCaught);
597: map.setDeleteStatement(oldStatement);
598: map.store();
599: }
600:
601: /**
602: * Copying a map
603: * @exception Exception if an error occurs
604: */
605: public void copyMap() throws Exception {
606: JDBCPersistentMap map1 = new JDBCPersistentMap(null, "Danet");
607: map1.setConnection(con);
608: assertTrue(map1.size() == 0);
609: map1.load();
610: assertTrue(map1.size() == 8);
611: JDBCPersistentMap map2 = new JDBCPersistentMap(null, "Danet2");
612: map2.setConnection(con);
613: assertTrue(map2.size() == 0);
614: map2.putAll(map1);
615: assertTrue(map2.size() == 8);
616: map2.store();
617: JDBCPersistentMap map3 = new JDBCPersistentMap(null, "Danet2");
618: map3.setConnection(con);
619: assertTrue(map3.size() == 0);
620: map3.load();
621: assertTrue(map3.size() == 8);
622: map2.clear();
623: map2.store();
624: map3.load();
625: assertTrue(map3.size() == 0);
626: }
627:
628: /**
629: * Cleaning the table
630: * @exception Exception if an error occurs
631: */
632: public void cleanTable() throws Exception {
633: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet",
634: "DefaultPersistenceMap");
635: map.setConnection(con);
636: map.store(); // Clear DB table
637: map.put("HSc", "Holger Schlüter");
638: map.put("MSc", "Matthias Schirm");
639: map.put("ML", "Dr. Michael Lipp");
640: map.put("GB", "Gunnar von de Beck");
641: map.put("INT", new Integer(1307));
642: map.put("NULL", null);
643: assertTrue(map.size() == 6);
644: map.load(); // Load empty map
645: assertTrue(map.size() == 0);
646: map.put("HSc", "Holger Schlüter");
647: map.put("MSc", "Matthias Schirm");
648: map.put("ML", "Dr. Michael Lipp");
649: map.put("GB", "Gunnar von de Beck");
650: map.put("INT", new Integer(1307));
651: map.put("NULL", null);
652: map.store();
653: map.load();
654: assertTrue(map.size() == 6);
655: map.clear(); // Clear the map
656: assertTrue(map.size() == 0);
657: map.store();
658: map.load();
659: assertTrue(map.size() == 0);
660: }
661:
662: /**
663: * Testing serialization
664: * @exception Exception if an error occurs
665: */
666: public void serialize() throws Exception {
667: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet",
668: "DefaultPersistenceMap");
669: map.setConnection(con);
670: map.put("HSc", "Holger Schlüter");
671: map.put("ML", "Dr. Michael Lipp");
672: map.put("GB", "Gunnar von de Beck");
673: ByteArrayOutputStream bo = new ByteArrayOutputStream();
674: ObjectOutputStream o = new ObjectOutputStream(bo);
675: o.writeObject(map);
676: o.close();
677: map.remove("HSc");
678: map.store();
679: map.load();
680: assertTrue(map.size() == 2); // Two entries stored in DB
681: ByteArrayInputStream bi = new ByteArrayInputStream(bo
682: .toByteArray());
683: ObjectInputStream i = new ObjectInputStream(bi);
684: map = (JDBCPersistentMap) i.readObject(); // Three object read
685: assertTrue(map.size() == 3);
686: i.close();
687: map.setConnection(con);
688: map.store(); // Three objects stored
689: map.clear();
690: assertTrue(map.size() == 0);
691: map.load(); // All three objects read
692: assertTrue(map.size() == 3);
693: }
694:
695: /**
696: * Testing null and "" distinction.
697: * @exception Exception if an error occurs
698: */
699: public void nullString() throws Exception {
700: JDBCPersistentMap map = new JDBCPersistentMap(null, "Danet",
701: "DefaultPersistenceMap");
702: map.setConnection(con);
703: map.put("nullString", null);
704: map.put("emptyString", "");
705: map.store();
706: map.load();
707: assertTrue(map.get("nullString") == null);
708: assertTrue(map.get("emptyString").equals(""));
709: }
710: }
|