1
XpcSecurity credentials = ud.getCredentials();
    Xpc xpc = new Xpc(credentials);
    xpc.start("training.getEmployees", "select");
    xpc.attrib("id", "10");
   XData result = xpc.run();

• 如果我们想要获取 id 在 10 到 30 之间的员工怎么办 • 如果我想根据时间戳/日期选择记录怎么办 • 如果想要连接多个表并查询它。

4

2 回答 2

1

您似乎正在使用基于 xpc.start("training.getEmployees", "select") 中的实体“training.getEmployees”的 XPC 插件(XPC 类文件)。在这种情况下,请执行以下操作:

XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees", "select");
xpc.attrib("idLower", "10");
xpc.attrib("idUpper", "30");
XData result = xpc.run();

在runMethod内的Xpc插件(可能命名为“GetEmployeesXpc”)中,执行以下操作来获取通过上面的xpc代码传递的数据

// Get the method passed through xpc.start
String method = elem.getAttribute("method"); 

// Get the attrib using the following
XData input = new XData(elem);
String upperLimit = input.getText("//idUpper");
String lowerLimit = input.getText("//idLower");

// process the query depending on how you access your data source
if (method.equals("select")) {
    // put your logic here to access your data source
    String query = "select * from employees where id>"+lowerLimit+" &&  id<"+upperLimit";"
     :
     :
} else {
     // Do something else
}

您可以对日期/时间戳或连接执行相同的操作。只需传递数据并在 Xpc 插件中处理它。

于 2012-11-06T10:52:58.063 回答
0

我的回答可能为时已晚,但出于参考目的,您可以试试这个:

XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees","select");

StringBuffer whereClause = new StringBuffer();

//In xpc this is the equivalent of "id between idLower and idUpper"
whereClause.append("<whereClause>\n");
whereClause.append("    <expr op='and' returnType='char'>\n");
whereClause.append("        <expr op='ge' returnType='char'>\n");
whereClause.append("            <operand>id</operand>\n");
whereClause.append("            <operand type='literal'>"+idLower+"</operand>\n");
whereClause.append("        </expr>\n");
whereClause.append("        <expr op='le' returnType='char'>\n");
whereClause.append("            <operand>id</operand>\n");
whereClause.append("            <operand type='literal'>"+idUpper+"</operand>\n");
whereClause.append("        </expr>\n"); whereClause.append("    </expr>\n");
whereClause.append("</whereClause>\n");

xpc.input(whereClause);
XData result = xpc.run();

对于表连接:

我看到你已经在使用 xpc 类了。在这个类中把它放在初始化函数中:

mapEntity("training.getEmployees");

addLevel("employees");  
mapTable("employee", "employee", null);
mapColumn("employee_id", "employeeId", "employeeId", true, false);
mapColumn("first_name", "firstName", "firstName", false, false);
mapColumn("last_name", "lastName", "lastName", false, false);

mapTable("time_track", "timeTrack", null);
mapColumn("time_track_id", "timeTrackId", "timeTrackId", true, false);
mapColumn("time_in", "timeIn", "timeIn", false, false);
mapColumn("time_out", "timeOut", "timeOut", false, false);
mapColumn("employee_id", "employeeId", "employeeId", false, false);

addJoin("employee", "employeeId", "timeTrack", "employeeId");

这相当于 Select * from employee a internal join time_track b on a.employee_id = b.employee_id

您现在可以在选择时应用条件

于 2013-04-05T06:06:03.007 回答