Skip to content

Instantly share code, notes, and snippets.

View odrotbohm's full-sized avatar
👨‍💻
@ home

Oliver Drotbohm odrotbohm

👨‍💻
@ home
View GitHub Profile
<!DOCTYPE html>
<html html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org"
th:replace="~{layout :: layout(~{:: #content})}">
<body cds-theme="dark">
<div class="content-area" id="content">
</div>
</body>
@odrotbohm
odrotbohm / LambdaTypeDetectionSample.java
Last active January 28, 2023 09:54
Lambda type detection sample
public class LambdaTypeDetectionSample {
public static void main(String[] args) {
Function<Integer, String> lambdaFunction = i -> i.toString();
Function<Integer, String> oldschoolFunction = new Function<Integer, String>() {
public String apply(Integer t) {
return t.toString();
}

tl;dr

We would like to simplify the event-based module integration and make sure the default transactional setup is correct by introducing a custom @ModuleIntegrationListener annotation.

Context

Classic Spring applications use bean references and invocations to orchestrate functionality, even if the functionality triggered resides in different application modules. In those cases, the default approach to consistency is a transaction that spans the original business method and all transitive functionality:

@Service
@RequiredArgsConstructor
@odrotbohm
odrotbohm / StoreRepository.java
Last active October 22, 2021 09:08
Dynamic, Querydsl-based filter bindings using Spring Data REST
public interface StoreRepository extends PagingAndSortingRepository<Store, String>,
QueryDslPredicateExecutor<Store>, QuerydslBinderCustomizer<QStore> {
@RestResource(rel = "by-location")
Page<Store> findByAddressLocationNear(Point location, Distance distance, Pageable pageable);
default void customize(QuerydslBindings bindings, QStore store) {
bindings.bind(store.address.city).single((path, value) -> path.startsWith(value));
bindings.bind(String.class).single((StringPath path, String value) -> path.contains(value));
}

Suggestions for HAL FORMS

{
  "_links" : { … },
  "name" : "…",
  "other-values" : [
    { … }, …
  ],
 "_templates" : {
@odrotbohm
odrotbohm / MyComponentImpl.java
Last active November 3, 2020 08:22
Constructor injection example with Lombok
/**
* Sample component implementation showing the usage of constructor injection
* avoiding the need to declare a constructor by the help of Lombok. There are
* several advantages of using constructor injection over field injection:
*
* <ol>
* <li>The class communicates its dependencies. Just start with {@code new
* MyDependencyImpl(…}and your IDE will tell you what you need to hand it in. No
* need to look into the implementation of the class to discover that.</li>
* <li>The class can only be used in valid state. The constructor argument require
@odrotbohm
odrotbohm / Sample.java
Created June 29, 2020 21:08
Jackson deserialization into a complex constructor
@SpringBootTest
@RequiredArgsConstructor
class Sample {
private final ObjectMapper jackson;
@Test
void deserializesThroughConstructor() throws Exception {
var result = jackson.readValue("{\"firstname\" : \"Dave\", \"lastname\" : \"Matthews\" }", SomeSample.class);
@odrotbohm
odrotbohm / gist:3215345
Created July 31, 2012 09:08
Git aliases to ease cherry picking

When fixing bugs on a software project I repeatedly faced the situation where I'd like to apply the commit I just did to a branch to another. Think of fixing a bug in the master branch and immediately back-porting it to the maintenance branch. This usually needed the following steps:

  1. Looking up the SHA1 of the original commit
  2. Checking out the destination branch
  3. git cherry-pick $sha1

The very first step can be eased a bit by creating a git alias to lookup the SHA1 of the last commit of a given branch.

[alias]
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
/*
* Copyright 2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software