Statistics
| Revision:

root / trunk / libraries / libGDBMS / src / main / java / com / hardcode / gdbms / engine / data / DataSourceCommonImpl.java @ 10627

History | View | Annotate | Download (1.43 KB)

1
package com.hardcode.gdbms.engine.data;
2

    
3
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
4
import com.hardcode.gdbms.engine.values.Value;
5

    
6
/**
7
 * @author Fernando Gonz?lez Cort?s
8
 */
9
public abstract class DataSourceCommonImpl implements DataSource{
10

    
11
        /**
12
         * @see com.hardcode.gdbms.engine.data.DataSource#getRow(long)
13
         */
14
        public Value[] getRow(long rowIndex) throws ReadDriverException {
15
                Value[] ret = new Value[getFieldCount()];
16

    
17
                for (int i = 0; i < ret.length; i++) {
18
                        ret[i] = getFieldValue(rowIndex, i);
19
                }
20

    
21
                return ret;
22
        }
23

    
24
        /**
25
         * @see com.hardcode.gdbms.engine.data.DataSource#getFieldNames()
26
         */
27
        public String[] getFieldNames() throws ReadDriverException {
28
                String[] ret = new String[getFieldCount()];
29

    
30
                for (int i = 0; i < ret.length; i++) {
31
                        ret[i] = getFieldName(i);
32
                }
33

    
34
                return ret;
35
        }
36

    
37
    /**
38
     * gets a string representation of this datasource
39
     *
40
     * @return String
41
     */
42
    public String getAsString() throws ReadDriverException {
43
    
44
        StringBuffer aux = new StringBuffer();
45
        int fc = getFieldCount();
46
        int rc = (int) getRowCount();
47
    
48
        for (int i = 0; i < fc; i++) {
49
            aux.append(getFieldName(i).toUpperCase()).append("\t");
50
        }
51
    
52
        for (int row = 0; row < rc; row++) {
53
            for (int j = 0; j < fc; j++) {
54
                aux.append(getFieldValue(row, j)).append("\t");
55
            }
56
        }
57
    
58
        return aux.toString();
59
    }
60

    
61
}