Skip to content

Instantly share code, notes, and snippets.

View ljnelson's full-sized avatar
🙃

Laird Nelson ljnelson

🙃
View GitHub Profile
@ljnelson
ljnelson / person-jpa changelog.xml
Last active August 29, 2015 14:07
person-jpa example for Liquibase blog post
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd"
logicalFilePath="person-jpa">
<changeSet logicalFilePath="person-jpa" id="Initial changeSet" author="ljnelson">
<empty/>
@ljnelson
ljnelson / name-jpa changelog.xml
Created October 18, 2014 18:20
name-jpa example for Liquibase blog post
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd"
logicalFilePath="name-jpa">
<changeSet logicalFilePath="name-jpa" id="Initial changeSet" author="ljnelson">
<empty/>
@ljnelson
ljnelson / name-jpa aggregator changelog.xml
Created October 18, 2014 18:41
hand-build aggregator changelog for Liquibase blog post
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.2.xsd"
logicalFilePath="name-jpa-test">
<include name="person-jpa-1.0.0-SNAPSHOT-jar/META-INF/liquibase/changelog.xml" relativeToChangelogFile="true"/>
<include name="test-classes/META-INF/liquibase/changelog.xml" relativeToChangelogFile="true"/>
@ljnelson
ljnelson / Messages.mkc
Created January 23, 2012 21:46
Message key catalog
# Matches a RuntimeException followed immediately by an IllegalStateException
# whose message property is "hello". When found, the key "noDice" is
# looked up in the ResourceBundle identified by com.edugility.throwables.Bundle.
# The resulting message, if found, is run through MVEL's templating engine first,
# then through java.text.MessageFormat, then through java.util.Formatter.
java.lang.RuntimeException.../java.lang.IllegalStateException(message == "hello")
--
com.edugility.throwables.Bundle#noDice
# If the prior test didn't match, then this one gets invoked. Entries in
@ljnelson
ljnelson / ejb-jar.xml
Last active December 18, 2015 19:49
An example ejb-jar.xml that shows how to override an @ejb reference.
<?xml version="1.0" ?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/ejb-jar_3_1.xsd"
version="3.1">
<enterprise-beans>
<session>
<ejb-name>ReferencingBeanName</ejb-name>
<ejb-local-ref>
package foo;
@Stateless
public class CaturgiatorBean {
@EJB(name = "foo.CaturgiatorBean/frobnicator")
private Frobnicator frobnicator;
}
package foo;
@Stateless
public class CaturgiatorBean {
@EJB
private Frobnicator frobnicator;
}
@ljnelson
ljnelson / ConsoleHandlerActivation.java
Last active December 18, 2015 21:19
A snippet showing how to programmatically dial a ConsoleHandler's level up so that logging information gets through to the terminal.
final Logger topLogger = Logger.getLogger("");
assert topLogger != null;
Handler consoleHandler = null;
final Handler[] handlers = topLogger.getHandlers();
if (handlers != null && handlers.length > 0) {
for (final Handler handler : topLogger.getHandlers()) {
if (handler instanceof ConsoleHandler) {
consoleHandler = handler;
break;
}
@ljnelson
ljnelson / gist:6366032
Last active December 21, 2015 21:08
A method showing how to test to see if an EntityManager contains an arbitrary object, not just a known entity, without running the risk of rolling the transaction back.
/**
* Returns {@code true} if the supplied {@link EntityManager} is
* non-{@code null} and contains the supplied {@link Object} in its
* persistence context. Unlike the {@link EntityManager#contains(Object)}
* method, this method will not throw any exceptions, and hence will
* never roll the containing transaction back.
*
* @param em the {@link EntityManager} in question; may be {@code null}
* in which case {@code false} will be returned
*
@ljnelson
ljnelson / RFC7807ThrowableConverter.java
Created June 30, 2016 19:16
Hopefully the most correct way to process a JAX-RS Response and convert it to a Throwable, without losing other Throwables that may happen along the way.
public static final <T extends Throwable> T toThrowable(final Class<T> throwableClass, final Throwable cause, Response response) {
Objects.requireNonNull(throwableClass, "throwableClass == null");
Constructor<T> c = null;
try {
c = throwableClass.getConstructor(String.class, Throwable.class);
} catch (final NoSuchMethodException e) {
throw new IllegalArgumentException("throwableClass", e);
}
assert c != null : throwableClass + ".getConstructor(String.class, Throwable.class) == null";