Sbql4j - Stack-Based Query Language for Java

  •        813

This project is a result of research supported by Polish-Japanese Institute of Information TechnologyAn 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's 100% compatible with current Java Virtual Machines, and can be safely used in any Java project (compatible with Java 6). 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 and algebraic: +, -. *, /, %, == , != , >, <, >=, <=, OR, AND, NOT, instanceof aggregating: sum, count, avg, min, max set operators: union, intersect, unique, minus, in, ',' (comma - structure constructor) quantifiers: all, any non-algebraic operators '.' (dot - navigation, projection, path expressions), where, join, order by, close by (transitive closure - something like CONNECT BY in Oracle) range operators: [] (for example collection[5], collection[3..7], collection[2..*]) auxiliary name operators: as, group as constructor: new Some examples: Find all products that are in stock and cost more than 3.00 per unit (example from LINQ page) (Model description) List products = getProductList();List expensiveInStockProducts = #{ products where unitsInStock > 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 = #{\t(customers as c).\t($index as custIndex, c.orders as o).\t("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() { \t@Override \tpublic int compare(String o1, String o2) { \t\treturn o1.toLowerCase().compareTo(o2.toLowerCase()); \t} }; List sortedWords = #{ \twords as w \torder 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 = #{\tall (dept as d)\tany ((d.employs minus d.boss) as e)\t(e.salary == d.boss.salary)};Get the minimal, average and maximal number of employees in departments. (Model description) List dept = data.getDepts();Struct res = #{\tmin(dept.count(employs)) as minimum, \tavg(dept.count(employs)) as average, \tmax(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 = #{\temp.("Employee " + name + " consumes " + (salary * 12 * 100 / (worksIn.budget)) +\t "% 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.

http://code.google.com/p/sbql4j

Tags
Implementation
License
Platform

   




Related Projects

vim-olive - Vim Mode Line Verifier


Vim Mode Line Verifier

vim-mash - Motion Activated Search Highlighter for Vim


Motion Activated Search Highlighter for Vim

vim-grillz - Flash your wicked grillz!


Flash your wicked grillz!

vim-foist - Complete whole lines from any partial therein


Complete whole lines from any partial therein

vim-efmc - Vim Error Format Compiler


Vim Error Format Compiler


uzbl-utrs - mkng uzbl tlrbl


mkng uzbl tlrbl

toycsv - A toy CSV parser written in ruby + lexr + racc


A toy CSV parser written in ruby + lexr + racc

tiktok - TikTok provides a simple asynchronous timer object for VimL.


TikTok provides a simple asynchronous timer object for VimL.

tabby - Using Vim's Tabs the Right Way


Using Vim's Tabs the Right Way

SohiVila - GNU source-highlight Vim language


GNU source-highlight Vim language

SinTax - A DSL for generating Vim syntax highlighting files


A DSL for generating Vim syntax highlighting files

rkdots - Generate a graphviz visualisation of the given javascript statement.


Generate a graphviz visualisation of the given javascript statement.

RelNumBar - Show relativenumbers alongside normal numbers in Vim


Show relativenumbers alongside normal numbers in Vim

Punisher - Punisher hurts you where it hurts most - your time.


Punisher hurts you where it hurts most - your time.

noisy - Don't chat quietly (weechat channel noises)


Don't chat quietly (weechat channel noises)

newlisp-manual - Asciidoc version of the newLISP manual


Asciidoc version of the newLISP manual

Land-of-newLISP - Selected snippets from Land of Lisp rewritten in newLISP


Selected snippets from Land of Lisp rewritten in newLISP

Fossilise - Poor man's collaborative editing in Vim


Poor man's collaborative editing in Vim

firstly - Convert Between Numeric, Spelt, and Short & Long Ordinal Forms of Numbers


Convert Between Numeric, Spelt, and Short & Long Ordinal Forms of Numbers