Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libGDBMS / src / com / hardcode / gdbms / engine / instruction / TableListAdapter.java @ 466

History | View | Annotate | Download (1.68 KB)

1
/*
2
 * Created on 12-oct-2004
3
 */
4
package com.hardcode.gdbms.engine.instruction;
5

    
6
import java.util.ArrayList;
7

    
8
import com.hardcode.driverManager.DriverLoadException;
9
import com.hardcode.gdbms.engine.data.DataSource;
10
import com.hardcode.gdbms.engine.data.DataSourceFactory;
11
import com.hardcode.gdbms.engine.data.NoSuchTableException;
12

    
13

    
14
/**
15
 * Adaptador
16
 *
17
 * @author Fernando Gonz?lez Cort?s
18
 */
19
public class TableListAdapter extends Adapter {
20
    private DataSource[] tables;
21

    
22
    /**
23
     * Obtiene los DataSources de la cl?usula from
24
     *
25
     * @return array de datasources
26
     *
27
     * @throws TableNotFoundException Si no se encontr? alguna tabla
28
     * @throws RuntimeException
29
     */
30
    public DataSource[] getTables() throws TableNotFoundException {
31
        if (tables == null) {
32
            Adapter[] hijos = getChilds();
33
            ArrayList ret = new ArrayList();
34

    
35
            try {
36
                for (int i = 0; i < hijos.length; i++) {
37
                    TableRefAdapter tRef = (TableRefAdapter) hijos[i];
38

    
39
                    if (tRef.getAlias() == null) {
40
                        ret.add(DataSourceFactory.createRandomDataSource(
41
                                tRef.getName()));
42
                    } else {
43
                        ret.add(DataSourceFactory.createRandomDataSource(
44
                                tRef.getName(), tRef.getAlias()));
45
                    }
46
                }
47

    
48
                tables = (DataSource[]) ret.toArray(new DataSource[0]);
49
            } catch (NoSuchTableException e) {
50
                throw new TableNotFoundException();
51
            } catch (DriverLoadException e) {
52
                throw new RuntimeException(e);
53
                        }
54
        }
55

    
56
        return tables;
57
    }
58
}