This section provides an overview of PeopleCode and Application Engine programs and discusses how to:
本节概述了PeopleCode和应用程序引擎程序,并讨论了如何:
Inserting PeopleCode into Application Engine programs enables you to reuse common function libraries and improve performance. In many cases, a small PeopleCode program used instead of Application Engine PeopleCode is an excellent way to build dynamic SQL, perform simple If/Else edits, set defaults, and perform other tasks that do not require a trip to the database.
将PeopleCode插入到Application Engine程序中使您能够重用公共函数库并提高性能。在许多情况下,一个小的PeopleCode程序用来代替应用程序引擎PeopleCod是一个很好的方式来构建动态SQL,执行简单的If/else编辑、设置默认值和执行其他不需要访问数据库的任务。
Scope of Variables
变量的作用域
This table presents the different types of variables typically used in Application Engine programs and their scope:
下表显示了应用程序引擎程序中通常使用的不同类型的变量及其作用域:
Type of Variable |
Scope |
Comments |
State record (work record) |
Transaction (unit of work) |
Using a work record as your Application Engine state record means that the values in the work record cannot be committed to the database. Commits happen as directed, but any values in work records are not retained after a commit. |
State record (database record) |
Application Engine program |
Using a database record as your Application Engine state record preserves the values in the state record on commit, and the committed values are available in the event of a restart. |
Local PeopleCode variables |
PeopleCode program |
Local PeopleCode variables are available only for the duration of the PeopleCode program that is using them. |
Global PeopleCode variables |
Application Engine program |
Global PeopleCode variables are available during the life of the program that is currently running. Any global PeopleCode variables are saved when an Application Engine program commits and checks points; therefore, they are available in the event of a restart. |
Component PeopleCode variables |
Application Engine program |
Component PeopleCode variables act like global variables in Application Engine. |
Action Execution Order
操作执行顺序
A step can contain only one PeopleCode action because no other types of actions are required within a step in conjunction with a PeopleCode action (or program). If you include other actions with your PeopleCode action within the same step, keep in mind the hierarchy when you run it.
一个步骤只能包含一个PeopleCode操作,因为在一个步骤中不需要与PeopleCode操作(或程序)结合的其他类型的操作。如果您在同一步骤中包含其他操作与您的People Code操作,请在运行它时记住层次结构。
With PeopleCode actions, Application Engine runs the PeopleCode program before the SQL, Call Section, or Log Message actions, but a PeopleCode program runs after any program flow checks.
使用PeopleCode操作时,应用程序引擎将在SQL、CallSection或日志消息操作之前运行PeopleCode程序,但在任何程序流检查之后运行PeopleCode程序。
Because multiple action types exist, they must execute in agreement within a system; therefore, the order in which actions execute is significant. At runtime, actions defined for a given step are evaluated based on their action type. All of the action types exist within a strict hierarchy of execution. For example, if both a Do When action and a PeopleCode action exist within a given step, then the Do When action always runs first.
由于存在多个操作类型,它们必须在系统中以一致的方式执行;因此,操作的执行顺序非常重要。在运行时,为给定步骤定义的操作将根据其操作类型进行评估。所有操作类型都存在于严格的执行层次结构中。例如,如果两个Do当操作和PeopleCode操作存在于给定步骤中时,则Do When操作总是第一个运行。
The following example shows the sequence and level of execution for each type of action:
下面的例子显示了每种作用方式的执行顺序和水平:
This is an example of action execution hierarchy.
Application Engine is not intended to run programs that include only PeopleCode actions. The primary purpose of Application Engine is to run SQL against your data.
应用程序引擎不用于运行仅包括PeopleCode操作的程序。应用程序引擎的主要目的是对数据运行SQL。
Use PeopleCode primarily for setting If, Then, Else logic constructs, performing data preparation tasks, and building dynamic portions of SQL statements; rely on SQL to complete the bulk of actual program processing. Also use PeopleCode to reuse previously developed online logic. PeopleCode is the tool to use to take advantage of new technologies such as component interfaces and application classes.
PeopleCode主要用于设置If,Then,Else逻辑结构,执行数据准备任务,构建SQL语句的动态部分;依靠SQL来完成大量的实际程序处理。还可以使用PeopleCode重用以前开发的在线逻辑。PeopleCode是一种利用新技术(如组件接口和应用程序类)的工具。
Most programs must verify that a certain condition is true before they run a particular section. For example, if the hourly wage is less than or equal to X, do Step A; if not, fetch the next row. In certain instances, you must modify variables that exist in a state record. PeopleCode enables you to set state record variables dynamically.
大多数程序在运行特定的节之前必须验证某个条件为真。例如,如果小时工资小于或等于X,则执行步骤A;如果不是,则获取下一行。在某些情况下,必须修改存在于状态记录中的变量。PeopleCode允许您动态地设置状态记录变量。
Avoid rowset processing in an Application Engine program. Loading data into a rowset can use a significant amount of memory, which this formula approximates:
避免在应用程序引擎程序中处理行集。将数据加载到行集中可能会使用大量的内存,以下公式近似为:
mem = nrows * (row overhead + nrecords * (rec overhead + nfields * (field overhead) + average cumulative fielddata)) where
Mem = n 行*(行开销+ n 记录*( rec 开销+ nfields +*(现场开销+平均累计现场数据))
Using this formula, a rowset containing 500,000 rows with one record per row, 50 fields, and 200 bytes per field would require approximately 2.3 gigabytes of memory.
使用这个公式,包含500,000行,每行一条记录的行集,50个字段,每个字段200字节将需要大约2.3千兆字节的内存。