PostalcodeService.java 2 KB
Newer Older
Kim Gyeongeun committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
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;
	}

}