Statistics
| Revision:

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

History | View | Annotate | Download (1.65 KB)

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

    
6
import com.hardcode.driverManager.DriverLoadException;
7

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

    
13
import java.util.ArrayList;
14

    
15

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

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

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

    
41
                                        if (tRef.getAlias() == null) {
42
                                                ret.add(getInstructionContext().getDSFActory()
43
                                                                        .createRandomDataSource(tRef.getName(), DataSourceFactory.MANUAL_MODE));
44
                                        } else {
45
                                                ret.add(getInstructionContext().getDSFActory()
46
                                                                        .createRandomDataSource(tRef.getName(),
47
                                                                tRef.getAlias(), DataSourceFactory.MANUAL_MODE));
48
                                        }
49
                                }
50

    
51
                                tables = (DataSource[]) ret.toArray(new DataSource[0]);
52
                        } catch (NoSuchTableException e) {
53
                                throw new TableNotFoundException(e);
54
                        } catch (DriverLoadException e) {
55
                                throw new RuntimeException(e);
56
                        } catch (DriverException e) {
57
                throw new RuntimeException(e);
58
            }
59
                }
60

    
61
                return tables;
62
        }
63
}