Skip to content

Commit 901c844

Browse files
committed
Flush batch cursors buffers at the end of procedures
(cherry picked from commit fce0515) Reopen branch and temporary comment flushBuffers at ServerUserInformation (cherry picked from commit 8c59220) Minor to force merge (cherry picked from commit 3fc78be) Flush batch cursors buffers at the end of procedures only if is the procedure that own the cursors (cherry picked from commit 731ace1) Replace done for toRemove thus it removes only the right cursors (cherry picked from commit e6c5ec5)
1 parent dbaceba commit 901c844

File tree

14 files changed

+154
-40
lines changed

14 files changed

+154
-40
lines changed

android/src/main/java/com/genexus/db/driver/GXConnection.java

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.sql.Struct;
1818
import java.util.ArrayList;
1919
import java.util.Properties;
20+
import java.util.Vector;
2021
import java.util.concurrent.Executor;
2122

2223
import com.genexus.Application;
@@ -652,22 +653,27 @@ public void rollback() throws SQLException
652653
}
653654
}
654655

655-
private void commit_impl() throws SQLException
656-
{
657-
dataSource.dbms.commit(con);
658-
}
656+
private void commit_impl() throws SQLException
657+
{
658+
dataSource.dbms.commit(con);
659+
}
660+
661+
public void flushBatchCursors(java.lang.Object o) throws SQLException{
662+
Vector<Cursor> toRemove = new Vector();
663+
for (int i = 0; i < batchUpdateStmts.size(); i++) {
664+
BatchUpdateCursor cursor = (BatchUpdateCursor) batchUpdateStmts.get(i);
665+
if (cursor.pendingRecords()) {
666+
if (cursor.beforeCommitEvent(o))
667+
toRemove.add(cursor);
668+
}
669+
}
670+
if (toRemove.size()>0)
671+
batchUpdateStmts.removeAll(toRemove);
672+
}
659673

660674
public void commit() throws SQLException
661675
{
662-
663-
for(int i=0; i<batchUpdateStmts.size(); i++)
664-
{
665-
BatchUpdateCursor cursor = (BatchUpdateCursor)batchUpdateStmts.get(i);
666-
if (cursor.pendingRecords()){
667-
cursor.beforeCommitEvent();
668-
}
669-
}
670-
batchUpdateStmts.clear();
676+
flushBatchCursors(null);
671677

672678
if (DEBUG)
673679
{

common/src/main/java/com/genexus/common/classes/AbstractGXConnection.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ public abstract class AbstractGXConnection {
2828

2929
public abstract void commit() throws SQLException ;
3030

31+
public abstract void flushBatchCursors(java.lang.Object o) throws SQLException;
32+
3133
public abstract String getUserName() throws SQLException;
3234

3335
public abstract Date getDateTime() throws SQLException ;

common/src/main/java/com/genexus/db/BatchUpdateCursor.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,18 @@ public boolean pendingRecords() {
205205
return mPreparedStatement.getRecordCount() > 0;
206206
}
207207

208-
public void beforeCommitEvent() throws SQLException {
209-
try {
210-
DynamicExecute.dynamicInstaceExecute(mPreparedStatement.getOnCommitInstance(),
208+
public boolean beforeCommitEvent(java.lang.Object o) throws SQLException {
209+
boolean done = false;
210+
if (o == null || o == mPreparedStatement.getOnCommitInstance()) {
211+
try {
212+
DynamicExecute.dynamicInstaceExecute(mPreparedStatement.getOnCommitInstance(),
211213
mPreparedStatement.getOnCommitMethod(), null);
212-
} catch (Exception ex) {
213-
throw new SQLException(ex.getMessage());
214+
done = true;
215+
} catch (Exception ex) {
216+
throw new SQLException(ex.getMessage());
217+
}
214218
}
215-
219+
return done;
216220
}
217221

218222
public Object[] getBlockRecords() {

java/src/main/java/com/genexus/GXProcedure.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ protected void exitApplication()
140140
{
141141
if(dbgInfo != null && Application.realMainProgram == this)
142142
dbgInfo.onExit();
143+
try
144+
{
145+
Application.getConnectionManager().flushBuffers(remoteHandle, this);
146+
}catch(Exception exception){ ; }
143147
if(disconnectUserAtCleanup)
144148
{
145149
try

java/src/main/java/com/genexus/db/DBConnectionManager.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,19 @@ private void unsuscribeJMX(UserInformation ui) {
284284
LocalUserInformationJMX.DestroyLocalUserInformationJMX((LocalUserInformation)ui);
285285
}
286286
}
287+
public void flushBuffers(int handle, java.lang.Object o) throws SQLException, NullPointerException
288+
{
289+
UserInformation ui = getUserInformation(handle);
290+
291+
try
292+
{
293+
if (ui != null) {
294+
ui.flushBuffers(o);
295+
}
296+
}
297+
finally{
298+
}
299+
}
287300

288301
public void disconnect(int handle) throws SQLException, NullPointerException
289302
{

java/src/main/java/com/genexus/db/LocalUserInformation.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,24 @@ public void disconnect() throws SQLException
113113
}
114114
}
115115
}
116+
public void flushBuffers(java.lang.Object o) throws SQLException
117+
{
118+
for (Enumeration<ConnectionInformation> en = connections.elements(); en.hasMoreElements(); )
119+
{
120+
ConnectionInformation info = en.nextElement();
121+
if (info.rwConnection != null)
122+
{
123+
try
124+
{
125+
info.rwConnection.flushBatchCursors(o);
126+
}
127+
catch (SQLException e)
128+
{
129+
System.err.println("Error while flushing cursor " + e.getMessage());
130+
}
131+
}
132+
}
133+
}
116134

117135
public void disconnectOnException() throws SQLException
118136
{

java/src/main/java/com/genexus/db/ServerUserInformation.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,18 @@ public void disconnect() throws SQLException
6363
catch (Throwable e)
6464
{
6565
}
66-
}
66+
}
67+
6768

69+
if (disconnectException != null)
70+
throw disconnectException;
71+
}
6872

69-
if (disconnectException != null)
70-
throw disconnectException;
73+
public void flushBuffers(java.lang.Object o) throws SQLException
74+
{
75+
for (Enumeration<DataSource> en = namespace.getDataSources(); en.hasMoreElements(); ) {
76+
en.nextElement().flushBuffers(handle, o);
77+
}
7178
}
7279

7380
public boolean isConnected(String dataSourceName)

java/src/main/java/com/genexus/db/UserInformation.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public abstract class UserInformation extends AbstractUserInformation
1616
{
1717
public abstract void disconnectOnException() throws SQLException;
1818
public abstract void disconnect() throws SQLException;
19+
public abstract void flushBuffers(java.lang.Object o) throws SQLException;
1920

2021
private ConcurrentHashMap<String, Integer> orbHandles = new ConcurrentHashMap<String, Integer>();
2122
private ConcurrentHashMap<String, String> properties = new ConcurrentHashMap<String, String>();

java/src/main/java/com/genexus/db/UtilUserInformation.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ protected void putConnection(String dataSourceName, GXConnection rwConnection, G
5252
public void disconnect() throws SQLException
5353
{
5454
}
55-
55+
public void flushBuffers(java.lang.Object o) throws SQLException {
56+
}
5657
public void disconnectOnException() throws SQLException
5758
{
5859
}

java/src/main/java/com/genexus/db/driver/DataSource.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,25 @@ public void disconnectOnException(int handle) throws SQLException
474474
}
475475
}
476476

477+
public void flushBuffers(int handle, java.lang.Object o) throws SQLException
478+
{
479+
if (connectionPools.size() == 0)
480+
{
481+
getConnectionPool().flushBuffers(handle, o);
482+
}
483+
else {
484+
for (Enumeration en = connectionPools.elements(); en.hasMoreElements(); ) {
485+
ConnectionPool connPool = ((ConnectionPool) en.nextElement());
486+
for (Enumeration en1 = connPool.getConnections(); en1.hasMoreElements(); ) {
487+
GXConnection conn = (GXConnection) en1.nextElement();
488+
if (conn.getHandle() == handle) {
489+
conn.flushBatchCursors(o);
490+
}
491+
}
492+
}
493+
}
494+
}
495+
477496
public boolean getRWPoolEnabled()
478497
{
479498
return rwPoolEnabled;

0 commit comments

Comments
 (0)