-
Notifications
You must be signed in to change notification settings - Fork 11
INSERT
Konstantin Triger edited this page Aug 19, 2019
·
9 revisions
Started in Fundamentals, we continue writing tutorial samples with FluentJPA.
Other basic clauses: SELECT, UPDATE, DELETE
FluentQuery query = FluentJPA.SQL((Link link) -> {
INSERT().INTO(viewOf(link, Link::getUrl, Link::getName);
VALUES(row("http://www.google.com", "Google"),
row("http://www.yahoo.com", "Yahoo"),
row("http://www.bing.com", "Bing"));
});FluentQuery query = FluentJPA.SQL((Link link) -> {
INSERT().INTO(viewOf(link, Link::getUrl, Link::getName, Link::getLastUpdate));
VALUES(row("http://www.facebook.com", "Facebook", DATE.of("2013-06-01")));
});If some fields should not be takes from the object, they should be put at the end of the view. Then they can be overridden:
Link toInsert = ... //external parameter
FluentQuery query = FluentJPA.SQL((Link link) -> {
View<Link> viewOfLink = viewOf(link, Link::getUrl, Link::getName,
Link::getLastUpdate);
INSERT().INTO(viewOfLink);
VALUES(viewOfLink.from(toInsert, DEFAULT()));
// overrides come at the end ---^^^^^^^^^
// I.e. FluentJPA starts populating from the end,
// and rest of parameters "takes" from the entity (url and name in this example)
});// same structure - derivation
@Tuple
@Table(name = "link_tmp")
public static class LinkTmp extends Link {
}
FluentQuery query = FluentJPA.SQL((LinkTmp linkTmp,
Link link) -> {
INSERT().INTO(linkTmp);
SELECT(link);
FROM(link);
WHERE(link.getLastUpdate() != null);
});Getting Started
- Introduction
- Setup
- Data Types
- Entities & Tuples
- Sub Queries
- JPA Integration
- Java Language Support
- Directives
- Library
- Returning Results
- JPA Repositories
Examples
Basic SQL DML Statements
Advanced SQL DML Statements
- Common Table Expressions (WITH Clause)
- Window Functions (OVER Clause)
- Aggregate Expressions
- MERGE
- Temporal Tables
Advanced Topics