Revision 511 trunk/org.gvsig.postgresql/org.gvsig.postgresql.provider/src/main/java/org/gvsig/postgresql/dal/PostgreSQLBuilder.java

View differences:

PostgreSQLBuilder.java
32 32
import org.apache.commons.lang3.StringUtils;
33 33
import org.gvsig.fmap.dal.store.jdbc2.JDBCHelper;
34 34
import org.gvsig.fmap.dal.store.jdbc2.spi.JDBCSQLBuilderBase;
35
import org.gvsig.tools.packageutils.Version;
36
import org.gvsig.tools.packageutils.impl.DefaultVersion;
37 35

  
38 36
public class PostgreSQLBuilder extends JDBCSQLBuilderBase {
39 37

  
......
79 77
    
80 78
    public PostgreSQLBuilder(JDBCHelper helper) {
81 79
        super(helper);
82
              
83
        config.set(SQLConfig.default_schema, "public");
84
        config.set(SQLConfig.allowAutomaticValues, true);
85
        config.set(SQLConfig.geometry_type_support, this.helper.getGeometrySupportType());
86
        config.set(SQLConfig.has_spatial_functions, this.helper.hasSpatialFunctions());
87
        config.set(SQLConfig.constant_true, "true");
88
        config.set(SQLConfig.constant_false, "false");
89
            
90
        config.remove_functionality(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table);
91
        config.remove_functionality(SQLConfig.DELETE_GEOMETRY_COLUMN_FROM_TABLE_table);
92
         
93
        config.set(SQLConfig.UPDATE_TABLE_STATISTICS_table,"ANALYZE {0}");
80
        this.defaultSchema = "public";
81
        this.supportSchemas = true;
82
        this.allowAutomaticValues = true;
83
        this.geometrySupportType = this.helper.getGeometrySupportType();
84
        this.hasSpatialFunctions = this.helper.hasSpatialFunctions();
94 85

  
95
        config.set(SQLConfig.ST_GeomFromEWKB, "ST_GeomFromEWKB({0}, {1})");
96
        config.set(SQLConfig.ST_AsEWKB, "ST_AsEWKB(({0}))");        
97
        config.set(SQLConfig.ST_ExtentAggregate, "ST_Extent({0})");        
98
        config.set(SQLConfig.ST_UnionAggregate, "ST_Union({0})");
86
        this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_schema_table = null;
87
        this.STMT_DELETE_GEOMETRY_COLUMN_FROM_TABLE_table = null;
88

  
89
        this.STMT_UPDATE_TABLE_STATISTICS_table = "ANALYZE {0}";
90

  
91
//        config.set(SQLConfig.ST_GeomFromEWKB, "ST_GeomFromEWKB({0}, {1})");
92
//        config.set(SQLConfig.ST_AsEWKB, "ST_AsEWKB(({0}))");        
93
//        config.set(SQLConfig.ST_ExtentAggregate, "ST_Extent({0})");        
94
//        config.set(SQLConfig.ST_UnionAggregate, "ST_Union({0})");
99 95
        
100
        config.set(SQLConfig.lcase, "lower({0})");
101
        config.set(SQLConfig.ucase, "upper({0})");
102
        config.set(SQLConfig.operator_ILIKE, "({0}) ILIKE ({1})");
103
        config.set(SQLConfig.isNull, "( ({0}) ISNULL )");
104
        config.set(SQLConfig.notIsNull, "( ({0}) NOT NULL )");
96
//        config.set(SQLConfig.isNull, "( ({0}) ISNULL )");
97
//        config.set(SQLConfig.notIsNull, "( ({0}) NOT NULL )");
105 98

  
106 99
    }
107 100
    
......
110 103
        public List<String> toStrings() {
111 104
            List<String> sqls = new ArrayList<>();
112 105
            
113
            if( config.has_functionality(SQLConfig.UPDATE_TABLE_STATISTICS_table) ) {
106
            if( !StringUtils.isBlank(STMT_UPDATE_TABLE_STATISTICS_table) ) {
114 107
                // In postGIS, UpdateLayerStatistics function, don't allow to 
115 108
                // use the database name in the table name.
116
                String name = identifier(this.table.getName());
109
                String name = as_identifier(this.table.getName());
117 110
                if( table.has_schema()) {
118
                    name = identifier(this.table.getSchema()) + "." + name;
111
                    name = as_identifier(this.table.getSchema()) + "." + name;
119 112
                }
120 113
                String sql = MessageFormat.format(
121
                        config.getString(SQLConfig.UPDATE_TABLE_STATISTICS_table),
114
                        STMT_UPDATE_TABLE_STATISTICS_table,
122 115
                        name
123 116
                    );
124 117
                if( !StringUtils.isEmpty(sql) ) {
......
144 137
                    builder.append("IF NOT EXISTS ");
145 138
                }
146 139
            }
147
            builder.append(identifier(this.indexName));
140
            builder.append(as_identifier(this.indexName));
148 141
            builder.append(" ON ");
149 142
            builder.append(this.table.toString());
150 143
            if( this.isSpatial ) {
......
192 185
                } else {
193 186
                    builder.append(", ");
194 187
                }
195
                builder.append(identifier(column.getName()));
188
                builder.append(as_identifier(column.getName()));
196 189
                builder.append(" ");
197 190
                if( column.isAutomatic() ) {
198 191
                    builder.append(" SERIAL");
199 192
                } else {
200
                    builder.append(sqltype(column.getType(), column.getPrecision(), column.getSize()));
193
                    builder.append(sqltype(
194
                            column.getType(), 
195
                            column.getPrecision(), 
196
                            column.getSize(),
197
                            column.getGeometryType(),
198
                            column.getGeometrySubtype()
199
                    ));
201 200
                    if (column.getDefaultValue() == null) {
202 201
                        if (column.allowNulls()) {
203 202
                            builder.append(" DEFAULT NULL");
......
225 224
                if( column.isGeometry() ) {
226 225
                    String sql = MessageFormat.format(
227 226
                        AddGeometryColumn,
228
                        constant(this.table.getSchema()),
229
                        constant(this.table.getName()),
230
                        constant(column.getName()),
227
                        as_string(this.table.getSchema()),
228
                        as_string(this.table.getName()),
229
                        as_string(column.getName()),
231 230
                        column.getGeometrySRSId(),
232
                        constant(sqlgeometrytype(column.getGeometryType(), column.getGeometrySubtype())),
233
                        constant(sqlgeometrydimension(column.getGeometryType(), column.getGeometrySubtype())),
234
                        constant(column.allowNulls())
231
                        as_string(sqlgeometrytype(column.getGeometryType(), column.getGeometrySubtype())),
232
                        as_string(sqlgeometrydimension(column.getGeometryType(), column.getGeometrySubtype())),
233
                        as_string(column.allowNulls())
235 234
                    );
236 235
                    sqls.add(sql);
237 236
                }
......
323 322
        }
324 323
    }
325 324

  
326
    @Override
327
    public String bytearray(byte[] data) {
328
        return "decode('"+bytearray_hex(data)+"','hex')";
329
    }
325
//    @Override
326
//    public String bytearray(byte[] data) {
327
//        return "decode('"+as_string(data)+"','hex')";
328
//    }
330 329

  
331 330
    public PostgreSQLHelper getHelper() {
332 331
        return (PostgreSQLHelper) helper;

Also available in: Unified diff