This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gem.demo.java; | |
import java.util.NoSuchElementException; | |
import java.util.Random; | |
public class RandomString { | |
public static void main(String[] args) { | |
long time = System.currentTimeMillis(); | |
generate("hello"); | |
generate("world"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Arrays.stream(TimeZone.getAvailableIDs()).forEach(id -> { | |
boolean flag = false; | |
try { | |
ZoneId.of(id); | |
flag = true; | |
} catch (Exception e) { | |
//ignore; | |
} | |
if (!flag) | |
System.out.printf("[%s] %s%n", flag ? "x" : " ", id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Entity | |
public class Employee extends AbstractBaseEntity { | |
// Approach 1: | |
// @Id | |
// public String id; | |
// Approach 2: | |
@Id | |
// default column type is byte array | |
@Type(type = "org.hibernate.type.PostgresUUIDType") // or type = "pg-uuid" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface NoArgConstructor<T> { | |
T foo(); | |
} | |
interface ArgConstructor<T, U> { | |
T bar(U arg); | |
} | |
interface MultiArgsConstructor<T, U> { | |
T magic(U... arg); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.gem.demo.database.model; | |
public class Company { | |
public int id; | |
public String name; | |
public String address; | |
... | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[EL Info]: connection: 2015-08-30 12:52:11.554--ServerSession(1286783232)--/file:/C:/Users/KiT/IdeaProjects/Database Sample/service/target/classes/_pu login successful | |
Employee.prePersist | |
[EL Fine]: sql: 2015-08-30 12:52:11.635--ClientSession(1437983537)--Connection(1614079837)--INSERT INTO EMPLOYEE (NAME, SALARY) VALUES (?, ?) | |
bind => [2 parameters bound] | |
[EL Fine]: sql: 2015-08-30 12:52:11.637--ClientSession(1437983537)--Connection(1614079837)--SELECT LAST_INSERT_ID() | |
Employee.postPersist | |
======================================== | |
[EL Fine]: sql: 2015-08-30 12:52:11.729--ServerSession(1286783232)--Connection(1614079837)--SELECT ID, NAME, SALARY FROM EMPLOYEE WHERE (ID = ?) | |
bind => [1 parameter bound] | |
Employee.postLoad |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.persistence.*; | |
@Entity | |
public class User { | |
@Id | |
@GeneratedValue(strategy = GenerationType.IDENTITY) | |
private int id; | |
private String name; | |
@Lob | |
private String avatar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
[EL Fine]: sql: 2015-08-30 10:11:24.497--ServerSession(1622006612)--Connection(530410619)--SELECT ID, NAME, SALARY FROM EMPLOYEE WHERE (ID = ?) | |
bind => [1 parameter bound] | |
Employee.setName(KiT) // when manager.find(Employee.class, id); | |
Employee.getName() => KiT | |
Employee.setName(KiT) | |
Employee.getName() => KiT | |
Employee.setName(KiT) | |
Employee #1: KiT (12345) | |
Employee.getName() => KiT // when transaction.commit(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// JPA defines named parameters, and positional parameters. | |
// Named parameters can be specified in JPQL using the syntax :<name>. | |
Query query = em.createQuery("SELECT e FROM Employee e WHERE e.firstName = :first and e.lastName = :last"); | |
query.setParameter("first", "Bob"); | |
query.setParameter("last", "Smith"); | |
List<Employee> list = query.getResultList(); | |
// Positional parameters can be specified in JPQL using the syntax ? or ?<position>. | |
// Positional parameters start at position 1 not 0. |
