KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > index > ViewCursor


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.index;
6
7 import java.sql.SQLException JavaDoc;
8
9 import org.h2.message.Message;
10 import org.h2.result.LocalResult;
11 import org.h2.result.Row;
12 import org.h2.table.Table;
13 import org.h2.value.Value;
14 import org.h2.value.ValueNull;
15
16 public class ViewCursor implements Cursor {
17     
18     private Table table;
19     private LocalResult result;
20     private Row current;
21     
22     ViewCursor(Table table, LocalResult result) {
23         this.table = table;
24         this.result = result;
25     }
26     
27     public Row get() {
28         return current;
29     }
30     
31     public int getPos() {
32         throw Message.getInternalError();
33     }
34
35     public boolean next() throws SQLException JavaDoc {
36         boolean res = result.next();
37         if(!res) {
38             result.reset();
39             current = null;
40             return false;
41         }
42         current = table.getTemplateRow();
43         Value[] values = result.currentRow();
44         for(int i=0; i<current.getColumnCount(); i++) {
45             Value v = i<values.length ? values[i] : ValueNull.INSTANCE;
46             current.setValue(i, v);
47         }
48         return true;
49     }
50     
51 }
52
Popular Tags