`

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 数据备份】 在IT管理中,定期备份数据是至关重要的,特别是对于像Microsoft Project Server这样的关键业务系统。Project Server数据备份涉及到多个步骤,包括设置每日备份计划、手动...

    Project2003-2007转换器

    3. **备份**:在转换前,总是备份原始项目文件,以防万一转换失败或出现数据丢失。 4. **测试**:先对小规模的项目文件进行测试,确保转换结果满意后再处理大型或关键的项目文件。 5. **格式差异**:了解不同版本的...

    Project Server 2010 配置详解_project_MSproject配置说明_

    2. **备份与恢复**:制定定期备份策略,确保数据安全。了解恢复过程,以防万一需要恢复到特定状态。 3. **更新与补丁**:保持系统更新,安装必要的安全补丁和功能更新,确保系统稳定和安全。 4. **用户培训**:...

    project server 配置手册

    手册会详细说明如何配置数据库连接、备份策略和性能优化,确保数据的安全性和访问效率。 5. **项目计划与执行**:配置手册会涵盖如何创建、分配和管理项目计划,包括任务、资源和成本的规划。此外,还会有监控项目...

    svn备份、还原与迁移操作手册.docx

    SVN 备份、还原与迁移操作手册 SVN(Subversion)是一种版本控制系统,用于管理软件开发过程中的代码变更。备份、还原和迁移是 SVN 中三项非常重要的操作,以下是关于 SVN 备份、还原与迁移的知识点总结: 一、SVN...

    Project+server+2007完全安装

    1. 定期备份:为防止数据丢失,应定期备份Project Server数据库。 2. 更新与补丁:保持系统最新,安装微软发布的安全更新和Service Pack。 3. 监控与日志:分析系统日志,及时发现并解决问题。 Project Server 2007...

    ProjectServer异机恢复解决方案

    登录到服务器,选择要备份的数据库(ProjectServer_Published、ProjectServer_Draft、ProjectServer_Archive、ProjectServer_Reporting),对每个数据库执行完整备份,将备份文件保存在安全位置。 1.1.2 **异机环境...

    svn备份还原方法

    - 其中,`D:\Repositories\TestProject`是需要备份的仓库路径。 - `D:\svndumpfile\TestProject_20090722.dump`是备份文件的保存位置及文件名。 - 上述命令会将指定仓库的所有数据压缩成一个名为`TestProject_...

    delphi数据库的备份

    在IT行业中,数据库备份是至关重要的任务,它确保了数据的安全性和可恢复性。Delphi是一种流行的集成开发环境(IDE),常用于创建Windows应用程序,包括处理数据库操作。本篇文章将详细讲解如何使用Delphi 7来实现...

    SVN增量备份-附带脚本

    2. **后续增量备份**:之后的每次备份,使用`dump.bat`和`svndump.bat`结合`projectlist.conf`中的配置,只转储和备份自上次备份以来有变更的项目或文件。 3. **备份存储与管理**:备份文件应保存在安全可靠的存储...

    Step_3__config_Project_Server_2007.pdf

    ### Project Server 2007 配置指南 #### 一、引言 随着企业级项目的日益复杂化,项目管理工具的需求也在不断增长。Microsoft Project Server 2007 是一款集成了项目管理、资源管理和协作功能的强大工具,能够帮助...

    PROJECT 2007宝典 9/9

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

    增量备份复制

    增量备份是一种有效的数据保护策略,尤其对于频繁更新的数据而言,它可以显著减少备份所需的时间和存储空间。在Delphi 7这个强大的集成开发环境下,我们可以构建一个窗口界面的应用程序,实现增量备份的功能。这个名...

    Office Project Server 2007 部署图示指南.pdf

    此外,指南可能会介绍一些高级话题,如性能优化、高可用性配置(如群集和故障转移)、备份和恢复策略,以及安全性和合规性考虑。这些都对于保持系统的稳定运行和保护敏感数据至关重要。 最后,由于Office Project ...

    project server 2007 超详细设置说明

    - **备份**:在安装和配置过程中,定期备份重要数据。 #### 四、结语 通过上述步骤,您可以顺利完成Project Server 2007 的安装和配置工作。这将为企业提供一个强大的项目管理平台,帮助企业更有效地管理项目生命...

    Excel VBA Project密码移除代码

    在尝试之前,一定要备份原始文件。此外,此方法仅适用于你知道或忘记了密码的情况,而不是用于非法破解他人的保护。 最后,值得注意的是,Microsoft并不支持或鼓励这种行为。如果你在工作中遇到需要访问密码保护的...

    PROJECT 2007宝典 7/9

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

Global site tag (gtag.js) - Google Analytics