Java tutorial
/* * Copyright 2009 by pactera.edg.am Corporation. Address:HePingLi East Street No.11 * 5-5, BeiJing, * * All rights reserved. * * This software is the confidential and proprietary information of pactera.edg.am * Corporation ("Confidential Information"). You shall not disclose such * Confidential Information and shall use it only in accordance with the terms * of the license agreement you entered into with pactera.edg.am. */ package com.pactera.edg.am.metamanager.extractor.dao.helper; import java.sql.PreparedStatement; import java.sql.SQLException; import java.util.Iterator; import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.pactera.edg.am.metamanager.extractor.bo.ExtractorLogLevel; import com.pactera.edg.am.metamanager.extractor.bo.mm.MMDDependency; import com.pactera.edg.am.metamanager.extractor.util.AdapterExtractorContext; /** * ???PreparedStatementCallback * * @author hqchen * @version 1.0 Date: Aug 21, 2009 */ public class CreateDependencyHelper extends PreparedStatementCallbackHelper { private Log log = LogFactory.getLog(CreateDependencyHelper.class); protected List<MMDDependency> dependenciesList; public CreateDependencyHelper(int batchSize) { super(batchSize); } public void setDependenciesList(List<MMDDependency> dependenciesList) { this.dependenciesList = dependenciesList; } public Object doInPreparedStatement(PreparedStatement ps) throws SQLException { String logMsg = ""; // ??? long sysTime = AdapterExtractorContext.getInstance().getGlobalTime(); for (Iterator<MMDDependency> dependencies = dependenciesList.iterator(); dependencies.hasNext();) { MMDDependency dependency = dependencies.next(); myDoInPreparedStatement(sysTime, dependency, ps); } if (super.count % super.batchSize != 0) { ps.executeBatch(); ps.clearBatch(); } logMsg = "?:" + dependenciesList.size(); log.info(logMsg); AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.INFO, logMsg); return null; } private void myDoInPreparedStatement(long sysTime, MMDDependency dependency, PreparedStatement ps) throws SQLException { String ownerModelId = dependency.getOwnerMetadata().getClassifierId(); String valueModelId = dependency.getValueMetadata().getClassifierId(); try { // ?ID ps.setString(1, dependency.getOwnerMetadata().getId()); // ?ID ps.setString(2, ownerModelId); // ?ID ps.setString(3, dependency.getValueMetadata().getId()); // ?ID ps.setString(4, valueModelId); // ??? ps.setString(5, dependency.getCode()); // ps.setLong(6, sysTime); ps.setString(7, "1"); ps.setString(8, "1"); setPs(ps, 8); ps.addBatch(); // ?? ps.clearParameters(); if (++super.count % super.batchSize == 0) { ps.executeBatch(); ps.clearBatch(); } } catch (SQLException e) { String logMsg = new StringBuilder().append("?,?:??ID:") .append(dependency.getOwnerMetadata().getId()).append(",?:") .append(ownerModelId).append(",??ID:") .append(dependency.getValueMetadata().getId()).append(",?:") .append(valueModelId).append(", ???:").append(dependency.getCode()).toString(); log.error(logMsg); AdapterExtractorContext.addExtractorLog(ExtractorLogLevel.ERROR, logMsg); throw e; } } protected void setPs(PreparedStatement ps, int index) throws SQLException { } }