From: <aa...@sv...> - 2006-12-29 17:59:58
|
Author: aaime Date: 2006-12-29 10:59:36 -0800 (Fri, 29 Dec 2006) New Revision: 23630 Modified: geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/data= /jdbc/JDBCFeatureWriter.java geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/data= /jdbc/JDBCTextFeatureWriter.java Log: Partial fix for GEOT-1098 Modified: geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotoo= ls/data/jdbc/JDBCFeatureWriter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/dat= a/jdbc/JDBCFeatureWriter.java 2006-12-29 16:55:04 UTC (rev 23629) +++ geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/dat= a/jdbc/JDBCFeatureWriter.java 2006-12-29 18:59:36 UTC (rev 23630) @@ -17,6 +17,9 @@ =20 import java.io.IOException; import java.sql.SQLException; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; =20 @@ -277,8 +280,10 @@ FIDMapper mapper =3D queryData.getMapper(); =20 // read the new fid into the Feature=20 + Set autoincrementColumns =3D null; if ((mapper.getColumnCount() > 0) && !mapper.returnFIDColumnsAsAttributes()) { + autoincrementColumns =3D Collections.EMPTY_SET; String ID =3D mapper.createID(queryData.getConnection(), mut= able, null); fidAttributes =3D mapper.getPKAttributes(ID); =20 @@ -294,13 +299,21 @@ } } } + } else { + autoincrementColumns =3D new HashSet(); + for (int i =3D 0; i < mapper.getColumnCount(); i++) { + if (mapper.isAutoIncrement(i)) { + autoincrementColumns.add(mapper.getColumnName(i)); + } + } } =20 // set up attributes and write row for (int i =3D 0; i < current.getNumberOfAttributes(); i++) { Object currAtt =3D current.getAttribute(i); - - queryData.write(i, currAtt); + String attName =3D current.getFeatureType().getAttributeType= (i).getName(); + if(!autoincrementColumns.contains(attName))=20 + queryData.write(i, currAtt); } =20 queryData.doInsert(); Modified: geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotoo= ls/data/jdbc/JDBCTextFeatureWriter.java =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/dat= a/jdbc/JDBCTextFeatureWriter.java 2006-12-29 16:55:04 UTC (rev 23629) +++ geotools/trunk/gt/modules/library/jdbc/src/main/java/org/geotools/dat= a/jdbc/JDBCTextFeatureWriter.java 2006-12-29 18:59:36 UTC (rev 23630) @@ -20,6 +20,10 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; +import java.util.Collection; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; =20 @@ -159,17 +163,33 @@ StringBuffer statementSQL =3D new StringBuffer("INSERT INTO " + = tableName + " ("); =20 + // either add statements to append non autoincrement colums, or = gather + // the auto-increment ones + Set autoincrementColumns =3D null; if (!mapper.returnFIDColumnsAsAttributes()) { + autoincrementColumns =3D Collections.EMPTY_SET; for (int i =3D 0; i < mapper.getColumnCount(); i++) { if (!mapper.isAutoIncrement(i)) { statementSQL.append(mapper.getColumnName(i)).append(= ","); } } + } else { + autoincrementColumns =3D new HashSet(); + for (int i =3D 0; i < mapper.getColumnCount(); i++) { + if (mapper.isAutoIncrement(i)) { + autoincrementColumns.add(mapper.getColumnName(i)); + } + } } =20 + // encode insertion for attributes, but remember to avoid auto-i= ncrement ones,=20 + // they may be included in the feature type as well for (int i =3D 0; i < attributeTypes.length; i++) { - String colName =3D encodeColumnName(attributeTypes[i].getName()= ); - statementSQL.append(colName).append(","); + String attName =3D attributeTypes[i].getName(); + if(!autoincrementColumns.contains(attName)) { + String colName =3D encodeColumnName(attName); + statementSQL.append(colName).append(","); + } } =20 statementSQL.setCharAt(statementSQL.length() - 1, ')'); @@ -195,15 +215,18 @@ Object[] attributes =3D feature.getAttributes(null); =20 for (int i =3D 0; i < attributeTypes.length; i++) { + attrValue =3D null; if (attributeTypes[i] instanceof GeometryAttributeType) { String geomName =3D attributeTypes[i].getName(); int srid =3D ftInfo.getSRID(geomName); attrValue =3D getGeometryInsertText((Geometry) attribute= s[i], srid); } else { - attrValue =3D addQuotes(attributes[i]); + if(!autoincrementColumns.contains(attributeTypes[i].getN= ame())) + attrValue =3D addQuotes(attributes[i]); } =20 - statementSQL.append(attrValue + ","); + if(attrValue !=3D null) + statementSQL.append(attrValue + ","); } =20 statementSQL.setCharAt(statementSQL.length() - 1, ')'); |