项目作者: mohalaoui

项目描述 :
e_commerce shopping with postgres database design
高级语言: Java
项目地址: git://github.com/mohalaoui/e_commerce_shop.git
创建时间: 2020-07-11T17:33:07Z
项目社区:https://github.com/mohalaoui/e_commerce_shop

开源协议:

下载


Spring data jpa hibernate and postgres

postgres

  1. server.port=7000
  2. spring.datasource.url=jdbc:postgresql://192.168.5.8:5432/dev
  3. spring.datasource.username=vagrant
  4. spring.datasource.password=vagrant
  5. spring.jpa.show-sql=true
  6. spring.jpa.properties.hibernate.format_sql=true

hibernate

  • spring config
    1. The SQL dialect makes Hibernate generate better SQL for the chosen database

      spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

Hibernate ddl auto (create, create-drop, validate, update)

spring.jpa.hibernate.ddl-auto = update

ehcache

  • enable caching : @EnableCaching(mode = AdviceMode.ASPECTJ)
  • caching entities : @Cache(usage = CacheConcurrencyStrategy.READ_ONLY, region = “product”)
  • spring config
  1. spring.jpa.properties.hibernate.cache.use_second_level_cache=true
  2. spring.jpa.properties.hibernate.cache.use_query_cache=true
  3. spring.jpa.properties.hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
  4. spring.jpa.properties.hibernate.enable_lazy_load_no_trans=true
  • ehcache.xml
    • set the default cache policy
    • add custom cache policy by region
  • example:
  1. <defaultCache eternal="false" timeToLiveSeconds="30"
  2. memoryStoreEvictionPolicy="LRU" statistics="true" maxElementsInMemory="10000"
  3. overflowToDisk="false" ></defaultCache>
  4. <cache name="product" maxEntriesLocalHeap="10000" eternal="false"
  5. timeToIdleSeconds="60" timeToLiveSeconds="60" memoryStoreEvictionPolicy="LRU"
  6. statistics="true">
  7. </cache>

HATEOAS

  • dependency:

    1. <dependency>
    2. <groupId>org.springframework.boot</groupId>
    3. <artifactId>spring-boot-starter-hateoas</artifactId>
    4. </dependency>
  • adding link to resource:

    • ResourceRepresentation that extends RepresentationModel>
    • adding link: customersRepresentation.add(linkTo(methodOn(ShopControllerImpl.class).getCustomers()).withSelfRel());