package jp.agentec.sinaburocast.service; import java.util.List; import jp.agentec.sinaburocast.entity.Postalcode; import org.seasar.extension.jdbc.where.SimpleWhere; import org.seasar.framework.container.annotation.tiger.Component; import org.seasar.framework.container.annotation.tiger.InstanceType; @Component(instance=InstanceType.SINGLETON) public class PostalcodeService extends AbstractService<Postalcode> { public static final String ID_SEQ_NAME = "postalcode_id_seq"; /** * IDを発行して、登録する。 */ public int insertPostalcode(Postalcode postalcode, String insId) { postalcode.postalcodeId = getSeqNextVal(Integer.class, ID_SEQ_NAME); return super.insert(postalcode, insId); } public Postalcode findById(Integer postalcodeId) { return select().id(postalcodeId).getSingleResult(); } public List<Postalcode> findAllOrderById() { return select().orderBy("postalcodeId asc").getResultList(); } public List<Postalcode> findZipCodeListByName(String zipCode) { return select().where(new SimpleWhere().like("postalcode", "%" + zipCode.replace("%", "\\%") + "%")).orderBy("postalcodeId asc").getResultList(); } public List<Postalcode> findTestListByName(String zipCode) { //return select().innerJoin("prefecture1").where(new SimpleWhere().like("testName", "%" + testName + "%")).getResultList(); //return select().innerJoin("prefecture1").where(new SimpleWhere().like("postalcode", "%" + zipCode + "%")).orderBy("postalcodeId asc").getResultList(); return select().innerJoin("prefecture1").where("postalcode like '" + zipCode.replace("%", "\\%")+"%'").orderBy("postalcodeId asc").getResultList(); } public Postalcode findAddressByZipCode(String zipCode) { return select().innerJoin("prefecture1").where(new SimpleWhere().eq("postalcode", zipCode)).getSingleResult(); } /** * 郵便番号データ全件削除 * @return */ public int postalInfoDelAll() { String sql = "truncate table m_postalcode"; int ret = jdbcManager.updateBySql(sql).execute(); return ret; } }