Skip to content

Instantly share code, notes, and snippets.

View bdarfler's full-sized avatar

Ben Darfler bdarfler

View GitHub Profile
final Collection<String> parts = buildUpdateParts( dbObj );
if ( parts.isEmpty() ) { return; }
final String query = "UPDATE " + dbObj.getTableName() + " SET " + join( parts, ", " ) + " WHERE id = :id";
simpleJdbcTemplate.update( query, new BeanPropertySqlParameterSource( dbObj ) );
private static final Collection<String> buildUpdateParts( final LocaDbObj dbObj ) {
 return transform( filter( dbObj.getFieldNames(), not( IS_ID ) ), new BuildPart( dbObj ) );
}
private static final class BuildPart implements Function<String, String> {
 private final LocaDbObj dbObj;
 public BuildPart( final LocaDbObj dbObj ) {
simpleJdbcTemplate.update( "DELETE FROM " + dbObj.getTableName() + " WHERE id = :id", new BeanPropertySqlParameterSource( dbObj ) );
// Get Datasource from Spring Context
SimpleJdbcInsert jdbcInsert = new SimpleJdbcInsert( dataSource ).withTableName( dbObj.getTableName() ).usingGeneratedKeyColumns( "id" );
final int id = jdbcInsert.executeAndReturnKey( new BeanPropertySqlParameterSource( dbObj ) ).intValue();
dbObj.setId( id );
import static com.google.common.collect.Collections2.filter;
import static com.google.common.collect.Collections2.transform;
import static org.apache.commons.lang.StringUtils.join;
import static org.apache.commons.lang.StringUtils.lowerCase;
import static org.apache.commons.lang.StringUtils.splitByCharacterTypeCamelCase;
import static org.jvnet.inflector.Noun.pluralOf;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public abstract class AbstractBaseObj {
@Override
public boolean equals( final Object obj ) {
return EqualsBuilder.reflectionEquals( this, obj );
function addGlobalStyle(css) {
var head, style;
head = document.getElementsByTagName(‘head’)[0];
if (!head) { return; }
style = document.createElement(‘style’);
style.type = ‘text/css’;
style.innerHTML = css;
head.appendChild(style);
}
@Component
public class Requestor {
private static final class ProducerConsumer implements SessionCallback<Message> {
private static final int TIMEOUT = 5000;
private final String msg;
private final DestinationResolver destinationResolver;
private final String queue;
public ProducerConsumer( final String msg, String queue, final DestinationResolver destinationResolver ) {
 this.msg = msg;
 this.queue = queue;
@Component
public class Requestor {
private static final class CorrelationIdPostProcessor implements MessagePostProcessor {
private final String correlationId;
public CorrelationIdPostProcessor( final String correlationId ) {
this.correlationId = correlationId;
}
package com.company;
import javax.jms.ExceptionListener;
import javax.jms.JMSException;
import org.springframework.stereotype.Component;
@Component
public class JmsExceptionListener implements ExceptionListener
{
 public void onException( final JMSException e )
 {
 e.printStackTrace();
package com.company;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.springframework.stereotype.Component;
@Component
public class QueueListener implements MessageListener
{
 public void onMessage( final Message message )