diff --git a/process/ImporterMappingFunctions_lib/process.js b/process/ImporterMappingFunctions_lib/process.js index e3f610e18075773c68188215242ad2b1244549f9..efd1d74731059646a03963a9a735067fe39fcf12 100644 --- a/process/ImporterMappingFunctions_lib/process.js +++ b/process/ImporterMappingFunctions_lib/process.js @@ -13,10 +13,12 @@ import("Importer_lib"); // TODO: use SqlBuilder -///////////////////////////////////////////////////////////////////// -/// toolkit methods for the import handler /// -/// DO NOT TOUCH - use lib_importerCustomMappingFunctions /// -/////////////////////////////////////////////////////////////////// +/* +┌───────────────────────────────────────────────────────────────┠+│ toolkit methods for the import handler │ +│ DO NOT TOUCH - use lib_importerCustomMappingFunctions │ +└───────────────────────────────────────────────────────────────┘ +*/ /* * Values of the mapping line: @@ -51,7 +53,8 @@ function iKeyword(pObject) { values = [id, util.getNewUUID(), container, keyword, sort, "1", "0"]; this.insertData(this.getTableCase("ab_keyword_entry"), columns, null, values, this.Config.AliasTo); } - this.setOutput(pObject, id); + if (pObject.Target) // no target specified? just try to create a new keyword entry if necessary + this.setOutput(pObject, id); return true; } @@ -256,10 +259,7 @@ function iKeywordAttribute(pObject) { this.updateData(this.getTableCase("ab_keyword_attributerelation"), [valueColumn], null, [value], cond, this.Config.AliasTo); } } - this.setOutput(pObject, id); - } else { - this.setOutput(pObject, aid); - } + } return true; } @@ -290,12 +290,12 @@ function iComm(pObject) { var sql = "select " + this.getColumnCase("communicationid") + " from " + this.getTableCase("communication") +" where " + this.getColumnCase("contact_id") + " = ? and " + this.getColumnCase("medium_id") + " = ? and " - + this.getColumnCase("standard") + " = ? and " + this.getColumnCase("addr") + " = ?" + + this.getColumnCase("isstandard") + " = ? and " + this.getColumnCase("addr") + " = ?" var id = db.cell([sql, [[contact, SQLTYPES.CHAR], [medium, SQLTYPES.CHAR], //TODO: define types dynamically and not hardcoded [standard, SQLTYPES.SMALLINT], [address, SQLTYPES.VARCHAR]]], this.Config.AliasTo); if (id == "" || id == null) { var columns = [this.getColumnCase("communicationid"), this.getColumnCase("addr"), - this.getColumnCase("medium_id"), this.getColumnCase("contact_id"), this.getColumnCase("standard")]; + this.getColumnCase("medium_id"), this.getColumnCase("contact_id"), this.getColumnCase("isstandard")]; this.insertData(this.getTableCase("communication"), columns, null, [util.getNewUUID(), address, medium, contact, standard], this.Config.AliasTo); } return true; diff --git a/process/ImporterTest_lib/process.js b/process/ImporterTest_lib/process.js index f389533c1b9a280db0c9078928fe3b169756be54..4dfc91255dc2ce6361b3d5ac7b5a165784417861 100644 --- a/process/ImporterTest_lib/process.js +++ b/process/ImporterTest_lib/process.js @@ -1,4 +1,4 @@ -import("system.question"); +import("system.logging"); import("system.text"); import("system.db"); import("Importer_lib"); @@ -61,12 +61,12 @@ function ImporterTest() { var testResult = testCase.fn.call(testCase, cbFn); if (testResult instanceof Importer) { testResult = testResult.process(); - question.showMessage("Successful: " + testCase.name +"\n" + JSON.stringify(testResult, null, " ")) + logging.log("[ImporterTest_lib]Successful: " + testCase.name +"\n" + JSON.stringify(testResult, null, " ")) } else { - question.showMessage("Successful\nResult:\n\n" + testResult) + logging.log("[ImporterTest_lib]Successful\nResult:\n\n" + testResult) } } else { - question.showMessage("No test function defined!", question.WARNING) + logging.log("[ImporterTest_lib]No test function defined!") } return true; } diff --git a/process/Importer_lib/process.js b/process/Importer_lib/process.js index 45203c0f3f61d9a75acb0eb76684a6e467a4e1f7..ad800c6581ee472cf3a7e1e90ed9b4f6a67be8a7 100644 --- a/process/Importer_lib/process.js +++ b/process/Importer_lib/process.js @@ -11,12 +11,12 @@ import("ImporterCustomMappingFunctions_lib"); import("ImporterMappingFunctions_lib"); // TODO: use SqlBuilder - -/* -┌─────────────────────────────────────────────────────────────┠-│ importer module constructor function │ -│ DO NOT TOUCH - use lib_importerCustomMappingFunctions │ -└─────────────────────────────────────────────────────────────┘ + +/* +┌───────────────────────────────────────────────────────────────┠+│ importer module constructor function │ +│ DO NOT TOUCH - use lib_importerCustomMappingFunctions │ +└───────────────────────────────────────────────────────────────┘ Frequently asked questions: @@ -34,7 +34,7 @@ A: There is a @version-tag in the documentation of the Importer-function (const * the importer class, main object * @param {String []} pConfig req ( Name, FunktionsArt, Details ) * -* @version 2.1 +* @version 2.2 * * * @return {void} @@ -99,11 +99,12 @@ function Importer(pConfig) this.ErrorLog = ""; this.DataType = null; this.KeyColumn = new Object(); // contains key info as in KeyColumn["tbl.col"] = "I" | "U" | "I+U" - this.UseAOType = true; //default true, so that AOType will be uses (for older systems) - this.UseUUID = true; //default false, so that db.getNewID() instead of util.getNewUUID() would be uses + this.UseAOType = true; //default true, so that AOType will be uses (for legacy systems) + this.UseUUID = true; //default true, so that util.getNewUUID() is used since this is what you want most time this.TableCase = this.Cases.Upper; //default is uppercase this.ColumnCase = this.Cases.Upper; //default is uppercase this.skipEmptyValue = true; + this._dbTimeoutGeneral = null;//timeout for all purposes, should be set via the setTimeout function and retrieved via the getTimeout function this.AttributeCache = undefined; this.useAttributeCache = false; @@ -634,7 +635,7 @@ function Importer(pConfig) { insertSuccessfull = false; var startInsert = datetime.date(); - db.inserts(this.insertArray, this.Config.AliasTo); + db.inserts(this.insertArray, this.Config.AliasTo, this.getConfiguredTimeout(Importer.TIMEOUT.INSERT)); exectimer.dbInsertTime += datetime.date() - startInsert; this.recordCounts.insert++; insertSuccessfull = true; @@ -649,7 +650,7 @@ function Importer(pConfig) { updateSuccessfull = false; var startUpdate = datetime.date(); - db.updates(this.updateArray, this.Config.AliasTo); + db.updates(this.updateArray, this.Config.AliasTo, this.getConfiguredTimeout(Importer.TIMEOUT.UPDATE)); exectimer.dbUpdateTime += datetime.date() - startUpdate; this.recordCounts.update++; updateSuccessfull = true; @@ -874,7 +875,7 @@ function Importer(pConfig) if(this.Config.IdQuery == undefined || this.Config.IdColumn == undefined) { //new method for batch-processsing (paging) - daten = db.tablePage(this.Config.DataQuery, this.Config.AliasFrom, batchStart, bs); + daten = db.tablePage(this.Config.DataQuery, this.Config.AliasFrom, batchStart, bs, this.getConfiguredTimeout(Importer.TIMEOUT.QUERY_DATA)); batchStart += bs; //this happens when all-records % pBlockSize == 0 @@ -898,7 +899,7 @@ function Importer(pConfig) // get data of the next batch var sql = this.Config.DataQuery.replace(/\$\$id/i, idcolumn + " in ('" + batchList.join("','") + "')" ); - daten = db.table(sql, this.Config.AliasFrom); + daten = db.table(sql, this.Config.AliasFrom, db.DB_EOF, this.getConfiguredTimeout(Importer.TIMEOUT.QUERY_DATA)); } else { @@ -913,7 +914,7 @@ function Importer(pConfig) if(batchNum > 1) daten = null; else - daten = db.table(this.Config.DataQuery, this.Config.AliasFrom); + daten = db.table(this.Config.DataQuery, this.Config.AliasFrom, db.DB_EOF, this.getConfiguredTimeout(Importer.TIMEOUT.QUERY_DATA)); } tt = datetime.date() - tt; exectimer["getdata"] += tt; @@ -935,7 +936,7 @@ function Importer(pConfig) importtype = "M"; // get the list of primary keys - resIDList = db.array(db.COLUMN, pConfig.IdQuery, pConfig.AliasFrom); + resIDList = db.array(db.COLUMN, pConfig.IdQuery, pConfig.AliasFrom, db.DB_EOF, this.getConfiguredTimeout(Importer.TIMEOUT.QUERY_DATA)); tt = datetime.date() - tt; exectimer["getdata"] += tt; } @@ -1377,9 +1378,8 @@ function Importer(pConfig) } catch(ex) { - this.writeLog(this.LogLevels.Error, "Property <Target> not set for mapping object!"); - logging.log(ex); - logging.log("[IMPORTER] Property <Target> not set for mapping object!"); + logging.log(ex["rhinoException"] != undefined ? ex["rhinoException"] : ex); + this.writeLog(this.LogLevels.Error, "Property <Target> not set for mapping object:pObject=" + JSON.stringify(pObject)); } } // get the content of the output record buffer according to "Action" performed @@ -1511,6 +1511,62 @@ function Importer(pConfig) } } +Importer.TIMEOUT = { + /** + * timeout for simple queries, that may run iterative and *normally* for a shorter execution time + */ + //QUERY_ORDINARY: "query_ordinray",//currently disabled because of: #1049095 + /** + * timeout for more complex queries, that may often return lots of records + */ + QUERY_DATA: "query_data", + /** + * timeout for insert statements + */ + INSERT: "insert", + /** + * timeout for update statements + */ + UPDATE: "update" +}; + +/** + * returns the configured timeout value for a specific timeouttpye + * + * @param pTimeoutType possible values are Importer.TIMEOUT.**** + * + * @return {Number} timeout that is configured, if none is configured 0 is returned + */ +Importer.prototype.getConfiguredTimeout = function(pTimeoutType) +{ + if (pTimeoutType && this.Config.dbTimeout && this.Config.dbTimeout[pTimeoutType] != null) + return this.Config.dbTimeout[pTimeoutType]; + else if (this._dbTimeoutGeneral != null) + return this._dbTimeoutGeneral; + else + return 0; +}; + +/** + * sets the timeout time for a specific type or if no type was given a general timeouttime for the importer + * + * @param {Number} pTimeout timeout time for the given time in milliseconds + * @param {String} [pTimeoutType] possible values are Importer.TIMEOUT.****; if this is empty a general timeouttime is set + * + * + * @return {Number} timeout that is configured, if none is configured 0 is returned + */ +Importer.prototype.setTimeout = function(pTimeout, pTimeoutType) +{ + if (pTimeout != undefined) + { + if (pTimeoutType) + this.Config.dbTimeout[pTimeoutType] = pTimeout; + else + this._dbTimeoutGeneral = pTimeout; + } +}; + /** * Data handler for csv paging * @@ -1573,6 +1629,4 @@ function batchCsvLoad(pCurrentBatchNum, pBatchSize) } while(dataStr != null); return null; -} - - +} \ No newline at end of file diff --git a/process/_test_importer/documentation.adoc b/process/_test_importer/documentation.adoc index 73c74189523ce93e420282f9348dd4bf4d1d5bb1..849455b6d51b6d6c27acf113dc060734599516e6 100644 --- a/process/_test_importer/documentation.adoc +++ b/process/_test_importer/documentation.adoc @@ -1,3 +1,4 @@ = _test_importer -Executeable Process for testing the importer. This process also provides an example for using the importer module. \ No newline at end of file +Executeable Process for testing the importer. This process also provides an example for using the importer module, however it may be more complex +than an actual importprocess should look like. \ No newline at end of file