Planet JFX
Advertisement

To support embeded SQL operation or LINQ feature maybe very interesting and make JavaFX a first selection for enterprise application. Following is some of the ideas.

1. Automated generate ORM classes

@SQLEntityGenerator("users")
class User {
}

this will automated generate a mapped class to the table "users", so you need not handcode each attribute. the generation is done in the compile time and so it still follows the Static Type spec.

2. new syntax exec sql

example:

var user = User {}
var username = "wang"
exec sql select * into :user from users where username = :username;

The compiler can check the sql statement grammar, and the table name, the field name etc to make sure that the statement is correct.

or you can using

var count = 0;
exec sql select count(*) into :count from users where username = :username;

for insert statement like:

exec sql insert into users values :user;

or update some field like:

exec sql update users(username, password) values :user where username = :username;

or execute a group of statement like:

exec sql {
 select count(*) into :count from users;
 insert into users values :user;
 update users(username,password) values :user where username = :username;
}

LINQ feature[]

the SQL operation can not only applies on RDBMS, it can aslo applies on javafx's sequence, unlike Javafx's grammar, it is a standard "SQL" grammar.

var users: User[];
exec sql insert into :users values :user;
exec sql select * into :user from :users where username = :username;
var students:Student[];
var teachers:Teacher[];
var student: Student;
var teacher: Teacher;
// find the teacher/student who have same name
exec sql select t.*, s.* into :student, :teacher 
  from :teachers t, :students s where t.name = s.name;

also, you can do like:

update :teacher set name = :some-name-expr, age = :some-age-expr

which is more readable that the normal JavaFX's version

teacher.name = some-name-expr
teacher.age = some-age-expr

end[]

Do you think that this feature is interesting and valuable? Back to OpenJFX Compiler

Advertisement