diff --git a/java/CloudServices.config b/java/CloudServices.config new file mode 100644 index 000000000..ea67a564a --- /dev/null +++ b/java/CloudServices.config @@ -0,0 +1,8 @@ + + + + GXTEST + DataAccess + com.genexus.db.driver.GXDBMSGxTest + + \ No newline at end of file diff --git a/java/client.cfg b/java/client.cfg new file mode 100644 index 000000000..6038218d9 --- /dev/null +++ b/java/client.cfg @@ -0,0 +1,183 @@ +[Client] +MODEL_NUM= 2 +GENERATOR_NUM= 12 +LOGIN_AS_USERID=0 +SMTP_HOST= +NAME_SPACE= com.mockdb +NAME_HOST= +CORBA_SERVER_NAME= +DCOM_GUID= +CONN_TIMEOUT=300 +HELP_MODE=WINHTML +HELP_BASEURL= +PREFERRED_UI=BEST +JFC_LF=NATIVE +CALENDAR=1 +CALC=1 +WP_RESIZE=1 +SHOW_STATUS=1 +FIELD_EXIT=Tab +ESCAPE_FUNCTION=Exit_form +KEY_REFRESH=5 +KEY_PROMPT=4 +MDI_FORMS=1 +REMOTE_CALLS=NEVER +IMAGE_SUBST=0 +CS_CONNECT=First +CS_REORG=1 +CS_REORGJAVA=1 +SUBFILE_ORDER=Y +FC_READONLY=GRAYED +PACKAGE=com.mockdb +DECIMAL_POINT=. +DATE_FMT= DMY +CTOD_DATE_FMT= L +BLANK_EMPTY_DATE=0 +TIME_FMT=12 +YEAR_LIMIT=40 +COMPRESS_HTML=1 +DocumentType=HTML5 +IE_COMPATIBILITY_VIEW=EmulateIE7 +EXPOSE_METADATA= 0 +WEB_IMAGE_DIR=/static +HTTP_BACKEND_URL= +WEB_STATIC_DIR= +ORQ_CLIENT_URL= +ORQ_SERVER_DIR= +TMPMEDIA_DIR=PrivateTempStorage +PRINT_LAYOUT_METADATA_DIR=LayoutMetadata +HTTP_PROTOCOL=Unsecure +SAMESITE_COOKIE=Lax +StorageTimeZone= 1 +GX_BUILD_NUMBER=17233991 +ODBC_CALLS=0 +NameSpace1= com.mockdb +LANGUAGE=German +LANG_NAME=German +Theme=Carmine +CS_BLOB_PATH=PublicTempStorage +SUBMIT_POOL_SIZE=5 +CACHE_TTL_0=-1 +CACHE_TTL_1=60 +CACHE_TTL_2=600 +CACHE_TTL_3=0 +CACHE_STORAGE_SIZE=0 +CACHING=0 +SMART_CACHING=0 +CACHE_INVALIDATION_TOKEN=202231018204023 +EVENT_BEFORE_COMMIT= +EVENT_AFTER_COMMIT= +EVENT_BEFORE_ROLLBACK= +EVENT_AFTER_ROLLBACK= +EVENT_BEFORE_CONNECT= +EVENT_AFTER_CONNECT= +ENABLE_MANAGEMENT=0 +EnableIntegratedSecurity=0 +IntegratedSecurityLoginWeb= +IntegratedSecurityNotAuthorizedWeb= +HTTPCLIENT_MAX_SIZE=1000 +HTTPCLIENT_MAX_PER_ROUTE=1000 +VER_STAMP=20220103.214234 +[language|English] +code= eng +time_fmt= 12 +decimal_point= . +thousand_sep= , +date_fmt= MDY +culture= en-US +[language|German] +code= German +time_fmt= 12 +decimal_point= . +thousand_sep= , +date_fmt= DMY +culture= de-DE +[language|TraditionalChinese] +code= cht +time_fmt= 24 +decimal_point= . +thousand_sep= , +date_fmt= YMD +culture= zh-TW +[language|SimplifiedChinese] +code= chs +time_fmt= 24 +decimal_point= . +thousand_sep= , +date_fmt= YMD +culture= zh-CN +[language|Spanish] +code= spa +time_fmt= 24 +decimal_point= , +thousand_sep= . +date_fmt= DMY +culture= es-ES +[language|Japanese] +code= jap +time_fmt= 24 +decimal_point= . +thousand_sep= , +date_fmt= YMD +culture= ja-JP +[language|Portuguese] +code= por +time_fmt= 24 +decimal_point= , +thousand_sep= . +date_fmt= DMY +culture= pt-BR +[language|Italian] +code= ita +time_fmt= 24 +decimal_point= , +thousand_sep= . +date_fmt= DMY +culture= it-IT +[language|Arabic] +code= Arabic +time_fmt= 24 +decimal_point= , +thousand_sep= . +date_fmt= DMY +culture= ar-SA +[com.mockdb] +GXDB_LOCATION= +JTA=0 +DataSource1=DEFAULT +JDBC_LOG= c:\temp\UTL.log +JDBCLogEnabled=1 +JDBCUniqueName=0 +JDBCLogPath= +JDBCLogLevel=0 +JDBCLogBuffer=0 +JDBCLogDetail=0 +[com.mockdb|DEFAULT] +CS_DBNAME= +INFORMIX_DB=ANSI +CS_LIBL400= +CS_PACKAGE400= +DB2400_DATE_DATATYPE= +CS_SCHEMA= +USER_ID=G8xdg8k/gK9eOCDgU75tkr== +USER_PASSWORD=4gPZ5cDtMVud7diJ/gIVrg== +CS_CONNECT=First +WAIT_RECORD=0 +LOCK_RETRY=10 +LoginInServer=1 +JDBC_DRIVER=org.sqlite.JDBC +DB_URL=jdbc:sqlite:sample.db +USE_JDBC_DATASOURCE=0 +JDBC_DATASOURCE= +MAX_CURSOR=100 +INITIALIZE_NEW=1 +ISOLATION_LEVEL=CR +XBASE_TINT=1 +DBMS=sqlserver +UnlimitedRWPool=1 +PoolRWEnabled=1 +RecycleRW=1 +RecycleRWType=1 +RecycleRWMin=30 +POOLSIZE_RW=10 +POOL_STARTUP=0 diff --git a/java/pom.xml b/java/pom.xml index d26079809..320b93a27 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -255,6 +255,11 @@ 3.0.0 + org.xerial + sqlite-jdbc + 3.36.0.3 + + com.microsoft.sqlserver mssql-jdbc 10.2.0.jre8 diff --git a/java/sample.db b/java/sample.db new file mode 100644 index 000000000..98160152f Binary files /dev/null and b/java/sample.db differ diff --git a/java/src/main/java/com/genexus/db/driver/DataSource.java b/java/src/main/java/com/genexus/db/driver/DataSource.java index c93db018c..1ea9eecf9 100644 --- a/java/src/main/java/com/genexus/db/driver/DataSource.java +++ b/java/src/main/java/com/genexus/db/driver/DataSource.java @@ -4,10 +4,16 @@ import java.util.Enumeration; import java.util.Hashtable; +import com.genexus.Application; import com.genexus.common.classes.AbstractDataSource; +import com.genexus.diagnostics.core.ILogger; +import com.genexus.diagnostics.core.LogManager; +import com.genexus.util.GXService; +import com.genexus.util.GXServices; public class DataSource extends AbstractDataSource { + public static final ILogger logger = LogManager.getLogger(DataSource.class); public static String INFORMIX_DB_ANSI = "ANSI"; public static String INFORMIX_DB_LOGGED = "Logged"; public static String INFORMIX_DB_NOTLOGGED = "NotLogged"; @@ -310,6 +316,20 @@ private void setDBMS(String dbmsName) { throw new InternalError("Unrecognized DBMS in configuration file : " + dbmsName + " / " + className); } + GXService providerService = Application.getGXServices().get(GXServices.DATA_ACCESS_SERVICE); + if (providerService != null) + { + String providerClassName = providerService.getClassName(); + try + { + logger.info("Loading providerService:" + providerClassName); + dbms = (GXDBMS) Class.forName(providerClassName).getConstructor(new Class[] {GXDBMS.class}).newInstance(new Object[] {dbms}); + } + catch(Exception ex) + { + logger.error("Couldn't create DATA_ACCESS_PROVIDER as : " + providerClassName, ex); + } + } } public synchronized IConnectionPool getConnectionPool() diff --git a/java/src/main/java/com/genexus/db/driver/GXCallableStatement.java b/java/src/main/java/com/genexus/db/driver/GXCallableStatement.java index 703c379b5..d81aa9ad6 100644 --- a/java/src/main/java/com/genexus/db/driver/GXCallableStatement.java +++ b/java/src/main/java/com/genexus/db/driver/GXCallableStatement.java @@ -54,7 +54,7 @@ public boolean execute() throws SQLException log(GXDBDebug.LOG_MIN, "Executing callable statement"); try { - ret = stmt.execute(); + ret = con.getDBMS().execute(stmt); log(GXDBDebug.LOG_MIN, "succesfully executed"); } catch (SQLException sqlException) @@ -65,7 +65,7 @@ public boolean execute() throws SQLException } else { - ret = stmt.execute(); + ret = con.getDBMS().execute(stmt); } //con.setNotInUse(this); diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMS.java b/java/src/main/java/com/genexus/db/driver/GXDBMS.java index 0d29e8db7..30e910616 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMS.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMS.java @@ -2,6 +2,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.Statement; import java.sql.ResultSet; import java.sql.SQLException; @@ -44,6 +45,9 @@ public interface GXDBMS void commit(Connection con) throws SQLException; void rollback(Connection con) throws SQLException; ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLException; + int executeUpdate(PreparedStatement stmt) throws SQLException; + boolean execute(PreparedStatement stmt) throws SQLException; + int[] executeBatch(Statement stmt) throws SQLException; void setDatabaseName(String dbName); String getDatabaseName(); diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSaccess.java b/java/src/main/java/com/genexus/db/driver/GXDBMSaccess.java index d0f08321e..5118f76f5 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSaccess.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSaccess.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -15,6 +12,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public void setDatabaseName(String dbName) { } diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSas400.java b/java/src/main/java/com/genexus/db/driver/GXDBMSas400.java index 1c1ea8931..819bbf207 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSas400.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSas400.java @@ -40,6 +40,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean DataTruncation(SQLException e) { return (e.getErrorCode() == 01004 ); diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMScloudscape.java b/java/src/main/java/com/genexus/db/driver/GXDBMScloudscape.java index 6f9dd3836..c0e79aa1f 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMScloudscape.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMScloudscape.java @@ -29,6 +29,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean isAlive(GXConnection con) { diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSdb2.java b/java/src/main/java/com/genexus/db/driver/GXDBMSdb2.java index e5cea4865..4d3d2e3b8 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSdb2.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSdb2.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -15,6 +12,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean isAlive(GXConnection con) { try diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMShana.java b/java/src/main/java/com/genexus/db/driver/GXDBMShana.java index 51912f707..5860b31d7 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMShana.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMShana.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -17,6 +14,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean isAlive(GXConnection con) { try diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSinformix.java b/java/src/main/java/com/genexus/db/driver/GXDBMSinformix.java index 23740bd39..ad08ea7fc 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSinformix.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSinformix.java @@ -57,6 +57,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean DataTruncation(SQLException e) { return false; diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSmysql.java b/java/src/main/java/com/genexus/db/driver/GXDBMSmysql.java index a41a4628e..6169f8302 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSmysql.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSmysql.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -17,6 +14,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean isAlive(GXConnection con) { try diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSoracle7.java b/java/src/main/java/com/genexus/db/driver/GXDBMSoracle7.java index 71481a112..7f7bf4d0d 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSoracle7.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSoracle7.java @@ -1,10 +1,7 @@ package com.genexus.db.driver; import java.io.InputStream; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -26,6 +23,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public boolean isAlive(GXConnection con) { try diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java b/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java index 65f0e85aa..07083a7b7 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSpostgresql.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -22,6 +19,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public void setInReorg() { } diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSservice.java b/java/src/main/java/com/genexus/db/driver/GXDBMSservice.java index 6132aa27a..9fab9e9e1 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSservice.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSservice.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import com.genexus.CommonUtil; import com.genexus.db.service.ServiceError; @@ -34,6 +31,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx } } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + @Override public void setInReorg() { diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSsqlite.java b/java/src/main/java/com/genexus/db/driver/GXDBMSsqlite.java index 97a2071a2..31ca3fed8 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSsqlite.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSsqlite.java @@ -1,9 +1,6 @@ package com.genexus.db.driver; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.util.Date; import com.genexus.CommonUtil; @@ -15,6 +12,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public void setDatabaseName(String dbName) { } diff --git a/java/src/main/java/com/genexus/db/driver/GXDBMSsqlserver.java b/java/src/main/java/com/genexus/db/driver/GXDBMSsqlserver.java index b283b5574..44fbc8ea8 100644 --- a/java/src/main/java/com/genexus/db/driver/GXDBMSsqlserver.java +++ b/java/src/main/java/com/genexus/db/driver/GXDBMSsqlserver.java @@ -17,6 +17,21 @@ public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLEx return stmt.executeQuery(); } + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + return stmt.executeUpdate(); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return stmt.execute(); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return stmt.executeBatch(); + } + public void setDatabaseName(String dbName) { } diff --git a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java index 0d5cd6ba4..bbec393d1 100644 --- a/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java +++ b/java/src/main/java/com/genexus/db/driver/GXPreparedStatement.java @@ -226,7 +226,7 @@ public boolean execute() throws SQLException log(GXDBDebug.LOG_MAX, "Warning: execute"); try { - ret = stmt.execute(); + ret = con.getDBMS().execute(stmt); return ret; } catch (SQLException sqlException) @@ -243,7 +243,7 @@ public boolean execute() throws SQLException { try { - ret = stmt.execute(); + ret = con.getDBMS().execute(stmt); return ret; } catch (SQLException sqlException) @@ -341,11 +341,11 @@ public int executeUpdate() throws SQLException if (DEBUG) { log(GXDBDebug.LOG_MIN, "executeUpdate"); - ret = stmt.executeUpdate(); + ret = con.getDBMS().executeUpdate(stmt); } else { - ret = stmt.executeUpdate(); + ret = con.getDBMS().executeUpdate(stmt); } } catch (SQLException e) diff --git a/java/src/main/java/com/genexus/db/driver/GXStatement.java b/java/src/main/java/com/genexus/db/driver/GXStatement.java index 0d65ebd8c..7da80bbed 100644 --- a/java/src/main/java/com/genexus/db/driver/GXStatement.java +++ b/java/src/main/java/com/genexus/db/driver/GXStatement.java @@ -468,7 +468,7 @@ private void log(String text) public int[] executeBatch() throws SQLException { - return stmt.executeBatch(); + return con.getDBMS().executeBatch(stmt); } public Connection getConnection() throws SQLException diff --git a/java/src/main/java/com/genexus/specific/java/JavaModelContextExtension.java b/java/src/main/java/com/genexus/specific/java/JavaModelContextExtension.java index 4667d30ae..1f1ba9537 100644 --- a/java/src/main/java/com/genexus/specific/java/JavaModelContextExtension.java +++ b/java/src/main/java/com/genexus/specific/java/JavaModelContextExtension.java @@ -120,9 +120,9 @@ public AbstractDataSource beforeGetConnection(ModelContext context, int handle, @Override public void afterGetConnection(ModelContext modelContext, int handle, AbstractDataSource dataSource) { String proc = modelContext.getPreferences().getEvent("after_connect"); + ModelContext.getModelContext().setAfterConnectHandle(handle); if (!proc.equals("")) { - modelContext.setAfterConnectHandle(handle); try { if (ApplicationContext.getInstance().isApplicationServer()) diff --git a/java/src/main/java/com/genexus/util/GXServices.java b/java/src/main/java/com/genexus/util/GXServices.java index ea72f1fd2..49fe74adf 100644 --- a/java/src/main/java/com/genexus/util/GXServices.java +++ b/java/src/main/java/com/genexus/util/GXServices.java @@ -15,6 +15,7 @@ public class GXServices { public static final String STORAGE_SERVICE = "Storage"; public static final String STORAGE_APISERVICE = "StorageAPI"; public static final String CACHE_SERVICE = "Cache"; + public static final String DATA_ACCESS_SERVICE = "DataAccess"; private static final String SERVICES_FILE = "CloudServices.config"; private static final String SERVICES_DEV_FILE = "CloudServices.dev.config"; private static GXServices instance; diff --git a/java/src/test/java/com/genexus/db/driver/GXDBMSGxTest.java b/java/src/test/java/com/genexus/db/driver/GXDBMSGxTest.java new file mode 100644 index 000000000..5b3e6661a --- /dev/null +++ b/java/src/test/java/com/genexus/db/driver/GXDBMSGxTest.java @@ -0,0 +1,197 @@ + +package com.genexus.db.driver; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.Date; + +import com.genexus.CommonUtil; + +public class GXDBMSGxTest implements GXDBMS +{ + GXDBMS GXDBMSImpl; + public GXDBMSGxTest(GXDBMS innerInstance) + { + GXDBMSImpl = innerInstance; + } + + public ResultSet executeQuery(PreparedStatement stmt, boolean hold) throws SQLException + { + System.out.print("Executing SQL sentence"); + return GXDBMSImpl.executeQuery(stmt, hold); + } + + public int executeUpdate(PreparedStatement stmt) throws SQLException + { + System.out.print("Executing Update sentence"); + return GXDBMSImpl.executeUpdate(stmt); + } + + public boolean execute(PreparedStatement stmt) throws SQLException + { + return GXDBMSImpl.execute(stmt); + } + + public int[] executeBatch(Statement stmt) throws SQLException + { + return GXDBMSImpl.executeBatch(stmt); + } + + public void setDatabaseName(String dbName) + { + GXDBMSImpl.setDatabaseName(dbName); + } + + public String getDatabaseName() + { + return GXDBMSImpl.getDatabaseName(); + } + + public void setInReorg() + { + GXDBMSImpl.setInReorg(); + } + + public boolean isAlive(GXConnection con) + { + return GXDBMSImpl.isAlive(con); + } + + public boolean DataTruncation(SQLException e) + { + return GXDBMSImpl.DataTruncation(e); + } + + public void setDataSource(DataSource dataSource) + { + GXDBMSImpl.setDataSource(dataSource); + } + + public boolean useReadOnlyConnections() + { + return GXDBMSImpl.useReadOnlyConnections(); + } + + public boolean EndOfFile(SQLException e) + { + return GXDBMSImpl.EndOfFile(e); + } + + public boolean ReferentialIntegrity(SQLException e) + { + return GXDBMSImpl.ReferentialIntegrity(e); + } + + public boolean DuplicateKeyValue(SQLException e) + { + return GXDBMSImpl.DuplicateKeyValue(e); + } + + public boolean ObjectLocked(SQLException e) + { + return GXDBMSImpl.ObjectLocked(e); + } + + public boolean ObjectNotFound(SQLException e) + { + return GXDBMSImpl.ObjectNotFound(e); + } + + public java.util.Date nullDate() + { + return GXDBMSImpl.nullDate(); + } + + public boolean useDateTimeInDate() + { + return GXDBMSImpl.useDateTimeInDate(); + } + + public boolean useCharInDate() + { + return GXDBMSImpl.useCharInDate(); + } + + public void setConnectionProperties(java.util.Properties props) + { + GXDBMSImpl.setConnectionProperties(props); + } + + public void onConnection(GXConnection con) throws SQLException + { + GXDBMSImpl.onConnection(con); + } + + public java.util.Date serverDateTime(GXConnection con) throws SQLException + { + return GXDBMSImpl.serverDateTime(con); + } + + public String serverVersion(GXConnection con) throws SQLException + { + return GXDBMSImpl.serverVersion(con); + } + + public String connectionPhysicalId(GXConnection con) + { + return GXDBMSImpl.connectionPhysicalId(con); + } + + public boolean getSupportsAutocommit() + { + return GXDBMSImpl.getSupportsAutocommit(); + } + + public void commit(Connection con) throws SQLException + { + GXDBMSImpl.commit(con); + } + + public void rollback(Connection con) throws SQLException + { + GXDBMSImpl.rollback(con); + } + + public boolean ignoreConnectionError(SQLException e) + { + return GXDBMSImpl.ignoreConnectionError(e); + } + + public boolean rePrepareStatement(SQLException e) + { + return GXDBMSImpl.rePrepareStatement(e); + } + + public boolean getSupportsQueryTimeout() + { + return GXDBMSImpl.getSupportsQueryTimeout(); + } + + public boolean useStreamsInNullLongVarchar() + { + return GXDBMSImpl.useStreamsInNullLongVarchar(); + } + + public boolean useStreamsInLongVarchar() + { + return GXDBMSImpl.useStreamsInLongVarchar(); + } + + public int getId() + { + return GXDBMSImpl.getId(); + } + + public int getLockRetryCount(int lockRetryCount, int waitRecord) + { + return GXDBMSImpl.getLockRetryCount(lockRetryCount, waitRecord); + } + + public boolean connectionClosed(SQLException e) + { + return GXDBMSImpl.connectionClosed(e); + } +} diff --git a/java/src/test/java/com/genexus/db/driver/TestMockDataAccess.java b/java/src/test/java/com/genexus/db/driver/TestMockDataAccess.java new file mode 100644 index 000000000..893278d97 --- /dev/null +++ b/java/src/test/java/com/genexus/db/driver/TestMockDataAccess.java @@ -0,0 +1,34 @@ +package com.genexus.db.driver; + +import com.mockdb.*; +import com.genexus.Application; +import org.junit.Before; +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; + +import static org.junit.Assert.assertEquals; + +public class TestMockDataAccess { + + private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); + + @Before + public void setUpStreams() { + System.setOut(new PrintStream(outContent)); + } + + @Test + public void testMockDataAccess(){ + Application.init(GXcfg.class); + ausemockdataaccess pgm = new ausemockdataaccess (-1); + Application.realMainProgram = pgm; + pgm.execute(); + + assertEquals("Executing Update sentence" + + "Executing Update sentence" + + "Executing SQL sentence" + + "Executing Update sentence", outContent.toString()); + } +} diff --git a/java/src/test/java/com/mockdb/GXcfg.java b/java/src/test/java/com/mockdb/GXcfg.java new file mode 100644 index 000000000..c6d044826 --- /dev/null +++ b/java/src/test/java/com/mockdb/GXcfg.java @@ -0,0 +1,13 @@ +package com.mockdb ; +import com.genexus.*; + +public final class GXcfg +{ + public static int strcmp( String Left , + String Right ) + { + return GXutil.rtrim(Left).compareTo(GXutil.rtrim(Right)); + } + +} + diff --git a/java/src/test/java/com/mockdb/ausemockdataaccess.java b/java/src/test/java/com/mockdb/ausemockdataaccess.java new file mode 100644 index 000000000..1c884ab35 --- /dev/null +++ b/java/src/test/java/com/mockdb/ausemockdataaccess.java @@ -0,0 +1,186 @@ +package com.mockdb ; +import com.genexus.*; +import com.genexus.db.*; +import java.sql.*; + +public final class ausemockdataaccess extends GXProcedure +{ + public static void main( String args[] ) + { + Application.init(com.mockdb.GXcfg.class); + ausemockdataaccess pgm = new ausemockdataaccess (-1); + Application.realMainProgram = pgm; + pgm.executeCmdLine(args); + GXRuntime.exit( ); + } + + public void executeCmdLine( String args[] ) + { + + execute(); + } + + public ausemockdataaccess( int remoteHandle ) + { + super( remoteHandle , new ModelContext( ausemockdataaccess.class ), "" ); + } + + public ausemockdataaccess( int remoteHandle , + ModelContext context ) + { + super( remoteHandle , context, "" ); + } + + public void execute( ) + { + execute_int(); + } + + private void execute_int( ) + { + initialize(); + /* GeneXus formulas */ + /* Output device settings */ + privateExecute(); + } + + private void privateExecute( ) + { + /* + INSERT RECORD ON TABLE Transaction1 + + */ + A11Transaction1Id = (short)(1) ; + A12Transaction1Nombre = "UNO" ; + /* Using cursor P000R2 */ + pr_default.execute(0, new Object[] {Short.valueOf(A11Transaction1Id), A12Transaction1Nombre}); + Application.getSmartCacheProvider(remoteHandle).setUpdated("Transaction1"); + if ( (pr_default.getStatus(0) == 1) ) + { + Gx_err = (short)(1) ; + Gx_emsg = localUtil.getMessages().getMessage("GXM_noupdate") ; + } + else + { + Gx_err = (short)(0) ; + Gx_emsg = "" ; + } + /* End Insert */ + /* Optimized UPDATE. */ + /* Using cursor P000R3 */ + pr_default.execute(1); + Application.getSmartCacheProvider(remoteHandle).setUpdated("Transaction1"); + /* End optimized UPDATE. */ + /* Using cursor P000R4 */ + pr_default.execute(2); + while ( (pr_default.getStatus(2) != 101) ) + { + A12Transaction1Nombre = P000R4_A12Transaction1Nombre[0] ; + A11Transaction1Id = P000R4_A11Transaction1Id[0] ; + AV8Transaction1Nombre = A12Transaction1Nombre ; + pr_default.readNext(2); + } + pr_default.close(2); + /* Optimized DELETE. */ + /* Using cursor P000R5 */ + pr_default.execute(3); + Application.getSmartCacheProvider(remoteHandle).setUpdated("Transaction1"); + /* End optimized DELETE. */ + cleanup(); + } + + public static Object refClasses( ) + { + GXutil.refClasses(usemockdataaccess.class); + return new com.mockdb.GXcfg(); + } + + protected void cleanup( ) + { + Application.commitDataStores(context, remoteHandle, pr_default, "ausemockdataaccess"); + CloseOpenCursors(); + exitApp(); + } + + protected void CloseOpenCursors( ) + { + } + + /* Aggregate/select formulas */ + public void initialize( ) + { + A12Transaction1Nombre = "" ; + Gx_emsg = "" ; + scmdbuf = "" ; + P000R4_A12Transaction1Nombre = new String[] {""} ; + P000R4_A11Transaction1Id = new short[1] ; + AV8Transaction1Nombre = "" ; + pr_default = new DataStoreProvider(context, remoteHandle, new com.mockdb.ausemockdataaccess__default(), + new Object[] { + new Object[] { + } + , new Object[] { + } + , new Object[] { + P000R4_A12Transaction1Nombre, P000R4_A11Transaction1Id + } + , new Object[] { + } + } + ); + /* GeneXus formulas. */ + Gx_err = (short)(0) ; + } + + private short A11Transaction1Id ; + private short Gx_err ; + private int GX_INS3 ; + private String A12Transaction1Nombre ; + private String Gx_emsg ; + private String scmdbuf ; + private String AV8Transaction1Nombre ; + private IDataStoreProvider pr_default ; + private String[] P000R4_A12Transaction1Nombre ; + private short[] P000R4_A11Transaction1Id ; +} + +final class ausemockdataaccess__default extends DataStoreHelperBase implements ILocalDataStoreHelper +{ + public Cursor[] getCursors( ) + { + return new Cursor[] { + new UpdateCursor("P000R2", "INSERT INTO [Transaction1]([Transaction1Id], [Transaction1Nombre]) VALUES(?, ?)", GX_NOMASK + GX_MASKLOOPLOCK) + ,new UpdateCursor("P000R3", "UPDATE [Transaction1] SET [Transaction1Nombre]='UNO UNO' WHERE [Transaction1Id] = 1", GX_NOMASK + GX_MASKLOOPLOCK) + ,new ForEachCursor("P000R4", "SELECT [Transaction1Nombre], [Transaction1Id] FROM [Transaction1] ORDER BY [Transaction1Id] ",false, GX_NOMASK + GX_MASKLOOPLOCK, false, this,100, GxCacheFrequency.OFF,false ) + ,new UpdateCursor("P000R5", "DELETE FROM [Transaction1] WHERE [Transaction1Id] = 1", GX_NOMASK + GX_MASKLOOPLOCK) + }; + } + + public void getResults( int cursor , + IFieldGetter rslt , + Object[] buf ) throws SQLException + { + switch ( cursor ) + { + case 2 : + ((String[]) buf[0])[0] = rslt.getString(1, 20); + ((short[]) buf[1])[0] = rslt.getShort(2); + return; + } + } + + public void setParameters( int cursor , + IFieldSetter stmt , + Object[] parms ) throws SQLException + { + switch ( cursor ) + { + case 0 : + stmt.setShort(1, ((Number) parms[0]).shortValue()); + stmt.setString(2, (String)parms[1], 20); + return; + } + } + +} + diff --git a/java/src/test/java/com/mockdb/usemockdataaccess.java b/java/src/test/java/com/mockdb/usemockdataaccess.java new file mode 100644 index 000000000..f78e6353f --- /dev/null +++ b/java/src/test/java/com/mockdb/usemockdataaccess.java @@ -0,0 +1,71 @@ +package com.mockdb ; +import com.genexus.*; + +public final class usemockdataaccess extends GXProcedure +{ + public static void main( String args[] ) + { + Application.init(com.mockdb.GXcfg.class); + usemockdataaccess pgm = new usemockdataaccess (-1); + Application.realMainProgram = pgm; + pgm.executeCmdLine(args); + GXRuntime.exit( ); + } + + public void executeCmdLine( String args[] ) + { + + execute(); + } + + public usemockdataaccess( ) + { + super( -1 , new ModelContext( usemockdataaccess.class ), "" ); + Application.init(com.mockdb.GXcfg.class); + } + + public usemockdataaccess( int remoteHandle ) + { + super( remoteHandle , new ModelContext( usemockdataaccess.class ), "" ); + } + + public usemockdataaccess( int remoteHandle , + ModelContext context ) + { + super( remoteHandle , context, "" ); + } + + public void execute( ) + { + execute_int(); + } + + private void execute_int( ) + { + initialize(); + /* GeneXus formulas */ + /* Output device settings */ + new com.mockdb.ausemockdataaccess(remoteHandle, context).execute( ); + cleanup(); + } + + protected void cleanup( ) + { + CloseOpenCursors(); + Application.cleanup(context, this, remoteHandle); + } + + protected void CloseOpenCursors( ) + { + } + + /* Aggregate/select formulas */ + public void initialize( ) + { + /* GeneXus formulas. */ + Gx_err = (short)(0) ; + } + + private short Gx_err ; +} +