johnsonlu / best-practices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Best Practice Bookmarks - (PostgreSQL / Java / Spring / Hibernate)

Some best practices that are useful in this stack.

Contents:

PostgreSQL

  2004-10-19 10:23:54+02

There is no performance difference among these three types, apart from increased storage space when using the blank-padded type, and a few extra CPU cycles to check the length when storing into a length-constrained column. While character(n) has performance advantages in some other database systems, there is no such advantage in PostgreSQL; in fact character(n) is usually the slowest of the three because of its additional storage costs. In most situations text or character varying should be used instead. - https://www.postgresql.org/docs/current/static/datatype-character.html

Java

Spring / Hibernate

  @Id
  @SequenceGenerator(name="sequance_name", sequenceName="sequance_name", allocationSize=1)
  @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="sequance_name")
  private short id;

All the annotations above are important for the definition of the sequence otherwise it won't work, including the allocationSize. If you don't define the allocationSize the id value might go negative or collisions might happen.

Security

REST

  @JsonProperty("id")
  private Integer recordId;

  @JsonProperty("user_id")
  private Integer userId;
	
  @JsonProperty("air_temp")
  private Double airTemp;
	
  @JsonProperty("rel_temp")
  private Double relTemp;	

Testing

Git

Other

Stack

* Windows 10
* PostgreSQL 10.2
* Java 9
* Spring Boot 2.0.0
* Gradle 4.6
* Eclipse Oxygen.2
* DBeaver
* Git 2.16

About