1 5 package com.tdsecurities.itracker.converter; 6 7 import java.sql.PreparedStatement ; 8 import java.sql.ResultSet ; 9 import java.sql.SQLException ; 10 import java.sql.Timestamp ; 11 import java.util.Date ; 12 13 import org.apache.log4j.Logger; 14 15 import com.tdsecurities.itracker.common.DataSourceManager; 16 17 21 public class PermissionConverter extends BasicConverter 22 { 23 private static final String SOURCE_SQL = "select * from user_group"; 24 private static final String TARGET_SQL = "insert into permissionbean (id,type,create_date,last_modified,project_id,user_id) values (?,?,?,?,?,?)"; 25 private static final String LAST_ID_SQL = "select max(id) from permissionbean"; 26 27 private Logger log = Logger.getLogger(PermissionConverter.class); 28 private long id = 1; 29 30 protected String getSourceQuery() 31 { 32 return SOURCE_SQL; 33 } 34 35 protected String getTargetQuery() 36 { 37 return TARGET_SQL; 38 } 39 40 protected String getIdStoreName() 41 { 42 return "permission"; 43 } 44 45 protected String getLastIdQuery() 46 { 47 return LAST_ID_SQL; 48 } 49 50 protected int prepareTargetStatement(PreparedStatement targetStmt, ResultSet rs) throws Exception 51 { 52 return BasicConverter.SKIP_ROW; 53 } 54 55 protected void additionalProcessing(PreparedStatement targetStmt, ResultSet rs) 56 throws SQLException 57 { 58 long now = (new Date ()).getTime(); 59 int startPermission = 2; 60 if( !"".equals(rs.getString("admin_flags"))) 61 { 62 startPermission = 1; 63 } 64 65 for( int i = startPermission; i <= 9; i++) 66 { 67 int col = 1; 68 targetStmt.setLong(col++, id++); 69 targetStmt.setInt(col++, i); 70 targetStmt.setTimestamp(col++, new Timestamp (now)); 71 targetStmt.setTimestamp(col++, new Timestamp (now)); 72 targetStmt.setInt(col++, rs.getInt("group_id")); 73 targetStmt.setInt(col++, rs.getInt("user_id")); 74 targetStmt.executeUpdate(); 75 } 76 } 77 78 protected void preConversionProcessing() 79 { 80 log.info("Converting permissions ..."); 81 executeUpdate(DataSourceManager.ITRACKER, "delete from permissionbean"); 82 } 83 84 protected void postConversionProcessing() 85 { 86 log.info("Converted permissions."); 87 } 88 } 89 | Popular Tags |