Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃

Laird Nelson ljnelson

🙃
View GitHub Profile
@ljnelson
ljnelson / person-jpa changelog.xml
Last active Aug 29, 2015
person-jpa example for Liquibase blog post
View person-jpa changelog.xml
<?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 aggregator changelog.xml
Created Oct 18, 2014
hand-build aggregator changelog for Liquibase blog post
View name-jpa aggregator changelog.xml
<?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 / name-jpa changelog.xml
Created Oct 18, 2014
name-jpa example for Liquibase blog post
View name-jpa changelog.xml
<?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 / Messages.mkc
Created Jan 23, 2012
Message key catalog
View Messages.mkc
# 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 Dec 18, 2015
An example ejb-jar.xml that shows how to override an @ejb reference.
View ejb-jar.xml
<?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>
View CaturgiatorBean.java
package foo;
@Stateless
public class CaturgiatorBean {
@EJB(name = "foo.CaturgiatorBean/frobnicator")
private Frobnicator frobnicator;
}
View CaturgiatorBean.java
package foo;
@Stateless
public class CaturgiatorBean {
@EJB
private Frobnicator frobnicator;
}
@ljnelson
ljnelson / ConsoleHandlerActivation.java
Last active Dec 18, 2015
A snippet showing how to programmatically dial a ConsoleHandler's level up so that logging information gets through to the terminal.
View ConsoleHandlerActivation.java
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 Dec 21, 2015
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.
View gist:6366032
/**
* 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 Jun 30, 2016
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.
View RFC7807ThrowableConverter.java
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";