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.HashMap; import java.util.List; import java.util.Map; import java.util.Set; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.dao.DataAccessException; import com.pactera.edg.am.metamanager.extractor.bo.mm.AbstractMetadata; import com.pactera.edg.am.metamanager.extractor.bo.mm.MMMetaModel; import com.pactera.edg.am.metamanager.extractor.dao.ISequenceDao; import com.pactera.edg.am.metamanager.extractor.util.AdapterExtractorContext; /** * ?,??PreparedStatementCallback * * @author hqchen * @version 1.0 Date: Oct 10, 2009 */ public class DeleteMetadataAlterHelper extends PreparedStatementCallbackHelper { private Log log = LogFactory.getLog(CreateMetadataAlterHelper.class); protected Set<MMMetaModel> metaModels; protected ISequenceDao sequenceDao; protected String taskInstanceId; // ID protected String userId; protected long startTime; /** * ?ID??,key:?ID,value:namespace */ protected Map<String, String> namespaceCache = new HashMap<String, String>(); public DeleteMetadataAlterHelper(int batchSize) { super(batchSize); userId = AdapterExtractorContext.getInstance().getUserId(); } /** * ID? * * @param sequenceDao */ public void setSequenceDao(ISequenceDao sequenceDao) { this.sequenceDao = sequenceDao; } public void setMetaModels(Set<MMMetaModel> metaModels) { this.metaModels = metaModels; } public Object doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException { startTime = AdapterExtractorContext.getInstance().getGlobalTime(); taskInstanceId = AdapterExtractorContext.getInstance().getTaskInstanceId(); for (MMMetaModel metaModel : metaModels) { batchLoadDelete(ps, metaModel); } if (super.count % super.batchSize != 0) { ps.executeBatch(); ps.clearBatch(); } return null; } private void batchLoadDelete(PreparedStatement ps, MMMetaModel metaModel) throws SQLException { if (metaModel.isHasMetadata()) { // ? List<AbstractMetadata> metadatas = metaModel.getMetadatas(); doInPreparedStatement(ps, metaModel.getCode(), metaModel.isHasChildMetaModel(), metadatas); } if (metaModel.isHasChildMetaModel()) { // ? for (MMMetaModel childMetaModel : metaModel.getChildMetaModels()) { batchLoadDelete(ps, childMetaModel); } } } protected void doInPreparedStatement(PreparedStatement ps, String metaModelCode, boolean hasChildMetaModel, List<AbstractMetadata> metadatas) throws SQLException { try { for (AbstractMetadata metadata : metadatas) { // ?ID String sequenceId = sequenceDao.getUuid(); ps.setString(1, sequenceId); // ?,1 ps.setString(2, "1"); // ID ps.setString(3, taskInstanceId); // // ?ID // ps.setString(4, metadata.getId()); // // // ps.setString(5, metaModelCode); // ID ps.setString(4, userId); // START_TIME?START_TIME ps.setLong(5, metadata.getStartTime()); // : ALTERATION_TIME ps.setLong(6, startTime); // OLD_START_TIME ???OLD_START_TIME?? ps.setNull(7, java.sql.Types.BIGINT); // ?ID ps.setString(8, metadata.getId()); ps.addBatch(); ps.clearParameters(); if (++super.count % super.batchSize == 0) { ps.executeBatch(); ps.clearBatch(); } } } catch (SQLException e) { // ??,????,,?? log.warn("??!", e); } } }