001/* 002 * Copyright 2006-2013 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.core.repository.dao; 018 019import java.sql.Types; 020 021import org.springframework.beans.factory.InitializingBean; 022import org.springframework.jdbc.core.JdbcOperations; 023import org.springframework.util.Assert; 024import org.springframework.util.StringUtils; 025 026/** 027 * Encapsulates common functionality needed by JDBC batch metadata DAOs - 028 * provides jdbcTemplate for subclasses and handles table prefixes. 029 * 030 * @author Robert Kasanicky 031 */ 032public abstract class AbstractJdbcBatchMetadataDao implements InitializingBean { 033 034 /** 035 * Default value for the table prefix property. 036 */ 037 public static final String DEFAULT_TABLE_PREFIX = "BATCH_"; 038 039 public static final int DEFAULT_EXIT_MESSAGE_LENGTH = 2500; 040 041 private String tablePrefix = DEFAULT_TABLE_PREFIX; 042 043 private int clobTypeToUse = Types.CLOB; 044 045 private JdbcOperations jdbcTemplate; 046 047 protected String getQuery(String base) { 048 return StringUtils.replace(base, "%PREFIX%", tablePrefix); 049 } 050 051 protected String getTablePrefix() { 052 return tablePrefix; 053 } 054 055 /** 056 * Public setter for the table prefix property. This will be prefixed to all 057 * the table names before queries are executed. Defaults to 058 * {@link #DEFAULT_TABLE_PREFIX}. 059 * 060 * @param tablePrefix the tablePrefix to set 061 */ 062 public void setTablePrefix(String tablePrefix) { 063 this.tablePrefix = tablePrefix; 064 } 065 066 public void setJdbcTemplate(JdbcOperations jdbcTemplate) { 067 this.jdbcTemplate = jdbcTemplate; 068 } 069 070 protected JdbcOperations getJdbcTemplate() { 071 return jdbcTemplate; 072 } 073 074 public int getClobTypeToUse() { 075 return clobTypeToUse; 076 } 077 078 public void setClobTypeToUse(int clobTypeToUse) { 079 this.clobTypeToUse = clobTypeToUse; 080 } 081 082 @Override 083 public void afterPropertiesSet() throws Exception { 084 Assert.notNull(jdbcTemplate, "JdbcOperations is required"); 085 } 086 087}