XpcSecurity credentials = ud.getCredentials();
Xpc xpc = new Xpc(credentials);
xpc.start("training.getEmployees", "select");
xpc.attrib("id", "10");
XData result = xpc.run();
•如果我们想要获得身份在10到30之间的员工,该怎么办? •如果我想根据时间戳/日期选择记录,该怎么办? •如果想要连接多个表并进行查询。
答案 0 :(得分:1)
您似乎正在使用基于xpc.start中实体“training.getEmployees”的XPC插件(XPC类文件)(“training.getEmployees”,“select”)。在这种情况下,请执行以下操作:
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插件中处理它。
答案 1 :(得分: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 * a.employee_id = b.employee_id
上的内部联接time_track b现在您可以在选择
时应用条件