GistTree.Com
Entertainment at it's peak. The news is by your side.

Show HN: A new way of ORM in Java

0

ObjectiveSQL is an ORM framework in Java unsuitable on ActiveRecord pattern, which encourages snappy trend and swish, codes with the least, and conference over configuration.

Aspects

  • Dynamic code technology with JSR 269 for Java API of database obtain admission to
  • Fleshy Java API of database obtain admission to without coding
  • Dynamically SQL programming with Java syntax, and in actuality halt to SQL syntax

Set up

Must you are the employ of Maven factual add the next dependency to your pom.xml:

<dependency>
    <groupId>com.github.braisdomgroupId>
    <artifactId>design-sqlartifactId>
    <version>1.3.8version>
dependency>

Installing IntelliJ Plugin: Preferences/Settings -> Plugins -> Search with “ObjectiveSql” in market -> Install

Straightforward SQL programming without coding

// You excellent outline a domain mannequin and occupy linked properties
@DomainModel
public class Member {
    private String no;
    
    @Queryable
    private String title;
    private Integer gender;
    private String mobile;
    private String otherInfo;

    @Relation(relationType = RelationType.HAS_MANY)
    private Checklist<Order> orders;
}
// That you simply would be in a position to well presumably presumably obtain behaviors of place a question to, update and delete without coding.
Member.countAll();
Member.rely("identification > ?", 1);
Member.queryByPrimaryKey(1);
Member.queryFirst("identification = ?", 1);
Member.place a question to("identification > ?", 1);
Member.queryAll();

Member newMember = contemporary Member()
        .setNo("100000")
        .setName("Pamela")
        .setGender(1)
        .setMobile("15011112222");
Member.have(newMember);

Member[] people = contemporary Member[]{newMember1, newMember2, newMember3};
        Member.have(people);

Member.update(1L, newMember);

Member.kill(1L);

Member.pause(String.structure("DELETE FROM %s WHERE title = 'Mary'", Member.TABLE_NAME));

...
Member.queryAll(Member.HAS_MANY_ORDERS);
Member.queryPrimary(1, Member.HAS_MANY_ORDERS);
Member.queryByName("demo", Member.HAS_MANY_ORDERS);
...

Advanced SQL programming

Inform.Desk orderTable = Inform.asTable();
Dangle out rob = contemporary Dangle out();

rob.project(sum(orderTable.quantity) / sum(orderTable.quantity) * 100)
    .from(orderTable)
    .groupBy(orderTable.productId);
SELECT SUM(direct.quantity) / SUM(direct.quantity)  * 100
      FROM orders AS direct GROUP BY direct.product_id
Member.Desk member = Member.asTable();
Inform.Desk direct = Inform.asTable();

Dangle out rob = contemporary Dangle out();

rob.from(direct, member)
        .the attach(direct.memberId.eq(member.identification));
rob.project(member.no,
        member.title,
        member.mobile,
        countDistinct(direct.no).as("order_count"),
        sum(direct.quantity).as("total_quantity"),
        sum(direct.quantity).as("total_amount"),
        min(direct.salesAt).as("first_shopping"),
        max(direct.salesAt).as("last_shopping"));
rob.groupBy(member.no, member.title, member.mobile);
SELECT
	`T0`.`no` ,
	`T0`.`title` ,
	`T0`.`mobile` ,
	COUNT(DISTINCT `T1`.`no` ) AS `order_count`,
	SUM(`T1`.`quantity` ) AS `total_quantity`,
	SUM(`T1`.`quantity` ) AS `total_amount`,
	MIN(`T1`.`sales_at` ) AS `first_shopping`,
	MAX(`T1`.`sales_at` ) AS `last_shopping`
FROM `orders` AS `T1`, `people` AS `T0`
WHERE (`T1`.`member_id` = `T0`.`identification` )
GROUP BY `T0`.`no` , `T0`.`title` , `T0`.`mobile`
  1. Java syntax very halt to SQL syntax

  2. SQL program could be modified to logical program, resuable and procedural

Read More

Leave A Reply

Your email address will not be published.