Skip to content

Commit 8c34c4f

Browse files
fpanizzaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:fix/AndroidAutoCommitExecuteCursor' into beta
1 parent ab992cb commit 8c34c4f

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

android/src/main/java/com/genexus/db/DataStoreProvider.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.sql.SQLException;
44
import java.util.Date;
5+
import java.util.concurrent.locks.ReentrantLock;
56

67
import com.genexus.*;
78
import com.genexus.db.driver.DataSource;
@@ -164,10 +165,41 @@ public void executeBatch(int cursorIdx)
164165
{
165166
execute(cursorIdx, null, false);
166167
}
168+
169+
static ReentrantLock lockExecute = new ReentrantLock();
170+
167171
public synchronized void execute(int cursorIdx, Object[] parms)
168172
{
169-
execute(cursorIdx, parms, true);
170-
}
173+
DataSource ds = getDataSourceNoException();
174+
if(ds!=null && ds.jdbcIntegrity==false)
175+
{
176+
// If the JDBC integrity is disabled, SQLIte is in autocommit mode.
177+
// we need to lock the execute method to avoid concurrency issues.
178+
// for example, the postExecute method (select changes()) cause exception in Android SQLite.
179+
AndroidLog.debug("execute cursorIdx : " + cursorIdx);
180+
long timeStamp = System.currentTimeMillis();
181+
lockExecute.lock();
182+
long timeStampLock2 = System.currentTimeMillis();
183+
AndroidLog.debug("START execute afterlock cursorIdx: " + cursorIdx + " Waiting time: " + (timeStampLock2 - timeStamp));
184+
try
185+
{
186+
// execute the cursor with the parameters.
187+
execute(cursorIdx, parms, true);
188+
}
189+
finally
190+
{
191+
lockExecute.unlock();
192+
}
193+
long timeStamp2 = System.currentTimeMillis();
194+
AndroidLog.debug("END execute cursorIdx: " + cursorIdx+ " Execute time: " + (timeStamp2 - timeStampLock2));
195+
}
196+
else
197+
{
198+
// default case, we execute the cursor with the parameters.
199+
execute(cursorIdx, parms, true);
200+
}
201+
202+
}
171203

172204
private void execute(int cursorIdx, Object[] parms, boolean preExecute)
173205
{

0 commit comments

Comments
 (0)