KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > persistentsystem > AlterRecord


1 package com.daffodilwoods.daffodildb.server.datasystem.persistentsystem;import com.daffodilwoods.database.resource.*;
2
3 /**
4  *
5  * <p>Title: Alter Record</p>
6  * <p>Description: converts already inserted records according to new table structure</p>
7  */

8
9 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._TableCharacteristics;
10 import com.daffodilwoods.daffodildb.server.datasystem.interfaces._AlterRecord;
11 public class AlterRecord implements _AlterRecord{
12
13   /**
14    * 2d array of all column names, types, sizes and indexes of new Table Structure
15    */

16   private Object JavaDoc[][] columnInformation;
17    public AlterRecord(ColumnInformation columnInfo) {
18       columnInformation = columnInfo.getObjects();
19    }
20
21    /** converts old values of table according to new table structure by inserting null
22     * in new added columns and removing values if nay column is dropped
23     *
24     * @param oldValues old table structure based values which we have to convert according to new table
25     * Structure
26     * @param tableCharacteristics old table characterisitcs having all column info according to old
27     * structure
28     * @return values according to new table structure
29
30     */

31
32    public Object JavaDoc[] getNewRecord(Object JavaDoc[] oldValues,_TableCharacteristics tableCharacteristics, Object JavaDoc defaultValue) throws DException{
33       Object JavaDoc[] newVal = new Object JavaDoc[columnInformation.length];
34       for (int i = 0; i < columnInformation.length; i++) {
35          try{
36              newVal[i] = oldValues[tableCharacteristics.getIndexForColumnName((String JavaDoc)columnInformation[i][0])];
37          }
38          catch(DException de) {
39              newVal[i] = defaultValue;
40          }
41       }
42       return newVal;
43    }
44 }
45
Popular Tags