Skip to content

Commit 3b57117

Browse files
authored
Error handler rule was not implemented in a SQL Statement context in … (#594)
* Error handler rule was not implemented in a SQL Statement context in Java. Issue: 72730 * Error handler rule was not implemented in a SQL Statement context in Java. Issue: 72730 * Error handler rule was not implemented in a SQL Statement context in Java. Issue: 72730
1 parent 966f490 commit 3b57117

File tree

5 files changed

+54
-19
lines changed

5 files changed

+54
-19
lines changed

android/src/main/java/com/genexus/specific/android/Application.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
import com.genexus.common.interfaces.IClientPreferences;
1212
import com.genexus.common.interfaces.IExtensionApplication;
1313
import com.genexus.common.interfaces.IPreferences;
14-
import com.genexus.db.DBConnectionManager;
15-
import com.genexus.db.Namespace;
14+
import com.genexus.db.*;
1615
import com.genexus.internet.HttpResponse;
1716
import com.genexus.util.IniFile;
1817
import com.genexus.wrapper.GXCollectionWrapper;
@@ -97,6 +96,10 @@ public boolean handlSQLException(int handle, String dataSource, SQLException ex)
9796
return com.genexus.Application.getConnectionManager().getDataSource(handle, dataSource).dbms.ObjectNotFound(ex);
9897
}
9998

99+
@Override
100+
public void handleSQLError(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, AbstractGXConnection conn, String datastoreName, Cursor cursor) {
101+
}
102+
100103
@Override
101104
public Class getModelContextClass() {
102105
return ModelContext.class;

common/src/main/java/com/genexus/ExecuteDirectSQL.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@
22

33
import java.sql.SQLException;
44

5-
import com.genexus.ModelContext;
5+
import com.genexus.common.classes.AbstractGXConnection;
66
import com.genexus.common.interfaces.SpecificImplementation;
77
import com.genexus.db.*;
88
import com.genexus.util.*;
99

1010
public class ExecuteDirectSQL
1111
{
1212
public static void execute(ModelContext context, int handle, String dataSource, String Statement)
13+
{
14+
execute(context, handle, dataSource, Statement, null);
15+
}
16+
17+
public static void execute(ModelContext context, int handle, String dataSource, String statement, IErrorHandler errorHandler)
1318
{
1419
try
1520
{
16-
SpecificImplementation.Application.executeStatement(context, handle, dataSource, Statement);
21+
SpecificImplementation.Application.executeStatement(context, handle, dataSource, statement);
1722
}
1823
catch (SQLException ex)
1924
{
@@ -27,7 +32,21 @@ public static void execute(ModelContext context, int handle, String dataSource,
2732
}
2833
else
2934
{
30-
SpecificImplementation.Application.GXLocalException(handle, "ExecuteDirectSQL/" + Statement, ex);
35+
if (errorHandler == null)
36+
{
37+
SpecificImplementation.Application.GXLocalException(handle, "ExecuteDirectSQL/" + statement, ex);
38+
}
39+
else
40+
{
41+
try {
42+
AbstractGXConnection conn = new DefaultConnectionProvider().getConnection(context, handle, dataSource, true, true);
43+
SpecificImplementation.Application.handleSQLError(errorHandler, ex, context, handle, conn, dataSource, new DirectStatement(statement));
44+
}
45+
catch (SQLException e) {
46+
throw new GXRuntimeException(e);
47+
}
48+
}
49+
3150
}
3251
}
3352
}

common/src/main/java/com/genexus/common/interfaces/IExtensionApplication.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package com.genexus.common.interfaces;
22

33
import java.sql.SQLException;
4-
import com.genexus.GXDBException;
5-
import com.genexus.ICleanedup;
6-
import com.genexus.ModelContext;
7-
import com.genexus.SdtMessages_Message;
4+
5+
import com.genexus.*;
86
import com.genexus.common.classes.AbstractGXConnection;
97
import com.genexus.ModelContext;
108
import com.genexus.common.classes.AbstractNamespace;
119
import com.genexus.common.classes.AbstractUserInformation;
1210

11+
import com.genexus.db.Cursor;
1312
import com.genexus.util.IniFile;
1413

1514
public interface IExtensionApplication {
@@ -43,6 +42,8 @@ public interface IExtensionApplication {
4342

4443
boolean handlSQLException(int handle, String dataSource, SQLException ex);
4544

45+
void handleSQLError(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, AbstractGXConnection conn, String datastoreName, Cursor cursor);
46+
4647
Class<?> getModelContextClass();
4748

4849
ModelContext createModelContext(Class<SdtMessages_Message> class1);

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import com.genexus.GXRuntimeException;
66
import com.genexus.IErrorHandler;
77
import com.genexus.ModelContext;
8+
import com.genexus.common.classes.AbstractGXConnection;
89
import com.genexus.db.driver.GXDBMS;
910
import com.genexus.util.ReorgSubmitThreadPool;
1011

@@ -22,7 +23,16 @@ public class DefaultExceptionErrorHandler
2223

2324
public static void handleSQLError(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, IDataStoreHelper helper, Cursor cursor)
2425
{
25-
cursor.status = mapErrorToStatus(DBConnectionManager.getInstance().getUserInformation(remoteHandle).getNamespace().getDataSource(helper.getDataStoreName()).dbms, e);
26+
try {
27+
AbstractGXConnection conn = helper.getConnectionProvider().getConnection(context, remoteHandle, helper.getDataStoreName(), true, true);
28+
handleSQLError1(errorHandler, e, context, remoteHandle, conn, helper.getDataStoreName(), cursor);
29+
}
30+
catch (SQLException exc) {}
31+
}
32+
33+
public static void handleSQLError1(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, AbstractGXConnection conn, String datastoreName, Cursor cursor)
34+
{
35+
cursor.status = mapErrorToStatus(DBConnectionManager.getInstance().getUserInformation(remoteHandle).getNamespace().getDataSource(datastoreName).dbms, e);
2636
if (cursor.status != Cursor.DUPLICATE)
2737
{
2838
ReorgSubmitThreadPool.setAnError();
@@ -48,16 +58,13 @@ public static void handleSQLError(IErrorHandler errorHandler, SQLException e, Mo
4858

4959
if (context.globals.Gx_eop == ERROPT_DEFAULT)
5060
{
51-
defaultSQLErrorHandler(errorHandler, e, context, remoteHandle, helper, cursor);
61+
defaultSQLErrorHandler(context, cursor);
5262
}
5363

5464
if (context.globals.Gx_eop == ERROPT_CANCEL)
5565
{
56-
com.genexus.Application.rollback(context, remoteHandle, helper.getDataStoreName(), null);
57-
try {
58-
helper.getConnectionProvider().getConnection(context, remoteHandle, helper.getDataStoreName(), true, true).setError();
59-
}
60-
catch (SQLException exc) {}
66+
com.genexus.Application.rollback(context, remoteHandle, datastoreName, null);
67+
conn.setError();
6168
throw new GXRuntimeException(e);
6269
}
6370
}
@@ -101,7 +108,7 @@ private static int mapErrorToStatus(GXDBMS dbms, SQLException e)
101108
return Cursor.UNEXPECTED_DBMS_ERROR;
102109
}
103110

104-
public static void defaultSQLErrorHandler(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, IDataStoreHelper helper, Cursor cursor)
111+
public static void defaultSQLErrorHandler(ModelContext context, Cursor cursor)
105112
{
106113
context.globals.Gx_eop = ERROPT_CANCEL;
107114

java/src/main/java/com/genexus/specific/java/Application.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import com.genexus.common.interfaces.IClientPreferences;
1111
import com.genexus.common.interfaces.IExtensionApplication;
1212
import com.genexus.common.interfaces.IPreferences;
13-
import com.genexus.db.DBConnectionManager;
14-
import com.genexus.db.Namespace;
13+
import com.genexus.db.*;
14+
import com.genexus.db.Cursor;
1515
import com.genexus.internet.HttpResponse;
1616
import com.genexus.util.IniFile;
1717
import com.genexus.webpanels.GXWebObjectStub;
@@ -98,6 +98,11 @@ public boolean handlSQLException(int handle, String dataSource, SQLException ex)
9898
return com.genexus.Application.getConnectionManager().getDataSource(handle, dataSource).dbms.ObjectNotFound(ex);
9999
}
100100

101+
@Override
102+
public void handleSQLError(IErrorHandler errorHandler, SQLException e, ModelContext context, int remoteHandle, AbstractGXConnection conn, String datastoreName, Cursor cursor) {
103+
DefaultExceptionErrorHandler.handleSQLError1(errorHandler, e, context, remoteHandle, conn, datastoreName, cursor);
104+
}
105+
101106
@Override
102107
public Class getModelContextClass() {
103108
return ModelContext.class;

0 commit comments

Comments
 (0)