
import at.clockwork.security.domain.*

import groovy.sql.Sql
import java.sql.Connection
import java.sql.DriverManager
import javax.sql.DataSource




class UpdateScriptService {

	def run(def connection, def dataSourceFields) {

		connection.eachRow('select a.id, a.operation_role_id, b.cwid from cw_operator_type_detail a, cw_operation_role b where a.operator_role_id is null and a.operation_role_id is not null and a.operation_role_id = b.id') {

			OperatorRole operatorRole = OperatorRole.findWhere(cwID:it.cwid)
			if (operatorRole) {
				def resultMap = at.clockwork.system.service.DataSourceService.execute(
					connection,
					dataSourceFields,
					[
						mySQLStatement:"update cw_operator_type_detail set operator_role_id = " + operatorRole.id + " where id = " + it.id,
						msSQLStatement:"update cw_operator_type_detail set operator_role_id = " + operatorRole.id + " where id = " + it.id
					]
				)
			}

		}

		true
	}
}
