From: <hip...@us...> - 2007-02-28 17:43:13
|
Sergio this is the code for the store table data modifiede from user. J use an array of DBSubset for the primary key and dbs for the original sel= ection of user for each row j store for each DBSubset[] the value and after upgrade table values and dbsubset original. =09public boolean[] StoreRemoteDataConnection(DBSubset dbs,DBSubset[]prikey= s,TableSC datiutente, =09=09=09=09=09=09=09=09=09=09=09JDCConnection connessione,String[]elencoch= iavi) =09=09=09=09=09=09=09=09=09=09=09{ =09=09=09//array che conterra indici di inizio per i campi di ogni tabella = presente nel tablesc =09=09=09int[] indiceinizio=3D new int[numerocampiselez.length]; =09=09=09boolean[] res =3D new boolean[indiceinizio.length]; =09=09=09indiceinizio[0]=3D0; =09=09=09for (int i=3D0;i<numerocampiselez.length-1;i++){ =09=09=09=09indiceinizio[i+1]=3Dindiceinizio[i]+numerocampiselez[i]; =09=09=09=09System.out.println("indiceinizio"+indiceinizio[i+1]); =09=09=09} =09=09=09//array che conterra indici di fine per i campi di ogni tabella pr= esente nel tablesc =09=09=09int[] indicefine =3D new int[numerocampiselez.length]; =09=09=09indicefine[0]=3Dnumerocampiselez[0]; =09=09=09for (int i=3D1;i<numerocampiselez.length;i++){ =09=09=09=09indicefine[i]=3Dindicefine[i-1]+numerocampiselez[i]; =09=09=09} =09=09=09 =09=09=09for (int i=3D0;i<pk.length;i++){ =09=09=09=09System.out.println("HipergateDB tabella "+i+"num pk=3D "+pk[i]+= "\n num campi selezionati "+numerocampiselez[i]); =09=09=09=09 =09=09=09} =09=09=09for(int i=3D0;i<elencochiavi.length;i++){ =09=09=09=09System.out.println("hipergateDB tabella "+i+" campi comprensivi= di chiave selezionati \n"+elencochiavi[i]); =09=09=09} =09=09=09int j=3D0,numrig,numcol; =09=09=09while(j<datiappoggio.length){ =09=09=09=09numrig=3Ddatiappoggio[j].getRowCount(); =09=09=09=09numcol=3Ddatiappoggio[j].getColumnCount(); =09=09System.out.println(" dbsubsetpk in hipergate righe =3D"+ numr= ig+"colonne =3D"+numcol); =09for(int i=3D0;i<numrig;i++){ =09=09for (int k=3D0;k<numcol;k++){ =09=09System.out.println("dbsubsetpk in hipergate tabelle"+= j+"PK riga "+i+" "+ =09=09=09=09datiappoggio[j].get(k, i)); =09= =09=09 =09=09} =09} =09=09=09=09j++; =09=09=09} =09=09=09//visualizzo la tabella con i dati prelevati da remoto e presenti= su DBSubset =09=09=09System.out.println("la tabella hipergate ha righe "+tabelladati.ge= tRowCount()+ =09=09=09=09=09" colonne "+tabelladati.getColumnCount()); =09=09=09 =09=09=09for(int i=3D0;i<tabelladati.getRowCount();i++){ =09=09for (int k=3D0;k<tabelladati.getColumnCount();k++){ =09=09System.out.println("in hipergate tabella riga "+i+" "+ =09=09=09=09tabelladati.getValueAt(i, k)); =09= =09=09 // =09tabelladati.setValueAt(datiletti.get(k, i), i, k); =09=09} =09} =09=09=09//stampo gli indici di inizio e fine per la tabella =09=09=09for (int i=3D0;i<indiceinizio.length;i++){ =09=09=09=09System.out.println("inizio "+indiceinizio[i]); =09=09=09} =09=09=09for (int i=3D0;i<indicefine.length;i++){ =09=09=09=09System.out.println("fine "+indicefine[i]); =09=09=09} =09=09=09//creo ciclo per update campi nei DBSubset di appoggio =09=09=09for(int i=3D0;i<indiceinizio.length;i++){ =09=09=09=09//chiamo il metodo per ogni DBSubset di appoggio presente=20 =09=09=09=09res[i]=3Daggiornadati(indiceinizio[i],indicefine[i],datiappoggi= o[i], =09=09=09=09=09=09=09tabelladati,numerocampiselez[i],pk[i],nomicampitabella= ); =09=09=09} =09=09return res;=09 =09=09 =09} =09/** =09 * metodo che esegue lo store dei dati modificati sulla tabella=20 =09 * @param inizio colonna inizio tabella =09 * @param fine colonna fine tabella =09 * @param subset DBSubset di appoggio con chiavi primarie e i campi sele= zionati=20 =09 * @param tabella tabella su cui l'utente opera e aggiorna i campi =09 * @param numerocampi numero campi selezionati dal'utente =09 * @param elencochiavi stringa con chiavi primarie separate da <code&= gt;,</code> =09 * @param nomicampi array con i nomi dei campi presenti sulla tabella =09 * @return true se le store sono andate a buon fine false altrimenti =09 */ =09private boolean aggiornadati(int inizio,int fine,DBSubset subset,TableSC= tabella, =09=09=09=09=09=09=09=09int numerocampi,String elencochiavi,String[] nomica= mpi){ =09=09try{=09=09=09 =09=09=09String[] listachiavi=3D elencochiavi.split(","); =09=09=09//inizializzo array di oggetti da aggiornare =09=09=09Object []valoriricerca=3Dnew Object[subset.getColumnCount()-numero= campi]; =09=09=09int numeropk=3Dsubset.getColumnCount()-numerocampi; =09=09=09String nometabella=3D listachiavi[0].split("[.]")[0]; =09=09=09 =09=09=09System.out.println("aggiornadati tabella "+nometabella); =09=09=09provafellows k=3D new provafellows(nometabella); =09=09=09//per ogni riga =09=09=09for (int i=3D0;i<tabella.getRowCount();i++){ =09=09=09=09//creo array di oggetti per la riga corrente da aggiornare =09=09=09=09for(int r=3D0;r<numeropk;r++){ =09=09=09=09=09valoriricerca[r]=3Dsubset.get(r, i); =09=09=09=09} =09=09=09=09// eseguo la load per ogni riga del dbsubset di appoggio =09=09=09=09k.load(oCon, valoriricerca); =09=09=09=09System.out.println("ho eseguito la load"); =09=09=09=09for(int j=3Dinizio;j<fine;j++){ =09=09=09=09=09//scrivo il campo con il valore presente nella tabella =09=09=09=09=09k.put(nomicampi[j],tabella.getValueAt(i, j)); =09=09=09=09} =09=09=09=09// salvo il record =09=09=09=09k.store(oCon);=09=09=09=09 =09=09=09=09System.out.println("ho eseguito la store"); =09=09=09} =09=09=09return true; =09=09}catch (SQLException sqle){ =09=09=09System.out.println ("Store: errore connessione DB."); =09=09=09return false; =09=09} catch(ArrayIndexOutOfBoundsException ioe) {=20 =09=09=09System.out.println("Store : array fuori limite valido.");=20 =09=09=09return false; =09=09} =09} Now the insert works whit this code for table preexisted, j have some proble for empty table =09private boolean inseriscidati(String[] valoriinseriti,int inizio,int fi= ne,DBSubset subset,TableSC tabella, =09=09=09int numerocampi,String elencochiavi,String[] nomicampi){ =09=09try{ =09=09=09String[] listachiavi=3D elencochiavi.split(","); =09=09=09//=09=09inizializzo array di oggetti da aggiornare =09=09=09Object []chiavidacreare=3Dnew Object[subset.getColumnCount()-numer= ocampi]; =09=09=09//array di oggetti per la load di appoggio dell'ultima riga =09=09=09Object []chiaviappoggio=3Dnew Object[subset.getColumnCount()-numer= ocampi]; =09=09=09int numeropk=3Dsubset.getColumnCount()-numerocampi; =09=09=09 =09=09=09System.out.println("inseriscidati numero di chiavi primarie "+nume= ropk); =09=09=09String nometabella=3D listachiavi[0].split("[.]")[0]; =09=09=09System.out.println("inseriscidati tabella "+nometabella); =09=09=09//=09=09System.out.println("classe per provafellows "+subset.getCl= ass()); =09=09=09provafellows k=3D new provafellows(nometabella); =09=09=09// se =E8 una tabella senza campi eseguo solo put =09=09=09if(tabella.getRowCount()=3D=3D0){ =09=09=09=09for(int j=3Dinizio;j<fine;j++){ =09=09=09=09=09//scrivo il campo con il valore presente nella tabella =09=09=09=09=09k.put(nomicampi[j],valoriinseriti[j]); =09=09=09=09=09System.out.println("inseriscidati put campo "+nomicampi[j]+"= valoriinseriti "+valoriinseriti[j]); =09=09=09=09} =09=09=09=09// =09scrivo i valori del pk generate =09=09=09=09for (int i=3D0;i<chiavidacreare.length;i++){ =09=09=09=09=09 =09=09=09=09=09k.put(pk[i].split("[.]")[1],chiavidacreare[i]); =09=09=09=09=09System.out.println("inseriscidati put campo "+pk[i].split("[= .]")[1]+" valoriinseriti "+chiavidacreare[i]); =09=09=09=09} =09=09=09=09// salvo il record =09=09=09=09boolean ris=3Dk.store(oCon); =09=09=09=09return ris; =09=09=09} =09=09=09for(int r=3D0;r<numeropk;r++){ =09=09=09=09chiaviappoggio[r]=3Dsubset.get(r, subset.getRowCount()-1); =09=09=09=09System.out.println("chiave di appoggio "+chiaviappoggio[r]); =09=09=09} =09=09=09//eseguo load di appoggio sull'ultima riga =09=09=09k.load(oCon, chiaviappoggio); =09=09=09System.out.println("inseriscidati load ultimo campo eseguita"); =09=09=09// genero l'array con le chiavi primarie =09=09=09for (int i=3D0;i<chiavidacreare.length;i++){ =09=09=09=09chiavidacreare[i]=3DGadgets.generateUUID(); =09=09=09=09System.out.println("la chiave creata =E8 "+chiavidacreare[i]); =09=09=09} =09=09=09=09=09 =09=09=09//scrivo i valori inseriti dall'utente =09=09=09for(int j=3Dinizio;j<fine;j++){ =09=09=09=09//scrivo il campo con il valore presente nella tabella =09=09=09=09k.put(nomicampi[j],valoriinseriti[j]); =09=09=09=09System.out.println("inseriscidati put campo "+nomicampi[j]+" va= loriinseriti "+valoriinseriti[j]); =09=09=09} =09=09=09// =09scrivo i valori del pk generate =09=09=09for (int i=3D0;i<chiavidacreare.length;i++){ =09=09=09=09 =09=09=09=09k.put(pk[i].split("[.]")[1],chiavidacreare[i]); =09=09=09=09System.out.println("inseriscidati put campo "+pk[i].split("[.]"= )[1]+" valoriinseriti "+chiavidacreare[i]); =09=09=09} =09=09=09// salvo il record =09=09=09boolean ris=3Dk.store(oCon); =09=09=09 =09=09=09System.out.println("inseriscidati ho eseguito la store esito "+ris= ); =09=09}catch (SQLException sqe){ =09=09=09System.out.println ("inseriscidati : errore connessione DB."); =09=09=09return false; =09=09} =09=09return true; =09} |