`

project 备份

 
阅读更多
http://trip.elong.com/news/n010guj3.html


package cn.com.hsbc.domin;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.junit.Test;

import com.thoughtworks.xstream.core.util.Fields;

public class CustomProfile {

	private Integer groupId;

	private Integer entityId;

	private String groupCode;

	private String entityCode;

	private String customerName;

	public Integer getGroupId() {
		return groupId;
	}

	public void setGroupId(Integer groupId) {
		this.groupId = groupId;
	}

	public Integer getEntityId() {
		return entityId;
	}

	public void setEntityId(Integer entityId) {
		this.entityId = entityId;
	}

	public String getGroupCode() {
		return groupCode;
	}

	public void setGroupCode(String groupCode) {
		this.groupCode = groupCode;
	}

	public String getEntityCode() {
		return entityCode;
	}

	public void setEntityCode(String entityCode) {
		this.entityCode = entityCode;
	}

	public String getCustomerName() {
		return customerName;
	}

	public void setCustomerName(String customerName) {
		this.customerName = customerName;
	}

	public Map<String, Object> getCustomProfileMap() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
		Map<String,Object> customProfileMap = new HashMap<String,Object>();
		Class clazz = this.getClass();
		Field[] fields = clazz.getDeclaredFields();
		for (Field field : fields) {
			//field.setAccessible(true);
			String fieldName = field.getName();
			String methodName = "get" + fieldName.substring(0, 1).toUpperCase()
					+ fieldName.substring(1);
			System.out.println(methodName);
			Method[] methods = clazz.getMethods();
			if(methods!=null){
			for(Method method :methods )
				if(method.getName().equals(methodName)){
					customProfileMap.put(fieldName,method.invoke(this, null));
				}
			}
		}

		return customProfileMap;
	}

	
}


QtQueryStgRowHashMapper
package cn.com.hsbc.dao.impl;

import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;
/**
 * 
 * @author 
 *
 */
public class QtQueryStgRowHashMapper implements RowHashMapper<Map<String,Object>>{
	private Map<String,Object> rowMap = new HashMap<String,Object>();
	

	@Override
	public Map<String,Object> mapRow(ResultSet rs, int currentRow) throws SQLException {
		ResultSetMetaData rsm =	rs.getMetaData();
		for(int i = 0; i<rsm.getColumnCount();i++){
		rowMap.put(rsm.getColumnLabel(0), rs.getInt(0));
		}
		return rowMap;
	}

	public final void processRow(ResultSet rs) throws SQLException {
		if (this.rowCount == 0) {
			ResultSetMetaData rsmd = rs.getMetaData();
			this.columnCount = rsmd.getColumnCount();
			this.columnTypes = new int[this.columnCount];
			this.columnNames = new String[this.columnCount];
			for (int i = 0; i < this.columnCount; i++) {
				this.columnTypes[i] = rsmd.getColumnType(i + 1);
				this.columnNames[i] = JdbcUtils.lookupColumnName(rsmd, i + 1);
			}
			// could also get column names
		}
		processRow(rs, this.rowCount++);
	}
	

}


RowHashMapper

package cn.com.hsbc.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;

public interface RowHashMapper<T> {
	
	T mapRow(ResultSet rs, int currentRow) throws SQLException;

}


JdbcHashItemReader
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Map;

import org.springframework.batch.item.database.AbstractCursorItemReader;

/**
 * 
 * @author 
 *
 */
public class JdbcHashItemReader<T> extends AbstractCursorItemReader<T> {
	
	
	PreparedStatement preparedStatement;

	PreparedStatementSetter preparedStatementSetter;

	String sql;

	RowHashMapper<T> rowMapper;


	public JdbcHashItemReader() {
		super();
	}

	

	public RowHashMapper getRowMapper() {
		return rowMapper;
	}



	public void setRowMapper(RowHashMapper rowMapper) {
		this.rowMapper = rowMapper;
	}



	/**
	 * Set the SQL statement to be used when creating the cursor. This statement
	 * should be a complete and valid SQL statement, as it will be run directly
	 * without any modification.
	 * 
	 * @param sql
	 */
	public void setSql(String sql) {
		this.sql = sql;
	}

	/**
	 * Set the PreparedStatementSetter to use if any parameter values that need
	 * to be set in the supplied query.
	 * 
	 * @param preparedStatementSetter
	 */
	public void setPreparedStatementSetter(PreparedStatementSetter preparedStatementSetter) {
		this.preparedStatementSetter = preparedStatementSetter;
	}

	/**
	 * Assert that mandatory properties are set.
	 * 
	 * @throws IllegalArgumentException if either data source or sql properties
	 * not set.
	 */
	public void afterPropertiesSet() throws Exception {
		super.afterPropertiesSet();
		Assert.notNull(sql, "The SQL query must be provided");
		Assert.notNull(rowMapper, "RowMapper must be provided");
	}


	protected void openCursor(Connection con) {	
		try {
			if (isUseSharedExtendedConnection()) {
				preparedStatement = con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY,
						ResultSet.HOLD_CURSORS_OVER_COMMIT);
			}
			else {
				preparedStatement = con.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
			}
			applyStatementSettings(preparedStatement);
			if (this.preparedStatementSetter != null) {
				preparedStatementSetter.setValues(preparedStatement);
			}
			this.rs = preparedStatement.executeQuery();
			handleWarnings(preparedStatement);
		}
		catch (SQLException se) {
			close();
			throw getExceptionTranslator().translate("Executing query", getSql(), se);
		}
	
	}


	@SuppressWarnings("unchecked")
	protected T readCursor(ResultSet rs, int currentRow) throws SQLException {
		return  rowMapper.mapRow( rs,  currentRow) ;
	}
	
	/**
	 * Close the cursor and database connection.
	 */
	protected void cleanupOnClose() throws Exception {
		JdbcUtils.closeStatement(this.preparedStatement);
	}

	@Override
	public String getSql() {
		return this.sql;
	}

}




SimpleRetryPolicy
/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.batch.retry.policy;

import java.util.Collections;
import java.util.Map;

import org.springframework.batch.classify.BinaryExceptionClassifier;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryPolicy;
import org.springframework.batch.retry.context.RetryContextSupport;

/**
 * 
 * Simple retry policy that retries a fixed number of times for a set of named
 * exceptions (and subclasses). The number of attempts includes the initial try,
 * so e.g.
 * 
 * <pre>
 * retryTemplate = new RetryTemplate(new SimpleRetryPolicy(3));
 * retryTemplate.execute(callback);
 * </pre>
 * 
 * will execute the callback at least once, and as many as 3 times.
 * 
 * @author Dave Syer
 * @author Rob Harrop
 * 
 */
public class SimpleRetryPolicy implements RetryPolicy {

	/**
	 * The default limit to the number of attempts for a new policy.
	 */
	public final static int DEFAULT_MAX_ATTEMPTS = 3;

	private volatile int maxAttempts;

	private volatile BinaryExceptionClassifier retryableClassifier = new BinaryExceptionClassifier(false);

	/**
	 * Create a {@link SimpleRetryPolicy} with the default number of retry
	 * attempts.
	 */
	public SimpleRetryPolicy() {
		this(DEFAULT_MAX_ATTEMPTS, Collections
				.<Class<? extends Throwable>, Boolean> singletonMap(Exception.class, true));
	}

	/**
	 * Create a {@link SimpleRetryPolicy} with the specified number of retry
	 * attempts.
	 * 
	 * @param maxAttempts
	 * @param retryableExceptions
	 */
	public SimpleRetryPolicy(int maxAttempts, Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
		super();
		this.maxAttempts = maxAttempts;
		this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions);
	}

	/**
	 * @param retryableExceptions
	 */
	public void setRetryableExceptions(Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
		this.retryableClassifier = new BinaryExceptionClassifier(retryableExceptions);
	}

	/**
	 * Setter for retry attempts.
	 * 
	 * @param retryAttempts the number of attempts before a retry becomes
	 * impossible.
	 */
	public void setMaxAttempts(int retryAttempts) {
		this.maxAttempts = retryAttempts;
	}
	
	/**
	 * The maximum number of retry attempts before failure.
	 * 
	 * @return the maximum number of attempts
	 */
	public int getMaxAttempts() {
		return maxAttempts;
	}

	/**
	 * Test for retryable operation based on the status.
	 * 
	 * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext)
	 * 
	 * @return true if the last exception was retryable and the number of
	 * attempts so far is less than the limit.
	 */
	public boolean canRetry(RetryContext context) {
		Throwable t = context.getLastThrowable();
		return (t == null || retryForException(t)) && context.getRetryCount() < maxAttempts;
	}

	/**
	 * @see org.springframework.batch.retry.RetryPolicy#close(RetryContext)
	 */
	public void close(RetryContext status) {
	}

	/**
	 * Update the status with another attempted retry and the latest exception.
	 * 
	 * @see RetryPolicy#registerThrowable(RetryContext, Throwable)
	 */
	public void registerThrowable(RetryContext context, Throwable throwable) {
		SimpleRetryContext simpleContext = ((SimpleRetryContext) context);
		simpleContext.registerThrowable(throwable);
	}

	/**
	 * Get a status object that can be used to track the current operation
	 * according to this policy. Has to be aware of the latest exception and the
	 * number of attempts.
	 * 
	 * @see org.springframework.batch.retry.RetryPolicy#open(RetryContext)
	 */
	public RetryContext open(RetryContext parent) {
		return new SimpleRetryContext(parent);
	}

	private static class SimpleRetryContext extends RetryContextSupport {
		public SimpleRetryContext(RetryContext parent) {
			super(parent);
		}
	}

	/**
	 * Delegates to an exception classifier.
	 * 
	 * @param ex
	 * @return true if this exception or its ancestors have been registered as
	 * retryable.
	 */
	private boolean retryForException(Throwable ex) {
		return retryableClassifier.classify(ex);
	}
}


TimeoutRetryPolicy

/*
 * Copyright 2006-2007 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.batch.retry.policy;

import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryPolicy;
import org.springframework.batch.retry.context.RetryContextSupport;

/**
 * A {@link RetryPolicy} that allows a retry only if it hasn't timed out. The
 * clock is started on a call to {@link #open(RetryContext)}.
 * 
 * @author Dave Syer
 * 
 */
public class TimeoutRetryPolicy implements RetryPolicy {

	/**
	 * Default value for timeout (milliseconds).
	 */
	public static final long DEFAULT_TIMEOUT = 1000;

	private long timeout = DEFAULT_TIMEOUT;

	/**
	 * Setter for timeout in milliseconds. Default is {@link #DEFAULT_TIMEOUT}.
	 * @param timeout
	 */
	public void setTimeout(long timeout) {
		this.timeout = timeout;
	}
	
	/**
	 * The value of the timeout.
	 * 
	 * @return the timeout in milliseconds
	 */
	public long getTimeout() {
		return timeout;
	}

	/**
	 * Only permits a retry if the timeout has not expired. Does not check the
	 * exception at all.
	 * 
	 * @see org.springframework.batch.retry.RetryPolicy#canRetry(org.springframework.batch.retry.RetryContext)
	 */
	public boolean canRetry(RetryContext context) {
		return ((TimeoutRetryContext) context).isAlive();
	}

	public void close(RetryContext context) {
	}

	public RetryContext open(RetryContext parent) {
		return new TimeoutRetryContext(parent, timeout);
	}

	public void registerThrowable(RetryContext context, Throwable throwable) {
		((RetryContextSupport) context).registerThrowable(throwable);
		// otherwise no-op - we only time out, otherwise retry everything...
	}

	private static class TimeoutRetryContext extends RetryContextSupport {
		private long timeout;

		private long start;

		public TimeoutRetryContext(RetryContext parent, long timeout) {
			super(parent);
			this.start = System.currentTimeMillis();
			this.timeout = timeout;
		}

		public boolean isAlive() {
			return (System.currentTimeMillis() - start) <= timeout;
		}
	}

}
分享到:
评论

相关推荐

    Project Server数据备份

    使用每日备份计划备份数据;创建、调度和还原 Microsoft Project Server数据库的备份备份数据库;使用管理中心备份数据库

    PROJECT 2007宝典 9/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 7/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 1/10

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 5/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    project2007中文教程(中文带Project cerver2007教程).pdf

    pdf文件,还不错,自己下载用于学习的,上传到此,共享一下,也是给自己以后要用时留个备份。

    Python实现备份文件实例

    dir=h:/Project ; 指定备份的目录 recusive=1 ; 是否递归子目录 suffix=h|cpp|hpp|c|user|filters|vcxproj|sln|css|gif|html|bmp|png|lib|dsw|dsp|htm|html|ico|ini|jpg|rc|vssscc ; 指定备份的扩展名 exclude

    SVN备份还原清理BAT

    增量备份:svndump.bat(使用前先修改目录)、dump.bat、projectlist.conf(使用前先修改svn版本库名) 还原:svnload.bat(使用前先修改目录、版本库名、备份) 清理:clearSVNBackup.bat(使用VBS,使用前修改目录和指定...

    Delphi源码备份

    Delphi Project Backup Delphi备份工具 经常写程序的朋友一定都知道备份的重要性吧,一次忘记备份可能会让你欲哭无泪,在这方面,在这方面我也曾经有过惨痛教训,于是就写了 这个小工具。 它是专门为了备份...

    PROJECT 2007宝典 4/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    RRRoger#FirstProject#定时自动备份1

    定时自动备份1. 添加脚本粘贴以下文本修改文件权限2. 创建定时任务在最后一行添加(每周执行一次)0 0 * * 0 postgres /var/lib/pos

    svn备份还原方法

    svnadmin dump D:\Repositories\TestProject &gt; D:\svndumpfile\TestProject_20090722.dump 2、将dump文件拷贝到目标机器 3、在目标机器创建仓库: svnadmin create D:/repositories/TestProject 并注意检查...

    unrealcpp-full-project:用于备份的unrealcpp完整项目和用于项目中断错误的版本控制

    unrealcpp完整项目 unrealcpp完整项目用于备份,版本控制用于项目中断错误

    Tomcat日志文件定时清理备份的脚本

    以下脚本主要备份的日志文件为tomcat的catalina.out、localhost_access_log.yyyy-mm-dd.log日志和项目的日志文件,其中项目的日志文件格式为”projectname-yyyy-mm-dd.log”,以下为备份脚本,具体的操作都有相应的...

    PROJECT 2007宝典 8/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 6/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 3/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    PROJECT 2007宝典 2/9

    PROJECT 2007 宝典 OFFICE2007 OFFICE2010 PROJECT 2007宝典 原价:88.00元 作者:(美)马默 著,安晓梅,范书义 译 出版社:人民邮电出版社 出版日期:2008-1-1 ISBN:9787115167699 字数:1046000 页码:587 --...

    Delphi备份和清除Delphi工程文件.rar

    DELPHI删除指定目录下指定扩展名的文件,使用右键菜单备份Delphi工程文件,实现的功能有:  清除Delphi工程中的临时文件  备份Delphi工程(同时清除临时文件)  完整备份Delphi工程(包含临时文件)'  设置Delphi...

    WindChill 备份详细说明

    windchill 中文备份恢复文档,支持版本Windchill® 10.0 Windchill PDMLink® Windchill ProjectLink™ Pro/INTRALINK® 10.0

Global site tag (gtag.js) - Google Analytics