Index: ExporrtoJDBCService.java
===================================================================
--- ExporrtoJDBCService.java	(revision 43647)
+++ ExporrtoJDBCService.java	(revision 43648)
@@ -22,7 +22,7 @@
  */
 package org.gvsig.exportto.swing.prov.jdbc;
 
-import java.util.Map;
+import java.text.MessageFormat;
 import org.apache.commons.lang3.StringUtils;
 import org.cresques.cts.ICoordTrans;
 import org.cresques.cts.IProjection;
@@ -68,7 +68,8 @@
     public static final int ACTION_ABORT = 2;
 
     private ExporttoServiceFinishAction exporttoServiceFinishAction = null;
-    private ExporttoJDBCOptions options;
+    private final ExporttoJDBCOptions options;
+    private FeatureType targetFeatureType = null;
 //    private Map<String,String> translationIds;
 
     public ExporrtoJDBCService(ExporttoJDBCOptions options) {
@@ -91,12 +92,18 @@
 
     protected void createTable(JDBCServerExplorer explorer) throws Exception {
 
-        FeatureType targetFeatureType;
+        FeatureType targetTempFeatureType;
         EditableFeatureType targetEditableFeatureType;
 
-        targetFeatureType = options.getSource().getDefaultFeatureType().getCopy();
-        targetEditableFeatureType = targetFeatureType.getEditable();
+        targetTempFeatureType = options.getSource().getDefaultFeatureType().getCopy();
+        targetEditableFeatureType = targetTempFeatureType.getEditable();
 
+        // Remove inherited primary keys from the data source
+        for (int i = 0; i < targetEditableFeatureType.size(); i++) {
+            EditableFeatureAttributeDescriptor x = (EditableFeatureAttributeDescriptor) targetEditableFeatureType.get(i);
+            x.setIsPrimaryKey(false);
+        }
+                
         if (this.options.getTranslateIdentifiersToLowerCase()
                 || this.options.getRemoveSpacesInIdentifiers() 
                 || this.options.getTranslateHyphens()) {
@@ -134,6 +141,17 @@
         }
 
         // ======================================
+        // Remove index to improve performance
+        this.targetFeatureType = targetEditableFeatureType.getNotEditableCopy();
+        for (int i = 0; i < targetEditableFeatureType.size(); i++) {
+            EditableFeatureAttributeDescriptor x = (EditableFeatureAttributeDescriptor) targetEditableFeatureType.get(i);
+            //x.setIsPrimaryKey(false);
+            x.setIsIndexed(false);
+        }
+        
+        // ======================================
+
+
         JDBCNewStoreParameters createTableParams = (JDBCNewStoreParameters) explorer.getAddParameters();
 
         createTableParams.setSelectRole(this.options.getSelectRole());
@@ -155,12 +173,15 @@
 
     private static class InvalidGeometryException extends ExporttoServiceException {
 
+        private static final long serialVersionUID = 3082742759529054747L;
+
         public InvalidGeometryException(Feature feature, String checkMessage) {
             super(checkMessage, null, checkMessage, 0);
             this.feature = feature;
         }
     }
 
+    @Override
     public void export(FeatureSet featureSet) throws ExporttoServiceException {
         Geometry.ValidationStatus geometryCheck;
 
@@ -173,9 +194,9 @@
             // ======================================
             // Reprojection
             FeatureAttributeDescriptor geo_att = this.options.getSource().getDefaultFeatureType().getDefaultGeometryAttribute();
-            IProjection sourceProjection = null;
+            IProjection sourceProjection;
             ICoordTrans coord_trans = null;
-            Geometry reproj_geom = null;
+            Geometry reproj_geom;
             IProjection targetProjection = this.options.getTargetProjection();
             if (geo_att != null) {
                 sourceProjection = geo_att.getSRS();
@@ -215,11 +236,11 @@
 
             target.edit(FeatureStore.MODE_APPEND);
 
-            int featureCount = 1;
+            long featureCount = 1;
             taskStatus.setRangeOfValues(0, featureSet.getSize());
 
-            int targetGeometryIndex = -1;
-            int sourceGeometryIndex = -1;
+            int targetGeometryIndex;
+            int sourceGeometryIndex;
             if( getGeometryColumnCount(sourceFeatureType)==1
                     && getGeometryColumnCount(targetFeatureType)==1 ) {
                 // Si solo hay una columna de geometria asignaremos las geometrias
@@ -324,12 +345,36 @@
                 }
                 featureCount++;
             }
+            String msgRowCount = MessageFormat.format(" ({0,number, #,###} rows)",featureCount);
             targetFeature = null;
+            taskStatus.setIndeterminate();
+            logger.debug("Finish editing"+msgRowCount);
+            if( featureCount > 50000 ) {
+                taskStatus.message("Finishing insertion of records, may take a while" + msgRowCount);
+            } else {
+                taskStatus.message("Finishing insertion of records"+msgRowCount);
+            }
             target.finishEditing();
-
+            
+             if (this.options.canCreatetable()) {
+                taskStatus.message("Preparing the update of the indices"+msgRowCount);
+                target.edit();
+                EditableFeatureType ft = target.getDefaultFeatureType().getEditable();
+                for( FeatureAttributeDescriptor attr : this.targetFeatureType) {
+                    EditableFeatureAttributeDescriptor attr2 = (EditableFeatureAttributeDescriptor) ft.getAttributeDescriptor(attr.getName());
+                    if( attr2!=null ) {
+                        //attr2.setIsPrimaryKey(attr.isPrimaryKey());
+                        attr2.setIsIndexed(attr.isIndexed());
+                        attr2.setIsAutomatic(attr.isAutomatic());
+                    }
+                }
+                target.update(ft);
+                taskStatus.message("Updating the indices"+msgRowCount);
+                target.finishEditing();
+            }
             if (this.options.getUpdateTableStatistics()) {
                 logger.debug("Updating statistics");
-                taskStatus.message("Updating statistics");
+                taskStatus.message("Updating statistics"+msgRowCount);
                 explorer.updateTableStatistics(
                         openParams.getDBName(),
                         openParams.getSchema(),
@@ -337,13 +382,14 @@
                 );
             }
             logger.debug("finish");
+            taskStatus.message("Exportation finished");
+            this.taskStatus.terminate();
 
             if (exporttoServiceFinishAction != null) {
                 exporttoServiceFinishAction.finished(
                         this.options.getTableName() + " (" + explorer.getStoreName() + ")",
                         openParams);
             }
-            taskStatus.message("Exportation finished");
 
         } catch (Exception e) {
             logger.warn("Can't export data.", e);
@@ -360,7 +406,7 @@
                     try {
                         target.cancelEditing();
                     } catch(Exception ex) {
-                        // Do nothing
+                        logger.warn("Can't cancel editing.",ex);
                     }
                 }
                 target.dispose();
@@ -380,6 +426,7 @@
         return count;
     }
 
+    @Override
     public void setFinishAction(
             ExporttoServiceFinishAction exporttoServiceFinishAction) {
         this.exporttoServiceFinishAction = exporttoServiceFinishAction;
