Skip to content

Instantly share code, notes, and snippets.

View Bombe's full-sized avatar

David Roden Bombe

View GitHub Profile
@Bombe
Bombe / insert-file.sh
Last active April 18, 2024 08:06
Shell Script to Upload a Single File via FCP
#!/bin/bash
# 8e38d288-e581-44f3-bf47-bb0962d25b63
function client_hello() {
echo "ClientHello"
echo "Name=${1}"
echo "ExpectedVersion=2.0"
echo "EndMessage"
}

Removing Entity Listeners from a Hibernate Entity Manager

When testing your JPA entity handling code with a real entity manager it will not only write your entities to a real database, it will also call all entity listeners you have defined. Your entity listeners might be easy to fix but sometimes it’s just better to remove the entity listeners from the entity manager so they are ignored.

Entity listeners are methods in the entity class annotated with special annotation (such as @PerPersist or @PostDelete), or they can be defined in custom classes which are associated with the entity using the @EntityListeners annotation on the entity itself.

Depending on your entity listeners it can be advantageous to disable all entity listeners during tests instead of trying to get them to run during tests; they might access singletons or frameworks that are not active during tests, and mocking or stubbing those would seriously distract from the test itself.

How entity listeners are created from annotations and

Hibernate Ignores Entity Listeners

I switched a codebase from EclipseLink as JPA provider to Hibernate and found out that with Hibernate you can not use inheritance in event listener classes. The JPA specs do not go into much detail on this topic so JPA providers are bound to handle this different from one another.

I separated my entity listeners from my entities even though it is possible to add methods annotated with e.g. @PostPersist directly in the entity class. The entity listeners themselves were less than trivial but only slightly so: I created a generic base class for all entity listeners and specialized subclasses for each entity.

public class EntityListenerBase<T> {
	@PostPersist
	public void postPersisted(T object) {

SomeEventBus.sendEvent(createPostPersistEvent(object));

@Bombe
Bombe / calender.kt
Last active September 26, 2018 18:44
Creates an SVG-File with a calender for a whole year
import java.awt.*
import java.awt.SystemColor.*
import java.io.*
import java.nio.charset.*
import java.nio.file.*
import java.time.*
import java.time.DayOfWeek.*
import java.time.Month.*
import java.time.temporal.*

Keybase proof

I hereby claim:

  • I am bombe on github.
  • I am bombe (https://keybase.io/bombe) on keybase.
  • I have a public key ASDMNNihnq4QjHGBKK2HIHT68ovfdl59MAGx7Y1lba2ztAo

To claim this, I am signing this object:

@Bombe
Bombe / decide
Created November 16, 2017 13:47
Makes a decision between a number of given options.
#!/bin/bash
# 64D16CF7-35CB-4E1D-83E4-504260998EC4
numberOfChoices="${#@}"
if [ "${numberOfChoices}" == "0" ]; then
r="$((${RANDOM} % 2))"
if [ "${r}" == "0" ]; then
echo "No."
else
@Bombe
Bombe / .days
Last active March 31, 2016 11:17
days-left
20170414120000 Revision 2017 (for Visitors)
20160701120000 Nordlicht 2016
20160812120000 Evoke 2016
package de.xplosion.adp.servlet.filter;
import javax.inject.Inject;
import javax.inject.Singleton;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import com.google.inject.AbstractModule;
import com.google.inject.Guice;
import com.google.inject.Injector;
@Bombe
Bombe / insert-file
Created February 15, 2015 00:52
bash script to insert a file into Freenet (using FCP) (works on OS X)
#!/bin/bash
#
# GUID:F9FC4F74-501A-46BC-B57E-F9D8B4EFB83E
function client_hello() {
echo "ClientHello"
echo "Name=${1}"
echo "ExpectedVersion=2.0"
echo "EndMessage"
}
@Bombe
Bombe / set-language-level.patch
Created February 8, 2015 12:10
Patch for the retired Maven IDEA plugin (version 2.2.1) to allow setting the language level in the IDEA configuration file.
Index: src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java
===================================================================
--- src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java (revision 1658114)
+++ src/main/java/org/apache/maven/plugin/idea/IdeaProjectMojo.java (working copy)
@@ -161,6 +161,11 @@
setJdkName( module, defaultJdkName );
}
+ if ( jdkLevel != null )
+ {