Revision 40962
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/jdbc/JDBCStoreProviderWriter.java | ||
---|---|---|
40 | 40 |
import org.gvsig.fmap.dal.feature.exception.PerformEditingException; |
41 | 41 |
import org.gvsig.fmap.dal.feature.spi.FeatureProvider; |
42 | 42 |
import org.gvsig.fmap.dal.feature.spi.FeatureReferenceProviderServices; |
43 |
import org.gvsig.fmap.dal.resource.exception.AccessResourceException; |
|
43 | 44 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
44 | 45 |
import org.gvsig.fmap.dal.store.db.FeatureTypeHelper; |
46 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCException; |
|
45 | 47 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecutePreparedSQLException; |
46 | 48 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCExecuteSQLException; |
47 | 49 |
import org.gvsig.fmap.dal.store.jdbc.exception.JDBCPreparingSQLException; |
... | ... | |
720 | 722 |
if (directSQLMode) { |
721 | 723 |
return false; |
722 | 724 |
} |
723 |
if (getJDBCParameters().getPkFields() == null |
|
724 |
|| getJDBCParameters().getPkFields().length > 0) { |
|
725 |
FeatureType ft = null; |
|
726 |
try { |
|
727 |
ft = this.getFeatureStore().getDefaultFeatureType(); |
|
728 |
} catch (DataException e) { |
|
729 |
logger.error("Excepton get default Feature Type", e); |
|
730 |
} |
|
725 |
|
|
726 |
FeatureType ft = null; |
|
727 |
try { |
|
728 |
ft = this.getFeatureStore().getDefaultFeatureType(); |
|
729 |
} catch (DataException e) { |
|
730 |
logger.error("While getting default Feature Type", e); |
|
731 |
} |
|
732 |
|
|
733 |
String[] storePK = getPK(ft); |
|
734 |
JDBCHelper helper = this.getHelper(); |
|
735 |
String[] dbPK = null; |
|
736 |
try { |
|
737 |
dbPK = helper.getPksFrom(helper.getConnection(), getJDBCParameters()); |
|
738 |
} catch (Exception exc) { |
|
739 |
logger.error("While getting PK from DB", exc); |
|
740 |
return false; |
|
741 |
} |
|
742 |
return sameStrings(storePK, dbPK); |
|
743 |
} |
|
731 | 744 |
|
732 |
if (ft == null) { |
|
733 |
return false; |
|
734 |
} |
|
735 |
FeatureAttributeDescriptor attr; |
|
736 |
Iterator<FeatureAttributeDescriptor> iter = FeatureTypeHelper.iterator(ft); |
|
737 |
while (iter.hasNext()) { |
|
738 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
739 |
if (attr.isPrimaryKey()) { |
|
740 |
return true; |
|
741 |
} |
|
742 |
} |
|
743 |
return false; |
|
745 |
private boolean sameStrings(String[] a, String[] b) { |
|
746 |
|
|
747 |
if (a==null || b==null || a.length!=b.length || a.length==0) { |
|
748 |
/* |
|
749 |
* Must not be empty |
|
750 |
*/ |
|
751 |
return false; |
|
752 |
} |
|
753 |
int len = a.length; |
|
754 |
boolean found = false; |
|
755 |
/* |
|
756 |
* Check same |
|
757 |
*/ |
|
758 |
for (int ai=0; ai<len; ai++) { |
|
759 |
found = false; |
|
760 |
for (int bi=0; bi<len; bi++) { |
|
761 |
if (b[bi].compareTo(a[ai]) == 0) { |
|
762 |
found = true; |
|
763 |
break; |
|
764 |
} |
|
765 |
} |
|
766 |
if (! found) { |
|
767 |
return false; |
|
768 |
} |
|
769 |
} |
|
770 |
return true; |
|
771 |
} |
|
744 | 772 |
|
745 |
} else { |
|
746 |
return true; |
|
747 |
} |
|
748 |
} |
|
773 |
private String[] getPK(FeatureType ft) { |
|
774 |
|
|
775 |
List resp = new ArrayList(); |
|
776 |
FeatureAttributeDescriptor attr; |
|
777 |
Iterator<FeatureAttributeDescriptor> iter = FeatureTypeHelper.iterator(ft); |
|
778 |
while (iter.hasNext()) { |
|
779 |
attr = (FeatureAttributeDescriptor) iter.next(); |
|
780 |
if (attr.isPrimaryKey()) { |
|
781 |
resp.add(attr.getName()); |
|
782 |
} |
|
783 |
} |
|
784 |
return (String[]) resp.toArray(new String[0]); |
|
785 |
} |
|
749 | 786 |
} |
Also available in: Unified diff