Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Nov 12th, 2018 110 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. Imports Oracle.ManagedDataAccess.Client
  2. Imports Oracle.ManagedDataAccess.Types
  3.  
  4. Public Class UserDAO
  5.   Private Const CONNECTION_STR As String = "・・・"
  6.  
  7.   ' 全件検索
  8.   Public Shared Function SelectAll() As List(Of User)
  9.    
  10.   End Function
  11.  
  12.   ' 新規ユーザー登録
  13.   Public Shared Function Insert(id As Integer, name As String, email As String, inviterid As Integer) As RecordUserResultEnum
  14.       Using con As New OracleConnection(CONNECTION_STR)
  15.         ' ユーザーマスタ登録用
  16.         Dim cmd4user As New OracleCommand("INSERT INTO 異常系演習ユーザーマスタ(id, 氏名, email) VALUES(:ユーザーID, :氏名, :email)", con)
  17.         cmd4user.Parameters.Add(New OracleParameter("ユーザーID", OracleDbType.Int32))
  18.         cmd4user.Parameters.Add(New OracleParameter("氏名", OracleDbType.NVarchar2))
  19.         cmd4user.Parameters.Add(New OracleParameter("email", OracleDbType.NVarchar2))
  20.  
  21.         ' 紹介者データ登録用
  22.         Dim cmd4inviter As New OracleCommand("INSERT INTO 異常系演習紹介者データ(ユーザーid, 紹介者id) VALUES(:ユーザーID, :紹介者ID)", con)
  23.         cmd4inviter.Parameters.Add(New OracleParameter("ユーザーid", OracleDbType.Int32))
  24.         cmd4inviter.Parameters.Add(New OracleParameter("紹介者id", OracleDbType.Int32))
  25.  
  26.         ' DB接続
  27.         con.Open()
  28.  
  29.         ' トランザクション開始
  30.         Using tx As OracleTransaction = con.BeginTransaction
  31.           cmd4user.Transaction = tx
  32.           cmd4inviter.Transaction = tx
  33.  
  34.           ' ユーザーマスタ 登録
  35.           cmd4user.Parameters("ユーザーID").Value = id
  36.           cmd4user.Parameters("氏名").Value = name
  37.           cmd4user.Parameters("email").Value = email
  38.           Try
  39.             cmd4user.ExecuteNonQuery()
  40.           Catch ex As OracleException
  41.             tx.Rollback()
  42.             ' ID重複時(主キー違反)はエラー通知
  43.             ' それ以外は、そのままスローし直し
  44.             If ex.Number = 1 Then
  45.               ' ID重複
  46.               Return RecordUserResultEnum.DuplicateIDError
  47.             Else
  48.               ' それ以外
  49.               Throw ex
  50.             End If
  51.     End Try
  52.  
  53.                 ' 紹介者データ 登録
  54.                 cmd4inviter.Parameters("ユーザーid").Value = id
  55.                 cmd4inviter.Parameters("紹介者id").Value = inviterid
  56.                 Try
  57.                     cmd4inviter.ExecuteNonQuery()
  58.                 Catch ex As OracleException
  59.                     tx.Rollback()
  60.  
  61.                     ' 紹介者がいない(外部キーエラー)時はエラー通知
  62.                     ' それ以外は、そのままスローし直し
  63.                     If ex.Number = 2291 Then
  64.                         Return RecordUserResultEnum.InviterNotFoundError
  65.                     Else
  66.                         Throw ex
  67.                     End If
  68.                 End Try
  69.  
  70.                 ' コミット
  71.                 tx.Commit()
  72.  
  73.             End Using
  74.         End Using
  75.  
  76.         Return RecordUserResultEnum.Success
  77.  
  78.     End Function
  79. End Class
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top