KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > datasystem > indexsystem > TempBlobClobColumnObjectsTable


1 package com.daffodilwoods.daffodildb.server.datasystem.indexsystem;
2
3 import com.daffodilwoods.daffodildb.server.datasystem.btree.*;
4 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.*;
5 import com.daffodilwoods.daffodildb.server.datasystem.persistentsystem.*;
6 import com.daffodilwoods.daffodildb.server.datasystem.utility.*;
7 import com.daffodilwoods.daffodildb.server.sql99.dql.iterator.*;
8 import com.daffodilwoods.daffodildb.utils.*;
9 import com.daffodilwoods.daffodildb.utils.byteconverter.*;
10 import com.daffodilwoods.daffodildb.utils.field.*;
11 import com.daffodilwoods.database.general.*;
12 import com.daffodilwoods.database.resource.*;
13 import com.daffodilwoods.daffodildb.server.datasystem.interfaces.Utility;
14
15
16 public class TempBlobClobColumnObjectsTable extends BlobClobColumnObjectsTable implements _TempDataUser{
17   private _DatabaseUser user;
18   LobManager fileLobManager;
19
20   public TempBlobClobColumnObjectsTable(_DatabaseUser user0,_DataTable tab,QualifiedIdentifier tableName0,LobManager lobManager0) throws DException {
21     super(tab,tableName0,lobManager0);
22     user = user0;
23   }
24
25   public Object JavaDoc insert(_TableIterator iterator, Object JavaDoc[] values, int index) throws DException {
26        int columnCount = tableCharacteristics.getColumnCount();
27        for(int i = 0; i < columnCount ; i++){
28                if( !((FieldBase)values[i]).getNull() && tableCharacteristics.isBlobClob(i) ){
29                    DBlobUpdatable bb = (DBlobUpdatable)values[i];
30                    LobManager lob_man = bb.getLobManager();
31                    if ( lob_man !=null && !lob_man.database.getDatabaseName().equalsIgnoreCase(DatabaseConstants.TEMPDATABASE)) {
32                      if(fileLobManager == null)
33                        fileLobManager = lob_man;
34                      int address = bb.getStartingClusterAddress();
35                      short recordNumber = bb.getRecordNumber();
36                      if(address < 0){
37                       bb.setStartingClusterAddress(address);
38                       bb.setRecordNumber( (short)(recordNumber));
39                     }
40                     else{
41                       bb.setStartingClusterAddress( -address);
42                       bb.setRecordNumber( (short) ( -recordNumber));
43                     }
44                      values[i] = bb;
45                    }
46                    else{
47                     DBlobUpdatable bb1 = (DBlobUpdatable)values[i];
48                     if(!bb1.isDBlob()){
49                       values[i] = lobManager.insertBlobBytes(user, values[i], i);
50                     }
51                     }
52                  }
53
54        }
55        return table.insert(iterator,user,tableCharacteristics.getBufferRange(values),index);
56   }
57
58   public Object JavaDoc delete(_TableIterator iterator, int index) throws DException {
59     BufferRange[] bytes = (BufferRange[])iterator.getColumnValues();
60
61     int [] columnTypes = tableCharacteristics.getColumnTypes();
62     for(int i = 0 ; i < columnTypes.length ; i++ ){
63         if (!bytes[i].getNull() && tableCharacteristics.isBlobClob(i)){
64             int startAddress = bytes[i].getNull() ? 0 : CCzufDpowfsufs.getIntValue(bytes[i],0);
65             short recordNumber = bytes[i].getNull() ? 0 : CCzufDpowfsufs.getShortValue(bytes[i],4);
66             if( startAddress > 0 && recordNumber > 0)
67               lobManager.deleteBlob(user,startAddress,i,recordNumber);
68         }
69     }
70     return table.delete(iterator,user,index);
71   }
72
73   public Object JavaDoc update(_TableIterator iterator,int[] columns, Object JavaDoc[] values, int index) throws DException {
74     return super.update(iterator,user,columns,values,index);
75   }
76   public _DatabaseUser getDatabaseUser(){
77     return user;
78 }
79   public Object JavaDoc update(_TableIterator iterator, Object JavaDoc[] values, int index) throws DException {
80     return super.update(iterator,user,values,index);
81   }
82
83   public Object JavaDoc getColumnObjects(_TableIterator iterator) throws DException {
84         Object JavaDoc[] bytes = (Object JavaDoc[])iterator.getColumnValues();
85         FieldBase[] values = new FieldBase[bytes.length];
86             for(int i = 0,count = tableCharacteristics.getColumnCount(); i < count ; i++) {
87                 if( tableCharacteristics.isBlobClob(i) ){
88                     int columnType = tableCharacteristics.getColumnType(i);
89                     if(!((BufferRange)bytes[i]).getNull())
90                         values[i] = convertBlobClob(i,columnType,bytes[i]);
91                     else{
92                         values[i] = Utility.isBlob(columnType) ? new DBlobUpdatable(true) :
93                                     new DClobUpdatable(true);
94                     }
95                 }
96                 else
97                     values[i] = (FieldBase)tableCharacteristics.getObject(i,(BufferRange)bytes[i]);
98             }
99             return values;
100     }
101
102     public Object JavaDoc getColumnObjects(_TableIterator iterator, int column) throws DException {
103         Object JavaDoc bytes = iterator.getColumnValues(column);
104         if( tableCharacteristics.isBlobClob(column) ){
105                 int columnType = tableCharacteristics.getColumnType(column);
106                 if(!((BufferRange)bytes).getNull())
107                     return convertBlobClob(column,columnType,bytes);
108                 else
109                     return Utility.isBlob(columnType) ? new DBlobUpdatable(true) :
110                     new DClobUpdatable(true);
111         }
112         else{
113             return (FieldBase)tableCharacteristics.getObject(column,(BufferRange)bytes);
114         }
115     }
116
117     public Object JavaDoc getColumnObjects(_TableIterator iterator,int[] columns) throws DException{
118            Object JavaDoc[] values = (Object JavaDoc[])iterator.getColumnValues(columns);
119            FieldBase[] temp = new FieldBase[columns.length];
120                for(int i = 0; i < columns.length ; i++) {
121                    if( tableCharacteristics.isBlobClob(columns[i])){
122                        int columnType = tableCharacteristics.getColumnType(columns[i]);
123                        if( !((BufferRange)values[i]).getNull())
124                            temp[i] = convertBlobClob(columns[i],columnType,values[i]);
125                        else{
126                            temp[i] = Utility.isBlob(columnType) ? new DBlobUpdatable(true) :
127                                      new DClobUpdatable(true);
128                        }
129                    }
130                    else
131                        temp[i] = (FieldBase)tableCharacteristics.getObject(columns[i],(BufferRange)values[i]);
132                }
133                return temp;
134        }
135
136     private FieldBase convertBlobClob(int columnIndex,int columnType,Object JavaDoc values){
137           int startAddress = (int)CCzufDpowfsufs.getIntValue(((BufferRange)values).getBytes(),0);
138           short recordNumber = CCzufDpowfsufs.getShortValue(((BufferRange)values).getBytes(),4);
139           DBlobUpdatable dBlobUpdatable = null;
140
141           if(startAddress < 0 && recordNumber < 0){
142
143             dBlobUpdatable =(DBlobUpdatable)(Utility.isBlob(columnType) ? fileLobManager.retrieveDataForBlob(-startAddress,(short)(-recordNumber)) :
144                                             fileLobManager.retrieveDataForClob(-startAddress,(short)( -recordNumber)));
145             dBlobUpdatable.setDBLob(true);
146             return (FieldBase)dBlobUpdatable;
147           }
148           else{
149             dBlobUpdatable = (DBlobUpdatable) (Utility.isBlob(columnType) ?
150                                                lobManager.retrieveDataForBlob(
151                 startAddress, recordNumber) :
152                                                lobManager.retrieveDataForClob(
153                 startAddress, recordNumber));
154             dBlobUpdatable.setDBLob(false);
155           }
156             return (FieldBase)dBlobUpdatable;
157           }
158
159           public void setTable(_IndexTableList table1) throws DException {
160             super.setTable(table1);
161             int blobClobColumnCount = dataTable.getTableCharacteristics().isBlobClobTable();
162             ((TempIndexTable)table1).clustersInMemory += (blobClobColumnCount*2);
163           }
164           public Object JavaDoc deleteBlobClobRecord(_TableIterator iterator, _DatabaseUser user0, int index) throws DException{
165             return super.deleteBlobClobRecord(iterator,user,index);
166           }
167
168 }
169
Popular Tags