marioosh.net

mini blog / notes

Change commit date

$ git rebase -i HEAD~3   In editor mark commit that need change as ‘edit’ (the second commit in example below)   pick 64b0966 commit message 1… edit 07f540b commit message 2… pick a2b69e4 commit message 3…   # Rebase 50d9975..a2b69e4 onto 50d9975 (3 command(s)) # # Commands: # p, pick = use commit # Read more about Change commit date[…]

Posted in git

rx.js – chain requests

import { mergeMap } from ‘rxjs/operators’;   this.http.get(’/request1’).pipe( mergeMap((resp1:any) => this.http.post(’/request2′, resp1) ) );import { mergeMap } from ‘rxjs/operators’; this.http.get(‘/request1’).pipe( mergeMap((resp1:any) => this.http.post(‘/request2’, resp1) ) );

Native query with Enum as parameter

public interface ItemRepository extends JpaRepository<Item, Long> { @Query(value = "select * from items where type = :#{#type?.name()}", nativeQuery = true) List<Item> findByType(@Param("type") ItemType type); }   public enum ItemType { NORMAL, LARGE };public interface ItemRepository extends JpaRepository<Item, Long> { @Query(value = "select * from items where type = :#{#type?.name()}", nativeQuery = true) List<Item> findByType(@Param("type") ItemType Read more about Native query with Enum as parameter[…]

Optional @Value

// default: 60 @Value("${test-value:60}") private int minutes;   // default: null @Value("${test-value2:#{null}}") private String text;// default: 60 @Value("${test-value:60}") private int minutes; // default: null @Value("${test-value2:#{null}}") private String text;

Map<String,String> in JPA Entity

@Entity @Table(name="product") public class Product extends AbstractEntity {   @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id;   @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Map<String, String> attributes = new HashMap<String, String>();   // …   }@Entity @Table(name="product") public class Product extends AbstractEntity { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @ElementCollection(fetch = FetchType.EAGER) @JoinTable(name="product_attribute", joinColumns=@JoinColumn(name="product_id")) @MapKeyColumn(name="key") @Column(name="value") private Read more about Map<String,String> in JPA Entity[…]

Spring Data JPA: LIKE with OR query

@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); }@RepositoryRestResource public interface ProductRepository extends JpaRepository<Product, String> { List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, @Param("q") String id); } Request path: GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=…GET https://localhost:8443/api/products/search/findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase?q=… If we need shorter request path: // GET https://localhost:8443/api/products/search/custom?q=… @RestResource(path = "custom") List<Product> findByTitleContainingIgnoreCaseOrIdContainingIgnoreCase( @Param("q") String name, Read more about Spring Data JPA: LIKE with OR query[…]