Revision 37780 branches/v2_0_0_prep/libraries/org.gvsig.exportto/org.gvsig.exportto.swing/org.gvsig.exportto.swing.prov/org.gvsig.exportto.swing.prov.jdbc/src/main/java/org/gvsig/exportto/swing/prov/jdbc/ExporrtoJDBCService.java

View differences:

ExporrtoJDBCService.java
45 45
import org.gvsig.tools.service.ServiceException;
46 46
import org.gvsig.tools.task.AbstractMonitorableTask;
47 47

  
48

  
49 48
/**
50 49
 * @author gvSIG Team
51 50
 * @version $Id$
52
 *
51
 * 
53 52
 */
54
public class ExporrtoJDBCService extends AbstractMonitorableTask implements ExporttoService {
53
public class ExporrtoJDBCService extends AbstractMonitorableTask implements
54
    ExporttoService {
55

  
55 56
    private static final DataManager DATA_MANAGER = DALLocator.getDataManager();
56
   
57 57

  
58 58
    private String dbName = null;
59 59
    private String schema = null;
......
74 74

  
75 75
    /**
76 76
     * @param taskName
77
     * @throws ServiceException 
77
     * @throws ServiceException
78 78
     */
79
    protected ExporrtoJDBCService(FeatureStore featureStore, String dbName, String schema, String tableName, String pkField, String userName, String password,
80
        String host, int port, String explorerName, String storeName) {
81
        super("Export to JDBC");       
79
    protected ExporrtoJDBCService(FeatureStore featureStore, String dbName,
80
        String schema, String tableName, String pkField, String userName,
81
        String password, String host, int port, String explorerName,
82
        String storeName) {
83
        super("Export to JDBC");
82 84
        this.featureStore = featureStore;
83 85
        this.dbName = dbName;
84 86
        this.schema = schema;
......
89 91
        this.host = host;
90 92
        this.port = port;
91 93
        this.storeName = storeName;
92
        this.explorerName = explorerName;        
94
        this.explorerName = explorerName;
93 95
    }
94 96

  
95 97
    public void export(FeatureSet featureSet) throws ExporttoServiceException {
96
        
98

  
97 99
        initializeParams(featureSet);
98
        
100

  
99 101
        DisposableIterator it1 = null;
100 102
        FeatureStore target = null;
101 103
        try {
102
            EditableFeatureType fType = featureStore.getDefaultFeatureType().getEditable();
104
            EditableFeatureType fType =
105
                featureStore.getDefaultFeatureType().getEditable();
103 106
            if (pkField != null) {
104
                EditableFeatureAttributeDescriptor pk = fType.add(pkField,
105
                    DataTypes.LONG);
107
                EditableFeatureAttributeDescriptor pk =
108
                    fType.add(pkField, DataTypes.LONG);
106 109
                pk.setIsPrimaryKey(true);
107 110
                pk.setIsAutomatic(true);
108 111
            }
......
110 113
            newFeatureStoreParameters.setDefaultFeatureType(fType);
111 114
            explorer.add(storeName, newFeatureStoreParameters, true);
112 115

  
113
            target = (FeatureStore) DATA_MANAGER.openStore(storeName, newFeatureStoreParameters);
116
            target =
117
                (FeatureStore) DATA_MANAGER.openStore(storeName,
118
                    newFeatureStoreParameters);
114 119
            FeatureType targetType = target.getDefaultFeatureType();
115 120

  
116 121
            target.edit(FeatureStore.MODE_APPEND);
......
132 137
            }
133 138
            target.finishEditing();
134 139

  
135
            if (exporttoServiceFinishAction != null){
136
                exporttoServiceFinishAction.finished(newFeatureStoreParameters.getDataStoreName(), newFeatureStoreParameters);
140
            if (exporttoServiceFinishAction != null) {
141
                exporttoServiceFinishAction.finished(
142
                    newFeatureStoreParameters.getDataStoreName(),
143
                    newFeatureStoreParameters);
137 144
            }
138 145

  
139 146
        } catch (Exception e) {
......
151 158
            this.taskStatus.remove();
152 159
        }
153 160
    }
154
    
155 161

  
156
    private void initializeParams(FeatureSet featureSet) throws ExporttoServiceException {       
162
    private void initializeParams(FeatureSet featureSet)
163
        throws ExporttoServiceException {
157 164
        JDBCServerExplorerParameters explorerParam;
158 165
        try {
159
            explorerParam = (JDBCServerExplorerParameters) DATA_MANAGER
160
            .createServerExplorerParameters(explorerName);
166
            explorerParam =
167
                (JDBCServerExplorerParameters) DATA_MANAGER
168
                    .createServerExplorerParameters(explorerName);
161 169

  
162 170
            explorerParam.setHost(host);
163
            if (port > -1){
171
            if (port > -1) {
164 172
                explorerParam.setPort(port);
165 173
            }
166 174
            explorerParam.setDBName(dbName);
......
170 178
                explorerParam.setSchema(schema);
171 179
            }
172 180

  
173
            explorer = (JDBCServerExplorer) DATA_MANAGER.openServerExplorer(explorerName, explorerParam);
181
            explorer =
182
                (JDBCServerExplorer) DATA_MANAGER.openServerExplorer(
183
                    explorerName, explorerParam);
174 184

  
175
            newFeatureStoreParameters = (NewFeatureStoreParameters) explorer.getAddParameters();
185
            newFeatureStoreParameters =
186
                (NewFeatureStoreParameters) explorer.getAddParameters();
176 187

  
177 188
            ((DBStoreParameters) newFeatureStoreParameters).setTable(tableName);
178
            ((DBStoreParameters) newFeatureStoreParameters).setDefaultGeometryField(
179
                featureSet.getDefaultFeatureType().getDefaultGeometryAttributeName());
189
            ((DBStoreParameters) newFeatureStoreParameters)
190
                .setDefaultGeometryField(featureSet.getDefaultFeatureType()
191
                    .getDefaultGeometryAttributeName());
180 192

  
181 193
        } catch (InitializeException e) {
182 194
            throw new ExporttoServiceException(e);
......
186 198
            throw new ExporttoServiceException(e);
187 199
        } catch (DataException e) {
188 200
            throw new ExporttoServiceException(e);
189
        }       
201
        }
190 202
    }
191 203

  
192 204
    public void setFinishAction(

Also available in: Unified diff