Skip to content

Instantly share code, notes, and snippets.

/**
* splits the string at every nth position
* @param str
* @param position
* @return a list of Strings each string has a length <= position
*/
public static List<String> splitEveryPosition(String str, Integer position) {
List<String> strings = new ArrayList<String>();
@bmchild
bmchild / FkFinder.sql
Created September 2, 2014 21:21
Script to find the foreign key for table and column
SELECT
o1.name AS FK_table,
c1.name AS FK_column,
fk.name AS FK_name,
o2.name AS PK_table,
c2.name AS PK_column,
pk.name AS PK_name,
fk.delete_referential_action_desc AS Delete_Action,
fk.update_referential_action_desc AS Update_Action
FROM sys.objects o1
@Entity
public class User {
@Id
private String userId;
private String lastName;
private String ssn;
// other fields and getter and setters
}
select *
from User
where
userId in (:userIds)
-- Then we need an OR clause for each match we want
OR ( lastName = :lastName1 AND SUBSTRING(ssn, LEN(ssn)-3, 4) = :lastFourSsn1)
OR ( lastName = :lastName2 AND SUBSTRING(ssn, LEN(ssn)-3, 4) = :lastFourSsn2)
-- ...
/*
* Class used to filter the User entity
*/
public class UserParameter {
private String userId;
private String lastName;
/* only last 4 digits */
private String ssn;
// getters and setters
}
@bmchild
bmchild / AbstractBatchCustomRepositoryImpl.java
Created February 18, 2015 15:47
Custom Batch Save Repository
package com.bmchild.data.shared.batch;
import javax.sql.DataSource;
import org.apache.commons.lang.Validate;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.jdbc.core.JdbcTemplate;
/**
* @author bchild
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=1234
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.rmi.server.hostname=127.0.0.1
public interface Employable {
String MY_CONSTANT = "value"
}
public class MyClass {
private String theConstant = Employable.MY_CONSTANT;
}
@bmchild
bmchild / ToStringUtil.java
Created November 7, 2011 23:11
toString Utility
package com.mypackage;
import java.lang.reflect.Method;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
public class ToStringUtil {
@bmchild
bmchild / log4j.xml
Created November 8, 2011 21:16
log4j base
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="stdout" class="org.apache.log4j.ConsoleAppender">
<layout class="org.apache.log4j.PatternLayout">
<!-- Pattern to output the caller's file name and line number -->
<param name="ConversionPattern" value="%d{ISO8601} [%p] %m [(%M)%c]%n" />
</layout>