Revision 44058 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.dal/org.gvsig.fmap.dal.db/org.gvsig.fmap.dal.db.jdbc/src/main/java/org/gvsig/fmap/dal/store/jdbc2/spi/operations/CreateTableOperation.java

View differences:

CreateTableOperation.java
5 5
import java.sql.Statement;
6 6
import java.util.ArrayList;
7 7
import java.util.List;
8
import org.apache.commons.collections.CollectionUtils;
9 8
import org.apache.commons.lang3.tuple.Pair;
10 9
import org.gvsig.fmap.dal.exception.DataException;
11 10
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
......
15 14
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
16 15
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCSQLException;
17 16
import org.gvsig.fmap.dal.store.jdbc2.JDBCUtils;
17
import org.gvsig.fmap.dal.store.jdbc2.OperationsFactory.TableReference;
18 18
import org.gvsig.fmap.geom.DataTypes;
19 19

  
20 20
public class CreateTableOperation extends AbstractConnectionWritableOperation {
21 21

  
22
    private final String schemaName;
23
    private final String tableName;
22
    private final TableReference table;
24 23
    private final FeatureType type;
25 24
    private final List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges;
26 25
    private final List<String> additionalSQLs;
27
    private final String dbName;
28 26

  
29 27
    public CreateTableOperation(
30 28
            JDBCHelper helper
31 29
        ) {
32
        this(helper, null, null, null, null, null, null);
30
        this(helper, null, null, null, null);
33 31
    }
34 32
    
35 33
    public CreateTableOperation(
36 34
            JDBCHelper helper,
37
            String dbName,
38
            String schemaName,
39
            String tableName,
35
            TableReference table,
40 36
            FeatureType type,
41 37
            List<Pair<String, SQLBuilder.Privilege>> userAndPrivileges,
42 38
            List<String> additionalSQLs
43 39
        ) {
44 40
        super(helper);
45
        this.dbName = dbName;
46
        this.schemaName = schemaName;
47
        this.tableName = tableName;
41
        this.table = table;
48 42
        this.type = type;
49 43
        this.userAndPrivileges = userAndPrivileges;
50 44
        this.additionalSQLs = additionalSQLs;
......
53 47
    @Override
54 48
    public final Object perform(Connection conn) throws DataException {
55 49
        return this.performCreateTable(conn, 
56
                dbName, schemaName, tableName,
57
                type, userAndPrivileges, additionalSQLs);
50
                table, type, userAndPrivileges, additionalSQLs);
58 51
    }
59 52

  
60 53
    protected List<String> buildCreateIndexesSQL(
61
            String database,
62
            String schema,
63
            String table,
54
            TableReference table,
64 55
            FeatureType type
65 56
        ) {
66 57
        ArrayList<String> sqls = new ArrayList<>();
......
74 65
                sqlbuilder.create_index().if_not_exist();
75 66
                sqlbuilder.create_index().name("idx_" + table + "_" + attr.getName());
76 67
                sqlbuilder.create_index().column(attr.getName());
77
                sqlbuilder.create_index().table().database(database).schema(schema).name(table);
68
                sqlbuilder.create_index().table()
69
                        .database(this.table.getDatabase())
70
                        .schema(this.table.getSchema())
71
                        .name(this.table.getTable()
72
                );
78 73
                sqls.addAll(sqlbuilder.create_index().toStrings());
79 74
            }
80 75
        }
......
82 77
    }
83 78
    
84 79
    public boolean performCreateTable(Connection conn,
85
            String dbName, 
86
            String schemaName,
87
            String tableName,
80
            TableReference table,
88 81
            FeatureType type,
89 82
            List<Pair<String, SQLBuilder.Privilege>> rolesAndPrivileges,
90 83
            List<String> additionalSQLs) throws DataException {
91 84

  
92 85
        JDBCSQLBuilderBase sqlbuilder = this.createSQLBuilder();
93
        sqlbuilder.create_table().table().database(dbName).schema(schemaName).name(tableName);
86
        sqlbuilder.create_table().table()
87
                .database(this.table.getDatabase())
88
                .schema(this.table.getSchema())
89
                .name(this.table.getTable());
94 90
        for (FeatureAttributeDescriptor attr : type) {
95 91
            if( attr.getType()==DataTypes.GEOMETRY ) {
96 92
                sqlbuilder.create_table().add_geometry_column(
......
121 117

  
122 118
        List<String> sqls;
123 119
        sqls = sqlbuilder.create_table().toStrings();
124
        sqls.addAll(buildCreateIndexesSQL(dbName, schemaName, tableName, type));
120
        sqls.addAll(buildCreateIndexesSQL(this.table,type));
125 121
        sqls.addAll(sqlbuilder.grant().toStrings());
126 122
        sqls.addAll(additionalSQLs);
127 123

  

Also available in: Unified diff