没有任何数据可供显示
开源项目社区 | 当前位置 : |
|
www.trustie.net/open_source_projects | 主页 > 开源项目社区 > sbql4j |
sbql4j
|
2 | 0 | 59 |
贡献者 | 讨论 | 代码提交 |
An extension to Java language with an engine based on Stack-Based Architecture (SBA)
It provides capabilities similar to Microsoft LINQ for Java language. Allows to process Java objects with queries.
SBQL4J follow software engineering principles such as orthogonality, modularity, minimality, universality, typing safety, and clean, precise semantics.
Code with queries are parsed by preprocessor integrated with OpenJDK Compiler. SBQL4J builds AST query trees which are then analyzed and as output Java code is produced.
It integrates tightly with Java which means:
Java variables can be used in queries directly (no special syntax like setParameterX is required). Queries returns Java objects (collection or single object depending on query and used Java types). Java methods and constructors can be invoked inside queries. Query language is type-safe - queries are checked in compile time. Queries can be translated to pure Java code (with no reflection usage) so execution is very fast. (Description)
SBQL4J gives Java developers full power of SBQL query language . Multiply nested and complicated queries are well-supported, which can't be written in any other query language (including LINQ).
Available operators:
arithmetic: +, -. *, /, %, == , != , >, =, 0 and unitPrice > 3.00
};Selects all orders, while referring to customers by the order in which they are returned from the query (example from LINQ page). (Model description)
List customers = getCustomerList();
List customerOrders = #{
(customers as c).
($index as custIndex, c.orders as o).
("Customer #"+(custIndex + 1)+" has an order with OrderID "+o.orderID)
};This sample uses an order by operator with a custom comparer to sort first by word length and then by a case-insensitive sort of the words in an array (example from LINQ page).
String[] words = { "aPPLE", "AbAcUs", "bRaNcH", "BlUeBeRrY", "ClOvEr", "cHeRry" };
Comparator comp = new Comparator() {
@Override
public int compare(String o1, String o2) {
return o1.toLowerCase().compareTo(o2.toLowerCase());
}
};
List sortedWords = #{
words as w
order by w.length(); w using comp
}; Is it true that each department employs an employee earning the same as his/her boss? (Model description)
List dept = data.getDepts();
Boolean res = #{
all (dept as d)
any ((d.employs minus d.boss) as e)
(e.salary == d.boss.salary)
};Get the minimal, average and maximal number of employees in departments. (Model description)
List dept = data.getDepts();
Struct res = #{
min(dept.count(employs)) as minimum,
avg(dept.count(employs)) as average,
max(dept.count(employs)) as maximum
};For each employee get the message containing his/her name and the percent of the annual budget of his/her department that is consumed by his/her monthly salary (Model description)
List emp = data.getEmps();
List res = #{
emp.("Employee " + name + " consumes " + (salary * 12 * 100 / (worksIn.budget)) +
"% of the " + worksIn.name + " department budget.")
};See more executable examples (about 90 queries) in download section. There is a run-ready Eclipse project with build SBQL4J library and examples.