I'm trying to update records on db reding a shapefile.
I have to delete from db all records that have a certain code, and I
have to delete them while I'm reading the shape if when I find a code to
update.
 
The shapefile and the Oracle DB table have the same fields. The DB table
have only a primary-key autoincrement more than the shp.
 
The problem is that I need to do it during a trsaction but DB finish
resources (cursors) after almost 300 insert.
 
The method is this:
 
 
/**

* This method load all records of a shape file into the data store of
the layer.

* The shape file and the table on Oracle have the same fields. The
Oracle table

* have only an autoincrement field that is the primary key.

* 

* Before loading a shape record with a certain cod if it has never been
deleted from

* DB, all records on DB with that cod are deleted.

* 

* @param shpFile

* @param trans

* @throws SITException

*/

public void caricaVarianti(File shpFile, org.geotools.data.Transaction
trans) throws SITException { 

FeatureWriter aWriter = null;

FeatureReader frShp = null;

try {

String solonome = shpFile.getName(); 

String shpTypeName = solonome.substring(0,solonome.length()-4);

// Oracle datastore of this layer 

DataStore ds = getDataStore(); 

FeatureSource fs = ds.getFeatureSource(configBean.getTypeName());

if(!(fs instanceof FeatureStore)){

throw new SITException("Modifiche non consentite sul layer");

}

FeatureStore fst = (FeatureStore) fs;

fst.setTransaction(trans);

// Open shape data source

String dsParams = "url;";

URL anURL = shpFile.toURL();

String shpFactory =
"org.geotools.data.shapefile.ShapefileDataStoreFactory"; 

dsParams += anURL;

// construct a shp datastore

DataStore dsShp = configBean.getDsPool().openDataStore(dsParams,
shpFactory, false) ;

// Retrieve all records on the shapefile

Query quSHP = new DefaultQuery(shpTypeName,Filter.NONE); 

frShp = dsShp.getFeatureReader(quSHP, trans); 

FeatureType ftSHP = dsShp.getSchema(shpTypeName); 

List attnamesSHP = Schema.names(ftSHP); 

List<Integer> removedNum = new ArrayList<Integer>();

Feature shpFeat = null;

Feature aNewFeature = null;

aWriter = ds.getFeatureWriterAppend(configBean.getTypeName(), trans);

// all shape records

while (frShp.hasNext()) {

shpFeat = frShp.next(); 

aNewFeature = aWriter.next();

// copy of all fields (schema are identical)

for (int i=0; i < attnamesSHP.size(); i++) {

if (!(ftSHP.getAttributeType(i) instanceof GeometryAttributeType)) {

String szAtNameSHP = attnamesSHP.get(i).toString();

String szAtNameDest = attnamesSHP.get(i).toString();

// removing all records with this COD from DB

if(szAtNameDest != null && szAtNameDest.equals("VARIANTENUM")){

// get the record cod

int varianteNum =
Integer.parseInt(shpFeat.getAttribute(szAtNameDest).toString());

// if it has not been removed anymore

if(!removedNum.contains(varianteNum)){

Filtro f = getFiltroVuoto();

f.AndFiltro(Costanti.NL_VARIANTIRU_NVARIANTE, varianteNum, "=");

fst.removeFeatures(f.getFiltro());

removedNum.add(new Integer(varianteNum));

}

}

aNewFeature.setAttribute(szAtNameSHP
,shpFeat.getAttribute(szAtNameDest)); 

}

}

aNewFeature.setDefaultGeometry(shpFeat.getDefaultGeometry()); 

aWriter.write(); 

} 

} catch (IOException e) {

logger.error("Errore di acceso ai dati ", e);

throw new SITException("Errore accesso dati",e);

} catch (IllegalAttributeException e) {

logger.error("Problemi con la struttura del sorgente dati", e);

throw new SITException("Problemi con la struttura del sorgente dati",e);


}finally{ 

if(frShp != null){

try{

frShp.close();

}catch(IOException ioe){

logger.error("Errore durante la chiusura del FeatureReader",ioe);

}

} 

if(aWriter != null){

try{

aWriter.close();

}catch(IOException ioe){

logger.error("Errore durante la chiusura del FeatureWriter",ioe);

}

} 

}

}

 

Th error :

 

12:42:05 prova            0.0.0.0          ERROR
LayerVariantiRu[caricaVarianti]  Errore di acceso ai dati 
org.geotools.data.DataSourceException: SQL Exception writing geometry
columnORA-29925: impossibile eseguire
MDSYS.SDO_INDEX_METHOD_10I.ODCIINDEXINSERT
ORA-22303: tipo "SYS"."ODCICOLINFO" non trovato
ORA-01000: numero massimo di cursori aperti superato
ORA-01000: numero massimo di cursori aperti superato

 at
org.geotools.data.jdbc.JDBCTextFeatureWriter.doInsert(JDBCTextFeatureWri
ter.java:107)
 at
org.geotools.data.jdbc.JDBCFeatureWriter.write(JDBCFeatureWriter.java:21
9)
 at
org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManage
r.java:330)
 at
it.prato.comune.sit.LayerVariantiRu.caricaVarianti(LayerVariantiRu.java:
201)
 at
prove.TestVariantiRUUtente.testCaricamentoSHP(TestVariantiRUUtente.java:
66)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at
org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethod
Runner.java:99)
 at
org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRun
ner.java:81)
 at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAf
terRunner.java:34)
 at
org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.j
ava:75)
 at
org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45
)
 at
org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestC
lassMethodsRunner.java:66)
 at
org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRu
nner.java:35)
 at
org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRun
ner.java:42)
 at
org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAf
terRunner.java:34)
 at
org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
 at
org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4Tes
tReference.java:38)
 at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.ja
va:38)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:460)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTe
stRunner.java:673)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRun
ner.java:386)
 at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRu
nner.java:196)
Caused by: java.sql.SQLException: ORA-29925: impossibile eseguire
MDSYS.SDO_INDEX_METHOD_10I.ODCIINDEXINSERT
ORA-22303: tipo "SYS"."ODCICOLINFO" non trovato
ORA-01000: numero massimo di cursori aperti superato
ORA-01000: numero massimo di cursori aperti superato

 at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:11
2)
 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
 at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
 at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:207)
 at
oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:946)
 at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.
java:1168)
 at
oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement
.java:1614)
 at
oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:15
79)
 at
org.geotools.data.jdbc.JDBCTextFeatureWriter.doInsert(JDBCTextFeatureWri
ter.java:94)
 ... 24 more


-------------------------------------------------------------------------
SF.Net email is sponsored by:
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Geotools-gt2-users mailing list
Geotools-gt2-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to