Problemas com performance de consumo de web service com grande volume de dados

0 respostas
aboult

Pessoal, bom dia.

Estou tendo problemas com consumo de web services com grande volume de dados.
Eu tenho vários web métodos que são chamados pelo aplicativo e eu tenho um processo de importação onde ele chama método a método e vai recebendo as informações e persistindo no banco.

Anteriormente estava utilizando os métodos de inserção, update e select através do SQLiteDataBase. (query, insert, delete, update).

Mas conforme pesquisei encontrei que abrindo e encerrando a transação e utilizando o SQLiteStatement para compilar uma query antes e utilizá-la para carregar os dados no banco era muito mais rápido, mas ainda acho que pode ficar mais rápido, alguém já fez algo semelhante?

Processo de importação está assim hoje:

DataBase = new DadosBD(Singleton.getContextoAplicacao());
			SoapObject request = new SoapObject(this.getWsNameSpace(), this.getWsNomeMetodo());
			request.addProperty("representante", WsRepresentante);
			SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
			envelope.dotNet = true;
			envelope.implicitTypes = false;
			envelope.setOutputSoapObject(request);
			
			HttpTransportSE httpTransport = new HttpTransportSE(this.getWsUrl());
			httpTransport.call(this.getWsNameSpace() + "" + this.getWsNomeMetodo(), envelope);
			SoapObject result = (SoapObject) envelope.getResponse();
			
			if (result != null) {
				
				int resultCount = result.getPropertyCount();
				
				if(resultCount > 0){
					
					SoapObject objResult = new SoapObject();
					SoapObject objSoap = new SoapObject();
	
					objResult = (SoapObject) result.getProperty(1);
					if(objResult.getPropertyCount() > 0){
						
						objSoap = (SoapObject) objResult.getProperty(0);
						int propertyResultCount = objSoap.getPropertyCount();
		                
		                if (propertyResultCount > 0){

		                	DataBase.BeginTransaction();
		                	
		                	SQLiteStatement stmtInsert = DataBase.getDataBase().compileStatement(DataBase.ExecInsertBuilder(Tabela, TabelaColunaComposta));
		                	SQLiteStatement stmtSelect = DataBase.getDataBase().compileStatement(DataBase.ExecSelectBuilder(false, Tabela, TabelaSelecaoArgumentos, TabelaSelecao, TabelaGroupBy, TabelaHaving, TabelaOrderBy, "1"));
		                	SQLiteStatement stmtUpdate = DataBase.getDataBase().compileStatement(DataBase.ExecUpdateBuilder(Tabela, TabelaColunaComposta, TabelaWhereArgumentos));
		                	
		                	this.Dados = new ContentValues();
		                	
		                	for (int currentProperty = 0; currentProperty < propertyResultCount; currentProperty++) {
			       	    		 
		                        SoapObject obj = (SoapObject) objSoap.getProperty(currentProperty);
		                        int attributeResultCount = obj.getPropertyCount();
		                        
		                        for(int index = 0; index < attributeResultCount; index++){
		                        	
		                        	PropertyInfo pi = new PropertyInfo();
		                        	obj.getPropertyInfo(index, pi);
		                        	stmtInsert.bindString(index + 1, ((pi.getValue().toString().equals("anyType{}")?(""):(pi.getValue().toString()))));
		                        	stmtUpdate.bindString(index + 1, ((pi.getValue().toString().equals("anyType{}")?(""):(pi.getValue().toString()))));
		                        	this.Dados.put(pi.name.toString(), ((pi.getValue().toString().equals("anyType{}")?(""):(pi.getValue().toString()))));
		                        }
		                        
		                        for (int i = 0; i < this.getCamposPK().length; i++) {
		                        	stmtSelect.bindString(i + 1, this.Dados.get(CamposPK[i].toString()).toString());
		                        }
		                        
		                        if(!(stmtSelect.simpleQueryForLong()==1)){
		                        	stmtInsert.executeInsert();
		                        }else{
		                        	stmtUpdate.execute();
		                        }
		                    }
		                	DataBase.SetTransaction();
		                	DataBase.EndTransaction();
		                }
					}
				}
			}

E eu monto as queries para serem compiladas dessa maneira:

public String ExecSelectBuilder(boolean distinct, String tables, String[] columns, String where, String groupBy, String having, String orderBy, String limit){
		
		return SQLiteQueryBuilder.buildQueryString(distinct, tables, columns, where, groupBy, having, orderBy, limit);
	}
	
	public String ExecInsertBuilder(String tabela, String[] campos){
		
		if (tabela == null || campos == null || campos.length == 0) {
	        throw new IllegalArgumentException();
	    }
		
	    final StringBuilder s = new StringBuilder();
	    s.append("INSERT INTO ").append(tabela).append(" (");
	    
	    for (String column : campos) {
	        s.append(column).append(" ,");
	    }
	    
	    int length = s.length();
	    s.delete(length - 2, length);
	    s.append(") VALUES( ");
	    
	    for (int i = 0; i < campos.length; i++) {
	        s.append(" ? ,");
	    }
	    
	    length = s.length();
	    s.delete(length - 2, length);
	    s.append(")");
	    
	    return s.toString();
	}
	
	public String ExecUpdateBuilder(String table, String[] columns, String[] where){
		
		if (table == null || columns == null || columns.length == 0) {
	        throw new IllegalArgumentException();
	    }
		
	    final StringBuilder s = new StringBuilder();
	    s.append("UPDATE ").append(table).append(" SET ");
		
	    for (String column : columns){
	    	s.append(column).append(" = ? ,");
	    }
	    
	    int length = s.length();
	    s.delete(length - 2, length);
	    s.append(" WHERE ");
	    
	    for (String columnWhere : where){
	    	s.append(columnWhere).append(" = ? AND ");
	    }

	    length = s.length();
	    s.delete(length - 4, length);
		
		return s.toString();
	}

Alguém teria alguma ideia?

Criado 26 de abril de 2013
Respostas 0
Participantes 1