Browse files

Actually add the record file that was supposed to be added in the las…

…t commit.
  • Loading branch information...
1 parent 1d0ada7 commit 09a0a92c50a1dbac5b3fbae7f7f6cb0de9266fca John Rogelstad committed Mar 11, 2012
Showing with 86 additions and 4 deletions.
  1. +1 −2 .gitignore
  2. +2 −2 postgresql/xt/functions/dispatch.sql
  3. +83 −0 postgresql/xt/javascript/record.sql
View
3 .gitignore
@@ -3,8 +3,7 @@
# ignore tmp directories
tmp
-
# ignore OSX .DS_Store files
*.DS_Store
-
output.txt
+/*.backup
View
4 postgresql/xt/functions/dispatch.sql
@@ -50,13 +50,13 @@ select xt.dispatch($${"requestType":"dispatch",
}$$);
select xt.dispatch($${"requestType":"dispatch",
- "className":"XM.Session",
+ "className":"XT.Record",
"functionName":"fetchId",
"parameters":"XM.Address"
}$$);
select xt.dispatch($${"requestType":"dispatch",
- "className":"XM.Session",
+ "className":"XT.Record",
"functionName":"fetchNumber",
"parameters":"XM.Incident"
}$$);
View
83 postgresql/xt/javascript/record.sql
@@ -0,0 +1,83 @@
+select xt.install_js('XT','Record','xtuple', $$
+ /* Copyright (c) 1999-2011 by OpenMFG LLC, d/b/a xTuple.
+ See www.xm.ple.com/CPAL for the full text of the software license. */
+
+ XT.Record = {};
+
+ XT.Record.isDispatchable = true;
+
+ /**
+ Pass in a record type and get the next id for that type
+
+ @param {String} record type
+ @returns Number
+ */
+ XT.Record.fetchId = function(recordType) {
+ var nameSpace = recordType.beforeDot(),
+ type = recordType.afterDot(),
+ map = XT.Orm.fetch(nameSpace, type),
+ seq = map.idSequenceName,
+ sql = 'select nextval($1) as result';
+
+ return seq ? executeSql(sql, [seq])[0].result : false;
+ }
+
+ /**
+ Pass in a record type and get the next id for that type
+
+ @param {String} record type
+ @returns Number
+ */
+ XT.Record.fetchNumber = function(recordType) {
+ var nameSpace = recordType.beforeDot(),
+ type = recordType.afterDot(),
+ map = XT.Orm.fetch(nameSpace, type),
+ seq = map.orderSequence,
+ sql = 'select fetchNextNumber($1) as result';
+
+ return seq ? executeSql(sql, [seq])[0].result : false;
+ }
+
+ /**
+ Release a number back into the sequence pool for a given type.
+
+ @param {String} record type
+ @param {Number} number
+ @returns Boolean
+ */
+ XT.Record.releaseNumber = function(recordType, number) {
+ var nameSpace = recordType.beforeDot(),
+ type = recordType.afterDot(),
+ map = XT.Orm.fetch(nameSpace, type),
+ seq = map.orderSequence,
+ sql = 'select releaseNumber($1, $2) as result';
+
+ return seq ? executeSql(sql, [seq, number - 0])[0].result > 0 : false;
+ }
+
+ /**
+ Return a matching record id for a passed user key and value. If none found returns zero.
+
+ @param {String} record type
+ @param {String} user key
+ @param {Number} value
+ @returns Number
+ */
+ XT.Record.findExisting = function(recordType, key, value) {
+ var nameSpace = recordType.beforeDot(),
+ type = recordType.afterDot(),
+ map = XT.Orm.fetch(nameSpace, type),
+ table = recordType.decamelize(),
+ pKey = XT.Orm.primaryKey(map),
+ sql = 'select {primaryKey} as id from {table} where {userKey}=$1'
+ .replace(/{primaryKey}/, pKey)
+ .replace(/{table}/, table)
+ .replace(/{userKey}/, key)
+ .replace(/{value}/, value),
+ result = executeSql(sql, [value])[0];
+
+ return result ? result.id : 0;
+ }
+
+$$ );
+

0 comments on commit 09a0a92

Please sign in to comment.