View Javadoc
1   package org.melati.poem.test;
2   
3   import java.math.BigDecimal;
4   import java.sql.Timestamp;
5   import java.util.Date;
6   import java.util.Enumeration;
7   
8   import org.melati.poem.ColumnInfo;
9   import org.melati.poem.ColumnRenamePoemException;
10  import org.melati.poem.DisplayLevel;
11  import org.melati.poem.DuplicateColumnNamePoemException;
12  import org.melati.poem.DuplicateDeletedColumnPoemException;
13  import org.melati.poem.DuplicateTableNamePoemException;
14  import org.melati.poem.DuplicateTroidColumnPoemException;
15  import org.melati.poem.IntegrityFix;
16  import org.melati.poem.Persistent;
17  import org.melati.poem.PoemDatabaseFactory;
18  import org.melati.poem.PoemThread;
19  import org.melati.poem.PoemTypeFactory;
20  import org.melati.poem.ReadPersistentAccessPoemException;
21  import org.melati.poem.RowDisappearedPoemException;
22  import org.melati.poem.Searchability;
23  import org.melati.poem.StandardIntegrityFix;
24  import org.melati.poem.Table;
25  import org.melati.poem.TableInfo;
26  import org.melati.poem.UnificationPoemException;
27  import org.melati.poem.util.EnumUtils;
28  
29  /**
30   * Test the addition, and later the deletion, of columns to a table.
31   * 
32   * FIXME add deletion testing 
33   * 
34   * @author timp
35   * @since 01-Februray-2007
36   */
37  public class DynamicTableTest extends EverythingTestCase {
38    /**
39     * Constructor for PoemTest.
40     * 
41     * @param arg0
42     */
43    public DynamicTableTest(String arg0) {
44      super(arg0);
45    }
46  
47    protected void setUp() throws Exception {
48      super.setUp();
49    }
50  
51    protected void tearDown() throws Exception {
52      // Do not do super or we will create a db again
53      // super.tearDown();
54      if (getDb().getDbms().canDropColumns()) {
55        checkDbUnchanged();
56      }
57    }
58  
59    protected void databaseUnchanged() {
60      // It is not good enough to drop the new columns, as the deleted
61      // columnInfo's
62      // are still referred to, so drop the whole table
63      PoemThread.commit();
64      dropTable("addedtable");
65      dropTable("addedtable2");
66      dropTable("addedtable3");
67      dropTable("dynamic");
68      dropTable("tableinfo");
69      dropTable("columninfo");
70      dropTable("tablecategory");
71      PoemDatabaseFactory.removeDatabase(databaseName);
72    }
73  
74    /**
75     * Test the addition of a table.
76     */
77    public void testAddTableAndCommit() throws Exception {
78      if (!getDb().getDbms().canDropColumns()) {
79        return;
80      }
81      TableInfo info = (TableInfo)getDb().getTableInfoTable().newPersistent();
82      info.setName("addedtable");
83      info.setDisplayname("Junit created table");
84      info.setDisplayorder(13);
85      info.setSeqcached(new Boolean(false));
86      info.setCategory_unsafe(new Integer(1));
87      info.setCachelimit(0);
88      info.makePersistent();
89      Table<?> extra = getDb().addTableAndCommit(info, "id");
90      ColumnInfo ci = (ColumnInfo)getDb().getColumnInfoTable().newPersistent();
91      ci.setTableinfo(info);
92      ci.setTypefactory(PoemTypeFactory.STRING);
93      ci.setNullable(false);
94      ci.setSize(-1);
95      ci.setWidth(20);
96      ci.setHeight(1);
97      ci.setPrecision(1);
98      ci.setScale(1);
99      ci.setName("extra");
100     ci.setDescription("Description of extra column");
101     ci.setDisplayname("Extra");
102     ci.setDisplayorder(10);
103     ci.setIndexed(true);
104     ci.setUnique(true);
105     ci.setSearchability(Searchability.yes);
106     ci.setDisplaylevel(DisplayLevel.primary);
107     ci.setUsereditable(true);
108     ci.setUsercreateable(true);
109 
110     ci.makePersistent();
111     try {
112       extra.addColumnAndCommit(ci);
113       fail("Should have bombed");
114     } catch (UnificationPoemException e) { 
115       e = null;
116     }
117     ci.setIndexed(false);
118     ci.setUnique(false);
119     extra.addColumnAndCommit(ci);
120 
121     Persistent extraPersistent = extra.newPersistent();
122     PoemThread.commit();
123     assertNull(extraPersistent.getTroid());
124     extraPersistent.setCooked("extra", "Test");
125     extraPersistent.makePersistent();
126     assertEquals("Test", extraPersistent.getField("extra").getRaw());
127 
128     extra.getTableInfo().setDefaultcanread(getDb().administerCapability());
129     extraPersistent.getField("extra").getRaw();
130 
131     assertEquals(new Integer(0), extraPersistent.getTroid());
132     Enumeration<Persistent> cols = getDb().getColumnInfoTable().getTableinfoColumn()
133             .selectionWhereEq(info.getTroid());
134     int colCount = 0;
135     while (cols.hasMoreElements()) {
136       ColumnInfo c = (ColumnInfo)cols.nextElement();
137       c.delete();
138       colCount++;
139     }
140     assertEquals(2, colCount);
141 
142     PoemThread.commit();
143     dropTable("addedtable");
144 
145     try {
146       getDb().addTableAndCommit(info, "id");
147       fail("Should have blown up");
148     } catch (DuplicateTableNamePoemException e) {
149       e = null;
150     }
151     cols = getDb().getColumnInfoTable().getTableinfoColumn().selectionWhereEq(
152             info.getTroid());
153     colCount = 0;
154     while (cols.hasMoreElements()) {
155       ColumnInfo c = (ColumnInfo)cols.nextElement();
156       c.delete();
157       colCount++;
158     }
159     assertEquals(1, colCount);
160 
161     info.delete();
162     PoemThread.commit();
163     try {
164       getDb().addTableAndCommit(info, "id");
165       fail("Should have blown up");
166     } catch (RowDisappearedPoemException e) {
167       e = null;
168     }
169     dropTable("addedtable");
170 
171     TableInfo info3 = (TableInfo)getDb().getTableInfoTable().newPersistent();
172     info3.setName("addedtable2");
173     info3.setDisplayname("Junit created table");
174     info3.setDisplayorder(13);
175     info3.setSeqcached(new Boolean(false));
176     info3.setCategory_unsafe(new Integer(1));
177     info3.setCachelimit(0);
178     info3.makePersistent();
179     PoemThread.commit();
180     getDb().addTableAndCommit(info3, "id");
181     cols = getDb().getColumnInfoTable().getTableinfoColumn().selectionWhereEq(
182             info3.getTroid());
183     int count = 0;
184     while (cols.hasMoreElements()) {
185       ColumnInfo c = (ColumnInfo)cols.nextElement();
186       c.delete();
187     }
188     assertEquals(0, count);
189     info3.deleteAndCommit();
190     PoemThread.commit();
191   }
192 
193   /**
194    * Test that an added, 'extra', column can be represented as a field.
195    */
196   public void testExtraColumnAsField() {
197     if (!getDb().getDbms().canDropColumns()) {
198       return;
199     }
200     TableInfo ti = (TableInfo)getDb().getTableInfoTable().newPersistent();
201     ti.setName("addedtable3");
202     ti.setDisplayname("Junit created table");
203     ti.setDisplayorder(13);
204     ti.setSeqcached(new Boolean(false));
205     ti.setCategory_unsafe(new Integer(1));
206     ti.setCachelimit(0);
207     ti.makePersistent();
208     // PoemThread.commit();
209     Table<?> extra = getDb().addTableAndCommit(ti, "id");
210 
211     ColumnInfo ci = (ColumnInfo)getDb().getColumnInfoTable().newPersistent();
212     ci.setTableinfo(ti);
213     ci.setTypefactory(PoemTypeFactory.STRING);
214     ci.setNullable(false);
215     ci.setSize(-1);
216     ci.setWidth(20);
217     ci.setHeight(1);
218     ci.setPrecision(1);
219     ci.setScale(1);
220     ci.setName("extra");
221     ci.setDescription("Description of extra column");
222     ci.setDisplayname("Extra");
223     ci.setDisplayorder(10);
224     ci.setIndexed(true);
225     ci.setUnique(true);
226     ci.setSearchability(Searchability.yes);
227     ci.setDisplaylevel(DisplayLevel.primary);
228     ci.setUsereditable(true);
229     ci.setUsercreateable(true);
230 
231     ci.makePersistent();
232 
233     try {
234       extra.addColumnAndCommit(ci);
235       fail("Should have bombed");
236     } catch (UnificationPoemException e) { 
237       e = null;
238     }
239     ci.setIndexed(false);
240     ci.setUnique(false);
241     extra.addColumnAndCommit(ci);
242     
243     Persistent extraInstance = extra.newPersistent();
244     PoemThread.commit();
245     assertNull(extraInstance.getTroid());
246     extraInstance.setCooked("extra", "Test");
247     extraInstance.makePersistent();
248     assertEquals("Test", extraInstance.getField("extra").getRaw());
249 
250     // Show that guest cannot read
251     extra.getTableInfo().setDefaultcanread(getDb().administerCapability());
252     PoemThread.setAccessToken(getDb().guestAccessToken());
253     try {
254       extraInstance.getField("extra").getRaw();
255       fail("Should have bombed");
256     } catch (ReadPersistentAccessPoemException e) {
257       e = null;
258     }
259     // Do not tidy up here
260     // as we no longer have write priviledges.
261     // see our overidden version of databaseUnchanged()
262     // ci.delete();
263     // extra.troidColumn().getColumnInfo().delete();
264     // ti.delete();
265     // PoemThread.commit();
266   }
267 
268   /**
269    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
270    */
271   public void testAddColumnAndCommitTroid() {
272     if (!getDb().getDbms().canDropColumns()) {
273       return;
274     }
275     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
276     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
277             .newPersistent();
278     TableInfo ti = dt.getTableInfo();
279     columnInfo.setTableinfo(ti);
280     columnInfo.setName("testtroidcol");
281     columnInfo.setDisplayname("Test Troid Column");
282     columnInfo.setDisplayorder(99);
283     columnInfo.setSearchability(Searchability.yes);
284     columnInfo.setIndexed(false);
285     columnInfo.setUnique(false);
286     columnInfo.setDescription("A non-nullable extra Troid column");
287     columnInfo.setUsercreateable(true);
288     columnInfo.setUsereditable(true);
289     columnInfo.setTypefactory(PoemTypeFactory.TROID);
290     columnInfo.setSize(-1);
291     columnInfo.setWidth(20);
292     columnInfo.setHeight(1);
293     columnInfo.setPrecision(0);
294     columnInfo.setScale(0);
295     columnInfo.setNullable(false);
296     columnInfo.setDisplaylevel(DisplayLevel.detail);
297     columnInfo.makePersistent();
298     PoemThread.commit();
299     try {
300       columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
301       fail("Should have blown up");
302     } catch (DuplicateTroidColumnPoemException e) {
303       e = null;
304     }
305     try {
306       columnInfo.delete();
307     } catch (RuntimeException e) {
308       PoemThread.commit();
309       throw e;
310     }
311   }
312 
313   /**
314    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
315    */
316   public void testAddColumnAndCommitDeleted() throws Exception {
317     if (!getDb().getDbms().canDropColumns()) {
318       return;
319     }
320     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
321     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
322             .newPersistent();
323     TableInfo ti = dt.getTableInfo();
324     columnInfo.setTableinfo(ti);
325     columnInfo.setName("testdeletedcol");
326     columnInfo.setDisplayname("Test Deleted Column");
327     columnInfo.setDisplayorder(99);
328     columnInfo.setSearchability(Searchability.yes);
329     columnInfo.setIndexed(false);
330     columnInfo.setUnique(false);
331     columnInfo.setDescription("A non-nullable extra Deleted column");
332     columnInfo.setUsercreateable(true);
333     columnInfo.setUsereditable(true);
334     columnInfo.setTypefactory(PoemTypeFactory.DELETED);
335     columnInfo.setSize(-1);
336     columnInfo.setWidth(20);
337     columnInfo.setHeight(1);
338     columnInfo.setPrecision(0);
339     columnInfo.setScale(0);
340     columnInfo.setNullable(false);
341     columnInfo.setDisplaylevel(DisplayLevel.record);
342     columnInfo.makePersistent();
343     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
344     assertEquals(2, EnumUtils.vectorOf(
345             dt.getColumn("testdeletedcol").selectionWhereEq(Boolean.FALSE))
346             .size());
347     PoemThread.commit();
348     assertEquals(2, EnumUtils.vectorOf(
349             dt.getColumn("testdeletedcol").selectionWhereEq(Boolean.FALSE))
350             .size());
351     assertEquals(Boolean.FALSE, dt.two().getRaw("testdeletedcol"));
352     assertEquals(Boolean.FALSE, dt.two().getCooked("testdeletedcol"));
353     assertEquals(Boolean.FALSE, dt.getObject(0).getCooked("testdeletedcol"));
354     try {
355       columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
356       fail("Should have blown up");
357     } catch (DuplicateColumnNamePoemException e) {
358       assertEquals("Can't add duplicate column Dynamic.testdeletedcol: "
359               + "deleted (BOOLEAN (org.melati.poem.DeletedPoemType)) "
360               + "(from the running application) to Dynamic "
361               + "(from the data structure definition)", e.getMessage());
362       e = null;
363     }
364     try {
365       columnInfo.setName("testdeletedcol2");
366       fail("Should have blown up");
367     } catch (ColumnRenamePoemException e) {
368       e = null;
369     }
370     ColumnInfo columnInfo2 = (ColumnInfo)getDb().getColumnInfoTable()
371             .newPersistent();
372     columnInfo2.setTableinfo(ti);
373     columnInfo2.setName("testdeletedcol2");
374     columnInfo2.setDisplayname("Test duplicate Deleted Column");
375     columnInfo2.setDisplayorder(99);
376     columnInfo2.setSearchability(Searchability.yes);
377     columnInfo2.setIndexed(false);
378     columnInfo2.setUnique(false);
379     columnInfo2.setDescription("A non-nullable extra Deleted column");
380     columnInfo2.setUsercreateable(true);
381     columnInfo2.setUsereditable(true);
382     columnInfo2.setTypefactory(PoemTypeFactory.DELETED);
383     columnInfo2.setSize(-1);
384     columnInfo2.setWidth(20);
385     columnInfo2.setHeight(1);
386     columnInfo2.setPrecision(0);
387     columnInfo2.setScale(0);
388     columnInfo2.setNullable(false);
389     columnInfo2.setDisplaylevel(DisplayLevel.summary);
390     columnInfo2.makePersistent();
391     try {
392       columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo2);
393       fail("Should have blown up");
394     } catch (DuplicateDeletedColumnPoemException e) {
395       assertEquals("Can't add testdeletedcol2 to Dynamic as a deleted column, "
396               + "because it already has one, "
397               + "i.e. Dynamic.testdeletedcol: deleted "
398               + "(BOOLEAN (org.melati.poem.DeletedPoemType)) "
399               + "(from the running application)", e.getMessage());
400       e = null;
401     }
402     // String query = "ALTER TABLE " + getDb().getUserTable().quotedName() +
403     // " DROP COLUMN " + getDb().quotedName(columnInfo.getName());
404     // getDb().sqlUpdate(query);
405     // columnInfo.delete();
406     // getDb().getUserTable()
407     // columnInfo2.delete();
408     // getDb().uncacheContents();
409     // getDb().unifyWithDB();
410     PoemThread.commit();
411   }
412 
413   /**
414    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
415    */
416   public void testAddColumnAndCommitType() {
417     if (!getDb().getDbms().canDropColumns()) {
418       return;
419     }
420     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
421     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
422             .newPersistent();
423     TableInfo ti = dt.getTableInfo();
424     columnInfo.setTableinfo(ti);
425     columnInfo.setName("testtypecol");
426     columnInfo.setDisplayname("Test Type Column");
427     columnInfo.setDisplayorder(99);
428     columnInfo.setSearchability(Searchability.yes);
429     columnInfo.setIndexed(false);
430     columnInfo.setUnique(false);
431     columnInfo.setDescription("A non-nullable extra Type column");
432     columnInfo.setUsercreateable(true);
433     columnInfo.setUsereditable(true);
434     columnInfo.setTypefactory(PoemTypeFactory.TYPE);
435     columnInfo.setSize(-1);
436     columnInfo.setWidth(20);
437     columnInfo.setHeight(1);
438     columnInfo.setPrecision(0);
439     columnInfo.setScale(0);
440     columnInfo.setNullable(false);
441     columnInfo.setDisplaylevel(DisplayLevel.record);
442     columnInfo.makePersistent();
443     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
444     Integer t = null;
445     Enumeration<Dynamic> en = dt.selection();
446     Dynamic d = (Dynamic)en.nextElement();
447     t = (Integer)d.getRaw("testtypecol");
448     int count = 0;
449     while (en.hasMoreElements()) {
450       d = (Dynamic)en.nextElement();
451       if (d.statusExistent()) {
452         assertEquals(t, d.getRaw("testtypecol"));
453         count++;
454       }
455     }
456     assertEquals(1, count);
457 
458     PoemTypeFactory t2 = null;
459     Enumeration<Dynamic> en2 = dt.selection();
460     t2 = (PoemTypeFactory)((Dynamic)en2.nextElement()).getCooked("testtypecol");
461     while (en2.hasMoreElements()) {
462       assertEquals(t2.getName(), ((PoemTypeFactory)((Dynamic)en2.nextElement())
463               .getCooked("testtypecol")).getName());
464     }
465 
466     assertEquals(2, EnumUtils.vectorOf(
467             dt.getColumn("testtypecol").selectionWhereEq(new Integer(0)))
468             .size());
469     PoemThread.commit();
470     assertEquals(2, EnumUtils.vectorOf(
471             dt.getColumn("testtypecol").selectionWhereEq(new Integer(0)))
472             .size());
473     assertEquals(new Integer(0), dt.two().getRaw("testtypecol"));
474     assertEquals("User", ((PoemTypeFactory)dt.two().getCooked("testtypecol"))
475             .getName());
476     assertEquals("User", ((PoemTypeFactory)dt.getObject(0).getCooked(
477             "testtypecol")).getName());
478     columnInfo.delete();
479   }
480 
481   /**
482    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
483    */
484   public void testAddColumnAndCommitBoolean() {
485     if (!getDb().getDbms().canDropColumns()) {
486       return;
487     }
488     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
489     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
490             .newPersistent();
491     TableInfo ti = dt.getTableInfo();
492     columnInfo.setTableinfo(ti);
493     columnInfo.setName("testbooleancol");
494     columnInfo.setDisplayname("Test Boolean Column");
495     columnInfo.setDisplayorder(99);
496     columnInfo.setSearchability(Searchability.yes);
497     columnInfo.setIndexed(false);
498     columnInfo.setUnique(false);
499     columnInfo.setDescription("A non-nullable extra Boolean column");
500     columnInfo.setUsercreateable(true);
501     columnInfo.setUsereditable(true);
502     columnInfo.setTypefactory(PoemTypeFactory.BOOLEAN);
503     columnInfo.setSize(-1);
504     columnInfo.setWidth(20);
505     columnInfo.setHeight(1);
506     columnInfo.setPrecision(0);
507     columnInfo.setScale(0);
508     columnInfo.setNullable(false);
509     columnInfo.setDisplaylevel(DisplayLevel.record);
510     columnInfo.makePersistent();
511     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
512     assertEquals(2, EnumUtils.vectorOf(
513             dt.getColumn("testbooleancol").selectionWhereEq(Boolean.FALSE))
514             .size());
515     PoemThread.commit();
516     assertEquals(2, EnumUtils.vectorOf(
517             dt.getColumn("testbooleancol").selectionWhereEq(Boolean.FALSE))
518             .size());
519     assertEquals(Boolean.FALSE, dt.two().getRaw("testbooleancol"));
520     assertEquals(Boolean.FALSE, dt.two().getCooked("testbooleancol"));
521     assertEquals(Boolean.FALSE, dt.getObject(0).getCooked("testbooleancol"));
522     columnInfo.delete();
523   }
524 
525   /**
526    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
527    */
528   public void testAddColumnAndCommitInteger() {
529     if (!getDb().getDbms().canDropColumns()) {
530       return;
531     }
532     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
533     // Two records are created on initialisation
534     assertEquals(2, EnumUtils.vectorOf(dt.selection()).size());
535     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
536             .newPersistent();
537     TableInfo ti = dt.getTableInfo();
538     columnInfo.setTableinfo(ti);
539     columnInfo.setName("testintegercol");
540     columnInfo.setDisplayname("Test Integer Column");
541     columnInfo.setDisplayorder(199);
542     columnInfo.setSearchability(Searchability.yes);
543     columnInfo.setIndexed(false);
544     columnInfo.setUnique(false);
545     columnInfo.setDescription("A non-nullable extra Integer column");
546     columnInfo.setUsercreateable(true);
547     columnInfo.setUsereditable(true);
548     columnInfo.setTypefactory(PoemTypeFactory.INTEGER);
549     columnInfo.setSize(8);
550     columnInfo.setWidth(20);
551     columnInfo.setHeight(1);
552     columnInfo.setPrecision(0);
553     columnInfo.setScale(0);
554     columnInfo.setNullable(false);
555     columnInfo.setDisplaylevel(DisplayLevel.record);
556     columnInfo.makePersistent();
557     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
558     assertEquals(2, EnumUtils.vectorOf(
559             dt.getColumn("testintegercol").selectionWhereEq(new Integer(0)))
560             .size());
561     PoemThread.commit();
562     assertEquals(2, EnumUtils.vectorOf(
563             dt.getColumn("testintegercol").selectionWhereEq(new Integer(0)))
564             .size());
565     assertEquals(new Integer(0), dt.two().getRaw("testintegercol"));
566     assertEquals(new Integer(0), dt.two().getCooked("testintegercol"));
567     assertEquals(new Integer(0), dt.getObject(0).getCooked("testintegercol"));
568     columnInfo.delete();
569   }
570 
571   /**
572    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
573    */
574   public void testAddColumnAndCommitNullableInteger() {
575     if (!getDb().getDbms().canDropColumns()) {
576       return;
577     }
578     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
579     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
580             .newPersistent();
581     TableInfo ti = dt.getTableInfo();
582     columnInfo.setTableinfo(ti);
583     columnInfo.setName("testnullableintegercol");
584     columnInfo.setDisplayname("Test Nullable Integer Column");
585     columnInfo.setDisplayorder(199);
586     columnInfo.setSearchability(Searchability.yes);
587     columnInfo.setIndexed(false);
588     columnInfo.setUnique(false);
589     columnInfo.setDescription("A nullable extra Integer column");
590     columnInfo.setUsercreateable(true);
591     columnInfo.setUsereditable(true);
592     columnInfo.setTypefactory(PoemTypeFactory.INTEGER);
593     columnInfo.setSize(8);
594     columnInfo.setWidth(20);
595     columnInfo.setHeight(1);
596     columnInfo.setPrecision(0);
597     columnInfo.setScale(0);
598     columnInfo.setNullable(true);
599     columnInfo.setDisplaylevel(DisplayLevel.record);
600     columnInfo.makePersistent();
601     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
602     assertEquals(0, EnumUtils.vectorOf(
603             dt.getColumn("testnullableintegercol").selectionWhereEq(
604                     new Integer(0))).size());
605     PoemThread.commit();
606     assertEquals(0, EnumUtils.vectorOf(
607             dt.getColumn("testnullableintegercol").selectionWhereEq(
608                     new Integer(0))).size());
609     assertNull(dt.two().getRaw("testnullableintegercol"));
610     assertNull(dt.two().getCooked("testnullableintegercol"));
611     assertNull(dt.getObject(0).getCooked("testnullableintegercol"));
612     columnInfo.delete();
613   }
614 
615   /**
616    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
617    */
618   public void testAddColumnAndCommitDouble() {
619     if (!getDb().getDbms().canDropColumns()) {
620       return;
621     }
622     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
623     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
624             .newPersistent();
625     TableInfo ti = dt.getTableInfo();
626     columnInfo.setTableinfo(ti);
627     columnInfo.setName("testdoublecol");
628     columnInfo.setDisplayname("Test Double Column");
629     columnInfo.setDisplayorder(199);
630     columnInfo.setSearchability(Searchability.yes);
631     columnInfo.setIndexed(false);
632     columnInfo.setUnique(false);
633     columnInfo.setDescription("A non-nullable extra Double column");
634     columnInfo.setUsercreateable(true);
635     columnInfo.setUsereditable(true);
636     columnInfo.setTypefactory(PoemTypeFactory.DOUBLE);
637     columnInfo.setSize(8);
638     columnInfo.setWidth(20);
639     columnInfo.setHeight(1);
640     columnInfo.setPrecision(0);
641     columnInfo.setScale(0);
642     columnInfo.setNullable(false);
643     columnInfo.setDisplaylevel(DisplayLevel.record);
644     columnInfo.makePersistent();
645     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
646     assertEquals(2, EnumUtils.vectorOf(
647             dt.getColumn("testdoublecol").selectionWhereEq(new Double(0)))
648             .size());
649     PoemThread.commit();
650     assertEquals(2, EnumUtils.vectorOf(
651             dt.getColumn("testdoublecol").selectionWhereEq(new Double(0)))
652             .size());
653     assertEquals(new Double(0), dt.two().getRaw("testdoublecol"));
654     assertEquals(new Double(0), dt.two().getCooked("testdoublecol"));
655     assertEquals(new Double(0), dt.getObject(0).getCooked("testdoublecol"));
656     columnInfo.delete();
657   }
658 
659   /**
660    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
661    */
662   public void testAddColumnAndCommitLong() {
663     if (!getDb().getDbms().canDropColumns()) {
664       return;
665     }
666     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
667     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
668             .newPersistent();
669     TableInfo ti = dt.getTableInfo();
670     columnInfo.setTableinfo(ti);
671     columnInfo.setName("testlongcol");
672     columnInfo.setDisplayname("Test Long Column");
673     columnInfo.setDisplayorder(199);
674     columnInfo.setSearchability(Searchability.yes);
675     columnInfo.setIndexed(false);
676     columnInfo.setUnique(false);
677     columnInfo.setDescription("A non-nullable extra Long column");
678     columnInfo.setUsercreateable(true);
679     columnInfo.setUsereditable(true);
680     columnInfo.setTypefactory(PoemTypeFactory.LONG);
681     columnInfo.setSize(8);
682     columnInfo.setWidth(20);
683     columnInfo.setHeight(1);
684     columnInfo.setPrecision(0);
685     columnInfo.setScale(0);
686     columnInfo.setNullable(false);
687     columnInfo.setDisplaylevel(DisplayLevel.record);
688     columnInfo.makePersistent();
689     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
690     assertEquals(2, EnumUtils.vectorOf(
691             dt.getColumn("testlongcol").selectionWhereEq(new Long(0))).size());
692     PoemThread.commit();
693     assertEquals(2, EnumUtils.vectorOf(
694             dt.getColumn("testlongcol").selectionWhereEq(new Long(0))).size());
695     assertEquals(new Long(0), dt.two().getRaw("testlongcol"));
696     assertEquals(new Long(0), dt.two().getCooked("testlongcol"));
697     assertEquals(new Long(0), dt.getObject(0).getCooked("testlongcol"));
698     columnInfo.delete();
699   }
700 
701   /**
702    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
703    */
704   public void testAddColumnAndCommitBigDecimal() {
705     if (!getDb().getDbms().canDropColumns()) {
706       return;
707     }
708     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
709     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
710             .newPersistent();
711     TableInfo ti = dt.getTableInfo();
712     columnInfo.setTableinfo(ti);
713     columnInfo.setName("testbigdecimalcol");
714     columnInfo.setDisplayname("Test Big Decimal Column");
715     columnInfo.setDisplayorder(199);
716     columnInfo.setSearchability(Searchability.yes);
717     columnInfo.setIndexed(false);
718     columnInfo.setUnique(false);
719     columnInfo.setDescription("A non-nullable extra Big Decimal column");
720     columnInfo.setUsercreateable(true);
721     columnInfo.setUsereditable(true);
722     columnInfo.setTypefactory(PoemTypeFactory.BIGDECIMAL);
723     columnInfo.setSize(8);
724     columnInfo.setWidth(20);
725     columnInfo.setHeight(1);
726     columnInfo.setPrecision(0);
727     columnInfo.setScale(0);
728     columnInfo.setNullable(false);
729     columnInfo.setDisplaylevel(DisplayLevel.record);
730     columnInfo.makePersistent();
731     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
732     assertEquals(2, EnumUtils.vectorOf(
733             dt.getColumn("testbigdecimalcol").selectionWhereEq(
734                     new BigDecimal(0.0))).size());
735     PoemThread.commit();
736     assertEquals(2, EnumUtils.vectorOf(
737             dt.getColumn("testbigdecimalcol").selectionWhereEq(
738                     new BigDecimal(0.0))).size());
739     columnInfo.delete();
740   }
741 
742   /**
743    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
744    */
745   public void testAddColumnAndCommitString() {
746     if (!getDb().getDbms().canDropColumns()) {
747       return;
748     }
749     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
750     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
751             .newPersistent();
752     TableInfo ti = dt.getTableInfo();
753     columnInfo.setTableinfo(ti);
754     columnInfo.setName("teststringcol");
755     columnInfo.setDisplayname("Test String Column");
756     columnInfo.setDisplayorder(99);
757     columnInfo.setSearchability(Searchability.yes);
758     columnInfo.setIndexed(false);
759     columnInfo.setUnique(false);
760     columnInfo.setDescription("A non-nullable extra String column");
761     columnInfo.setUsercreateable(true);
762     columnInfo.setUsereditable(true);
763     columnInfo.setTypefactory(PoemTypeFactory.STRING);
764     columnInfo.setSize(-1);
765     columnInfo.setWidth(20);
766     columnInfo.setHeight(1);
767     columnInfo.setPrecision(0);
768     columnInfo.setScale(0);
769     columnInfo.setNullable(false);
770     columnInfo.setDisplaylevel(DisplayLevel.record);
771     columnInfo.makePersistent();
772     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
773     assertEquals(2, EnumUtils.vectorOf(
774             dt.getColumn("teststringcol").selectionWhereEq("default")).size());
775     PoemThread.commit();
776     assertEquals(2, EnumUtils.vectorOf(
777             dt.getColumn("teststringcol").selectionWhereEq("default")).size());
778     assertEquals("default", dt.two().getRaw("teststringcol"));
779     assertEquals("default", dt.two().getCooked("teststringcol"));
780     assertEquals("default", dt.getObject(0).getCooked("teststringcol"));
781     columnInfo.delete();
782   }
783 
784   /**
785    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
786    */
787   public void testAddColumnAndCommitPassword() {
788     if (!getDb().getDbms().canDropColumns()) {
789       return;
790     }
791     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
792     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
793             .newPersistent();
794     TableInfo ti = dt.getTableInfo();
795     columnInfo.setTableinfo(ti);
796     columnInfo.setName("testpasswordcol");
797     columnInfo.setDisplayname("Test Password Column");
798     columnInfo.setDisplayorder(99);
799     columnInfo.setSearchability(Searchability.yes);
800     columnInfo.setIndexed(false);
801     columnInfo.setUnique(false);
802     columnInfo.setDescription("A non-nullable extra Password column");
803     columnInfo.setUsercreateable(true);
804     columnInfo.setUsereditable(true);
805     columnInfo.setTypefactory(PoemTypeFactory.PASSWORD);
806     columnInfo.setSize(-1);
807     columnInfo.setWidth(20);
808     columnInfo.setHeight(1);
809     columnInfo.setPrecision(0);
810     columnInfo.setScale(0);
811     columnInfo.setNullable(false);
812     columnInfo.setDisplaylevel(DisplayLevel.record);
813     columnInfo.makePersistent();
814     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
815     assertEquals(2, EnumUtils.vectorOf(
816             dt.getColumn("testpasswordcol").selectionWhereEq("FIXME")).size());
817     PoemThread.commit();
818     assertEquals(2, EnumUtils.vectorOf(
819             dt.getColumn("testpasswordcol").selectionWhereEq("FIXME")).size());
820     assertEquals("FIXME", dt.two().getRaw("testpasswordcol"));
821     assertEquals("FIXME", dt.two().getCooked("testpasswordcol"));
822     assertEquals("FIXME", dt.getObject(0).getCooked("testpasswordcol"));
823     columnInfo.delete();
824   }
825 
826   /**
827    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
828    */
829   public void testAddColumnAndCommitDate() {
830     if (!getDb().getDbms().canDropColumns()) {
831       return;
832     }
833     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
834     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
835             .newPersistent();
836     TableInfo ti = dt.getTableInfo();
837     columnInfo.setTableinfo(ti);
838     columnInfo.setName("testdatecol");
839     columnInfo.setDisplayname("Test Date Column");
840     columnInfo.setDisplayorder(199);
841     columnInfo.setSearchability(Searchability.yes);
842     columnInfo.setIndexed(false);
843     columnInfo.setUnique(false);
844     columnInfo.setDescription("A non-nullable extra Date column");
845     columnInfo.setUsercreateable(true);
846     columnInfo.setUsereditable(true);
847     columnInfo.setTypefactory(PoemTypeFactory.DATE);
848     columnInfo.setSize(8);
849     columnInfo.setWidth(20);
850     columnInfo.setHeight(1);
851     columnInfo.setPrecision(0);
852     columnInfo.setScale(0);
853     columnInfo.setNullable(false);
854     columnInfo.setDisplaylevel(DisplayLevel.record);
855     columnInfo.makePersistent();
856     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
857     assertEquals(2, EnumUtils.vectorOf(
858             dt.getColumn("testdatecol").selectionWhereEq(
859                     new java.sql.Date(new Date().getTime()))).size());
860     PoemThread.commit();
861     assertEquals(2, EnumUtils.vectorOf(
862             dt.getColumn("testdatecol").selectionWhereEq(
863                     new java.sql.Date(new Date().getTime()))).size());
864     assertEquals(new java.sql.Date(new Date().getTime()).toString(), dt.two()
865             .getRaw("testdatecol").toString());
866     assertEquals(new java.sql.Date(new Date().getTime()).toString(), dt.two()
867             .getCooked("testdatecol").toString());
868     assertEquals(new java.sql.Date(new Date().getTime()).toString(), dt
869             .getObject(0).getCooked("testdatecol").toString());
870     columnInfo.delete();
871   }
872 
873   /**
874    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
875    */
876   public void testAddColumnAndCommitTimestamp() {
877     if (!getDb().getDbms().canDropColumns()) {
878       return;
879     }
880     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
881     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
882             .newPersistent();
883     TableInfo ti = dt.getTableInfo();
884     columnInfo.setTableinfo(ti);
885     columnInfo.setName("testtimestampcol");
886     columnInfo.setDisplayname("Test Timestamp Column");
887     columnInfo.setDisplayorder(199);
888     columnInfo.setSearchability(Searchability.yes);
889     columnInfo.setIndexed(false);
890     columnInfo.setUnique(false);
891     columnInfo.setDescription("A non-nullable extra Timestamp column");
892     columnInfo.setUsercreateable(true);
893     columnInfo.setUsereditable(true);
894     columnInfo.setTypefactory(PoemTypeFactory.TIMESTAMP);
895     columnInfo.setSize(8);
896     columnInfo.setWidth(20);
897     columnInfo.setHeight(1);
898     columnInfo.setPrecision(0);
899     columnInfo.setScale(0);
900     columnInfo.setNullable(false);
901     columnInfo.setDisplaylevel(DisplayLevel.record);
902     columnInfo.makePersistent();
903     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
904     Timestamp t = null;
905     Enumeration<Dynamic> en = dt.selection();
906     t = (Timestamp)((Dynamic)en.nextElement()).getRaw("testtimestampcol");
907     while (en.hasMoreElements()) {
908       assertEquals(t, ((Dynamic)en.nextElement()).getRaw("testtimestampcol"));
909     }
910     assertEquals(2, EnumUtils.vectorOf(
911             dt.getColumn("testtimestampcol").selectionWhereEq(t)).size());
912     PoemThread.commit();
913     assertEquals(2, EnumUtils.vectorOf(
914             dt.getColumn("testtimestampcol").selectionWhereEq(t)).size());
915     assertEquals(t, dt.two().getRaw("testtimestampcol"));
916     assertEquals(t, dt.two().getCooked("testtimestampcol"));
917     assertEquals(t, dt.getObject(0).getCooked("testtimestampcol"));
918     columnInfo.delete();
919   }
920 
921   /**
922    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
923    */
924   public void testAddColumnAndCommitBinary() {
925     if (!getDb().getDbms().canDropColumns()) {
926       return;
927     }
928     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
929     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
930             .newPersistent();
931     TableInfo ti = dt.getTableInfo();
932     columnInfo.setTableinfo(ti);
933     columnInfo.setName("testbinarycol");
934     columnInfo.setDisplayname("Test Binary Column");
935     columnInfo.setDisplayorder(199);
936     columnInfo.setSearchability(Searchability.yes);
937     columnInfo.setIndexed(false);
938     columnInfo.setUnique(false);
939     columnInfo.setDescription("A non-nullable extra Binary column");
940     columnInfo.setUsercreateable(true);
941     columnInfo.setUsereditable(true);
942     columnInfo.setTypefactory(PoemTypeFactory.BINARY);
943     columnInfo.setSize(8);
944     columnInfo.setWidth(20);
945     columnInfo.setHeight(1);
946     columnInfo.setPrecision(0);
947     columnInfo.setScale(0);
948     columnInfo.setNullable(false);
949     columnInfo.setDisplaylevel(DisplayLevel.record);
950     columnInfo.makePersistent();
951     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
952     byte[] t = null;
953     Enumeration<Dynamic> en = dt.selection();
954     t = (byte[])((Dynamic)en.nextElement()).getRaw("testbinarycol");
955     while (en.hasMoreElements()) {
956       assertEquals(t.length, ((byte[])((Dynamic)en.nextElement())
957               .getRaw("testbinarycol")).length);
958     }
959     assertEquals(2, EnumUtils.vectorOf(
960             dt.getColumn("testbinarycol").selectionWhereEq(t)).size());
961     PoemThread.commit();
962     assertEquals(2, EnumUtils.vectorOf(
963             dt.getColumn("testbinarycol").selectionWhereEq(t)).size());
964     assertEquals(t.length, ((byte[])dt.two().getRaw("testbinarycol")).length);
965     assertEquals(t.length, ((byte[])dt.two().getCooked("testbinarycol")).length);
966     assertEquals(t.length,
967             ((byte[])dt.getObject(0).getCooked("testbinarycol")).length);
968     columnInfo.delete();
969   }
970 
971   /**
972    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
973    */
974   public void testAddColumnAndCommitDisplaylevel() {
975     if (!getDb().getDbms().canDropColumns()) {
976       return;
977     }
978     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
979     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
980             .newPersistent();
981     TableInfo ti = dt.getTableInfo();
982     columnInfo.setTableinfo(ti);
983     columnInfo.setName("testdisplaylevelcol");
984     columnInfo.setDisplayname("Test Displaylevel Column");
985     columnInfo.setDisplayorder(99);
986     columnInfo.setSearchability(Searchability.yes);
987     columnInfo.setIndexed(false);
988     columnInfo.setUnique(false);
989     columnInfo.setDescription("A non-nullable extra Displaylevel column");
990     columnInfo.setUsercreateable(true);
991     columnInfo.setUsereditable(true);
992     columnInfo.setTypefactory(PoemTypeFactory.DISPLAYLEVEL);
993     columnInfo.setSize(-1);
994     columnInfo.setWidth(20);
995     columnInfo.setHeight(1);
996     columnInfo.setPrecision(0);
997     columnInfo.setScale(0);
998     columnInfo.setNullable(false);
999     columnInfo.setDisplaylevel(DisplayLevel.record);
1000     columnInfo.makePersistent();
1001     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
1002     Integer t = null;
1003     Enumeration<Dynamic> en = dt.selection();
1004     t = (Integer)((Dynamic)en.nextElement()).getRaw("testdisplaylevelcol");
1005     while (en.hasMoreElements()) {
1006       assertEquals(t, ((Dynamic)en.nextElement()).getRaw("testdisplaylevelcol"));
1007     }
1008 
1009     DisplayLevel t2 = null;
1010     Enumeration<Dynamic> en2 = dt.selection();
1011     t2 = (DisplayLevel)((Dynamic)en2.nextElement())
1012             .getCooked("testdisplaylevelcol");
1013     while (en2.hasMoreElements()) {
1014       assertEquals(t2, ((Dynamic)en2.nextElement())
1015               .getCooked("testdisplaylevelcol"));
1016     }
1017 
1018     assertEquals(2, EnumUtils.vectorOf(
1019             dt.getColumn("testdisplaylevelcol")
1020                     .selectionWhereEq(new Integer(0))).size());
1021     PoemThread.commit();
1022     assertEquals(2, EnumUtils.vectorOf(
1023             dt.getColumn("testdisplaylevelcol")
1024                     .selectionWhereEq(new Integer(0))).size());
1025     assertEquals(new Integer(0), dt.two().getRaw("testdisplaylevelcol"));
1026     assertEquals(DisplayLevel.primary, dt.two()
1027             .getCooked("testdisplaylevelcol"));
1028     assertEquals(DisplayLevel.primary, dt.getObject(0).getCooked(
1029             "testdisplaylevelcol"));
1030     columnInfo.delete();
1031   }
1032 
1033   /**
1034    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
1035    */
1036   public void testAddColumnAndCommitSearchability() {
1037     if (!getDb().getDbms().canDropColumns()) {
1038       return;
1039     }
1040     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
1041     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
1042             .newPersistent();
1043     TableInfo ti = dt.getTableInfo();
1044     columnInfo.setTableinfo(ti);
1045     columnInfo.setName("testsearchabilitycol");
1046     columnInfo.setDisplayname("Test searchability Column");
1047     columnInfo.setDisplayorder(99);
1048     columnInfo.setSearchability(Searchability.yes);
1049     columnInfo.setIndexed(false);
1050     columnInfo.setUnique(false);
1051     columnInfo.setDescription("A non-nullable extra Searchability column");
1052     columnInfo.setUsercreateable(true);
1053     columnInfo.setUsereditable(true);
1054     columnInfo.setTypefactory(PoemTypeFactory.SEARCHABILITY);
1055     columnInfo.setSize(-1);
1056     columnInfo.setWidth(20);
1057     columnInfo.setHeight(1);
1058     columnInfo.setPrecision(0);
1059     columnInfo.setScale(0);
1060     columnInfo.setNullable(false);
1061     columnInfo.setDisplaylevel(DisplayLevel.record);
1062     columnInfo.makePersistent();
1063     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
1064     Integer t = null;
1065     Enumeration<Dynamic> en = dt.selection();
1066     t = (Integer)((Dynamic)en.nextElement()).getRaw("testsearchabilitycol");
1067     while (en.hasMoreElements()) {
1068       assertEquals(t, ((Dynamic)en.nextElement())
1069               .getRaw("testsearchabilitycol"));
1070     }
1071 
1072     Searchability t2 = null;
1073     Enumeration<Dynamic> en2 = dt.selection();
1074     t2 = (Searchability)((Dynamic)en2.nextElement())
1075             .getCooked("testsearchabilitycol");
1076     while (en2.hasMoreElements()) {
1077       assertEquals(t2, ((Dynamic)en2.nextElement())
1078               .getCooked("testsearchabilitycol"));
1079     }
1080 
1081     assertEquals(2, EnumUtils.vectorOf(
1082             dt.getColumn("testsearchabilitycol").selectionWhereEq(
1083                     new Integer(0))).size());
1084     PoemThread.commit();
1085     assertEquals(2, EnumUtils.vectorOf(
1086             dt.getColumn("testsearchabilitycol").selectionWhereEq(
1087                     new Integer(0))).size());
1088     assertEquals(new Integer(0), dt.two().getRaw("testsearchabilitycol"));
1089     assertEquals(Searchability.primary, dt.two().getCooked(
1090             "testsearchabilitycol"));
1091     assertEquals(Searchability.primary, dt.getObject(0).getCooked(
1092             "testsearchabilitycol"));
1093     columnInfo.delete();
1094   }
1095 
1096   /**
1097    * @see org.melati.poem.Table#addColumnAndCommit(ColumnInfo)
1098    */
1099   public void testAddColumnAndCommitIntegrityfix() {
1100     if (!getDb().getDbms().canDropColumns()) {
1101       return;
1102     }
1103     DynamicTable<Dynamic> dt = ((EverythingDatabase)getDb()).getDynamicTable();
1104     ColumnInfo columnInfo = (ColumnInfo)getDb().getColumnInfoTable()
1105             .newPersistent();
1106     TableInfo ti = dt.getTableInfo();
1107     columnInfo.setTableinfo(ti);
1108     columnInfo.setName("testintegrityfixcol");
1109     columnInfo.setDisplayname("Test Integrityfix Column");
1110     columnInfo.setDisplayorder(99);
1111     columnInfo.setSearchability(Searchability.yes);
1112     columnInfo.setIndexed(false);
1113     columnInfo.setUnique(false);
1114     columnInfo.setDescription("A non-nullable extra Integrityfix column");
1115     columnInfo.setUsercreateable(true);
1116     columnInfo.setUsereditable(true);
1117     columnInfo.setTypefactory(PoemTypeFactory.INTEGRITYFIX);
1118     columnInfo.setSize(-1);
1119     columnInfo.setWidth(20);
1120     columnInfo.setHeight(1);
1121     columnInfo.setPrecision(0);
1122     columnInfo.setScale(0);
1123     columnInfo.setNullable(false);
1124     columnInfo.setDisplaylevel(DisplayLevel.record);
1125     columnInfo.makePersistent();
1126     columnInfo.getTableinfo().actualTable().addColumnAndCommit(columnInfo);
1127     Integer t = null;
1128     Enumeration<Dynamic> en = dt.selection();
1129     t = (Integer)((Dynamic)en.nextElement()).getRaw("testIntegrityfixcol");
1130     while (en.hasMoreElements()) {
1131       assertEquals(t, ((Dynamic)en.nextElement()).getRaw("testIntegrityfixcol"));
1132     }
1133 
1134     IntegrityFix t2 = null;
1135     Enumeration<Dynamic> en2 = dt.selection();
1136     t2 = (IntegrityFix)((Dynamic)en2.nextElement())
1137             .getCooked("testIntegrityfixcol");
1138     while (en2.hasMoreElements()) {
1139       assertEquals(t2, ((Dynamic)en2.nextElement())
1140               .getCooked("testIntegrityfixcol"));
1141     }
1142 
1143     assertEquals(2, EnumUtils.vectorOf(
1144             dt.getColumn("testIntegrityfixcol")
1145                     .selectionWhereEq(new Integer(2))).size());
1146     PoemThread.commit();
1147     assertEquals(2, EnumUtils.vectorOf(
1148             dt.getColumn("testIntegrityfixcol")
1149                     .selectionWhereEq(new Integer(2))).size());
1150     assertEquals(new Integer(2), dt.two().getRaw("testIntegrityfixcol"));
1151     assertEquals(StandardIntegrityFix.prevent, dt.two().getCooked(
1152             "testIntegrityfixcol"));
1153     assertEquals(StandardIntegrityFix.prevent, dt.getObject(0).getCooked(
1154             "testIntegrityfixcol"));
1155     columnInfo.delete();
1156   }
1157 
1158 }