{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.RDSData.BeginTransaction
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Starts a SQL transaction.
--
-- >  <important> <p>A transaction can run for a maximum of 24 hours. A transaction is terminated and rolled back automatically after 24 hours.</p> <p>A transaction times out if no calls use its transaction ID in three minutes. If a transaction times out before it's committed, it's rolled back automatically.</p> <p>DDL statements inside a transaction cause an implicit commit. We recommend that you run each DDL statement in a separate <code>ExecuteStatement</code> call with <code>continueAfterTimeout</code> enabled.</p> </important>
module Amazonka.RDSData.BeginTransaction
  ( -- * Creating a Request
    BeginTransaction (..),
    newBeginTransaction,

    -- * Request Lenses
    beginTransaction_database,
    beginTransaction_schema,
    beginTransaction_resourceArn,
    beginTransaction_secretArn,

    -- * Destructuring the Response
    BeginTransactionResponse (..),
    newBeginTransactionResponse,

    -- * Response Lenses
    beginTransactionResponse_transactionId,
    beginTransactionResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.RDSData.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | The request parameters represent the input of a request to start a SQL
-- transaction.
--
-- /See:/ 'newBeginTransaction' smart constructor.
data BeginTransaction = BeginTransaction'
  { -- | The name of the database.
    BeginTransaction -> Maybe Text
database :: Prelude.Maybe Prelude.Text,
    -- | The name of the database schema.
    BeginTransaction -> Maybe Text
schema :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
    BeginTransaction -> Text
resourceArn :: Prelude.Text,
    -- | The name or ARN of the secret that enables access to the DB cluster.
    BeginTransaction -> Text
secretArn :: Prelude.Text
  }
  deriving (BeginTransaction -> BeginTransaction -> Bool
(BeginTransaction -> BeginTransaction -> Bool)
-> (BeginTransaction -> BeginTransaction -> Bool)
-> Eq BeginTransaction
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BeginTransaction -> BeginTransaction -> Bool
$c/= :: BeginTransaction -> BeginTransaction -> Bool
== :: BeginTransaction -> BeginTransaction -> Bool
$c== :: BeginTransaction -> BeginTransaction -> Bool
Prelude.Eq, ReadPrec [BeginTransaction]
ReadPrec BeginTransaction
Int -> ReadS BeginTransaction
ReadS [BeginTransaction]
(Int -> ReadS BeginTransaction)
-> ReadS [BeginTransaction]
-> ReadPrec BeginTransaction
-> ReadPrec [BeginTransaction]
-> Read BeginTransaction
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BeginTransaction]
$creadListPrec :: ReadPrec [BeginTransaction]
readPrec :: ReadPrec BeginTransaction
$creadPrec :: ReadPrec BeginTransaction
readList :: ReadS [BeginTransaction]
$creadList :: ReadS [BeginTransaction]
readsPrec :: Int -> ReadS BeginTransaction
$creadsPrec :: Int -> ReadS BeginTransaction
Prelude.Read, Int -> BeginTransaction -> ShowS
[BeginTransaction] -> ShowS
BeginTransaction -> String
(Int -> BeginTransaction -> ShowS)
-> (BeginTransaction -> String)
-> ([BeginTransaction] -> ShowS)
-> Show BeginTransaction
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BeginTransaction] -> ShowS
$cshowList :: [BeginTransaction] -> ShowS
show :: BeginTransaction -> String
$cshow :: BeginTransaction -> String
showsPrec :: Int -> BeginTransaction -> ShowS
$cshowsPrec :: Int -> BeginTransaction -> ShowS
Prelude.Show, (forall x. BeginTransaction -> Rep BeginTransaction x)
-> (forall x. Rep BeginTransaction x -> BeginTransaction)
-> Generic BeginTransaction
forall x. Rep BeginTransaction x -> BeginTransaction
forall x. BeginTransaction -> Rep BeginTransaction x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BeginTransaction x -> BeginTransaction
$cfrom :: forall x. BeginTransaction -> Rep BeginTransaction x
Prelude.Generic)

-- |
-- Create a value of 'BeginTransaction' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'database', 'beginTransaction_database' - The name of the database.
--
-- 'schema', 'beginTransaction_schema' - The name of the database schema.
--
-- 'resourceArn', 'beginTransaction_resourceArn' - The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
--
-- 'secretArn', 'beginTransaction_secretArn' - The name or ARN of the secret that enables access to the DB cluster.
newBeginTransaction ::
  -- | 'resourceArn'
  Prelude.Text ->
  -- | 'secretArn'
  Prelude.Text ->
  BeginTransaction
newBeginTransaction :: Text -> Text -> BeginTransaction
newBeginTransaction Text
pResourceArn_ Text
pSecretArn_ =
  BeginTransaction' :: Maybe Text -> Maybe Text -> Text -> Text -> BeginTransaction
BeginTransaction'
    { $sel:database:BeginTransaction' :: Maybe Text
database = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:schema:BeginTransaction' :: Maybe Text
schema = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:resourceArn:BeginTransaction' :: Text
resourceArn = Text
pResourceArn_,
      $sel:secretArn:BeginTransaction' :: Text
secretArn = Text
pSecretArn_
    }

-- | The name of the database.
beginTransaction_database :: Lens.Lens' BeginTransaction (Prelude.Maybe Prelude.Text)
beginTransaction_database :: (Maybe Text -> f (Maybe Text))
-> BeginTransaction -> f BeginTransaction
beginTransaction_database = (BeginTransaction -> Maybe Text)
-> (BeginTransaction -> Maybe Text -> BeginTransaction)
-> Lens BeginTransaction BeginTransaction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransaction' {Maybe Text
database :: Maybe Text
$sel:database:BeginTransaction' :: BeginTransaction -> Maybe Text
database} -> Maybe Text
database) (\s :: BeginTransaction
s@BeginTransaction' {} Maybe Text
a -> BeginTransaction
s {$sel:database:BeginTransaction' :: Maybe Text
database = Maybe Text
a} :: BeginTransaction)

-- | The name of the database schema.
beginTransaction_schema :: Lens.Lens' BeginTransaction (Prelude.Maybe Prelude.Text)
beginTransaction_schema :: (Maybe Text -> f (Maybe Text))
-> BeginTransaction -> f BeginTransaction
beginTransaction_schema = (BeginTransaction -> Maybe Text)
-> (BeginTransaction -> Maybe Text -> BeginTransaction)
-> Lens BeginTransaction BeginTransaction (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransaction' {Maybe Text
schema :: Maybe Text
$sel:schema:BeginTransaction' :: BeginTransaction -> Maybe Text
schema} -> Maybe Text
schema) (\s :: BeginTransaction
s@BeginTransaction' {} Maybe Text
a -> BeginTransaction
s {$sel:schema:BeginTransaction' :: Maybe Text
schema = Maybe Text
a} :: BeginTransaction)

-- | The Amazon Resource Name (ARN) of the Aurora Serverless DB cluster.
beginTransaction_resourceArn :: Lens.Lens' BeginTransaction Prelude.Text
beginTransaction_resourceArn :: (Text -> f Text) -> BeginTransaction -> f BeginTransaction
beginTransaction_resourceArn = (BeginTransaction -> Text)
-> (BeginTransaction -> Text -> BeginTransaction)
-> Lens BeginTransaction BeginTransaction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransaction' {Text
resourceArn :: Text
$sel:resourceArn:BeginTransaction' :: BeginTransaction -> Text
resourceArn} -> Text
resourceArn) (\s :: BeginTransaction
s@BeginTransaction' {} Text
a -> BeginTransaction
s {$sel:resourceArn:BeginTransaction' :: Text
resourceArn = Text
a} :: BeginTransaction)

-- | The name or ARN of the secret that enables access to the DB cluster.
beginTransaction_secretArn :: Lens.Lens' BeginTransaction Prelude.Text
beginTransaction_secretArn :: (Text -> f Text) -> BeginTransaction -> f BeginTransaction
beginTransaction_secretArn = (BeginTransaction -> Text)
-> (BeginTransaction -> Text -> BeginTransaction)
-> Lens BeginTransaction BeginTransaction Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransaction' {Text
secretArn :: Text
$sel:secretArn:BeginTransaction' :: BeginTransaction -> Text
secretArn} -> Text
secretArn) (\s :: BeginTransaction
s@BeginTransaction' {} Text
a -> BeginTransaction
s {$sel:secretArn:BeginTransaction' :: Text
secretArn = Text
a} :: BeginTransaction)

instance Core.AWSRequest BeginTransaction where
  type
    AWSResponse BeginTransaction =
      BeginTransactionResponse
  request :: BeginTransaction -> Request BeginTransaction
request = Service -> BeginTransaction -> Request BeginTransaction
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy BeginTransaction
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BeginTransaction)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse BeginTransaction))
-> Logger
-> Service
-> Proxy BeginTransaction
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse BeginTransaction)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text -> Int -> BeginTransactionResponse
BeginTransactionResponse'
            (Maybe Text -> Int -> BeginTransactionResponse)
-> Either String (Maybe Text)
-> Either String (Int -> BeginTransactionResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"transactionId")
            Either String (Int -> BeginTransactionResponse)
-> Either String Int -> Either String BeginTransactionResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable BeginTransaction

instance Prelude.NFData BeginTransaction

instance Core.ToHeaders BeginTransaction where
  toHeaders :: BeginTransaction -> ResponseHeaders
toHeaders =
    ResponseHeaders -> BeginTransaction -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON BeginTransaction where
  toJSON :: BeginTransaction -> Value
toJSON BeginTransaction' {Maybe Text
Text
secretArn :: Text
resourceArn :: Text
schema :: Maybe Text
database :: Maybe Text
$sel:secretArn:BeginTransaction' :: BeginTransaction -> Text
$sel:resourceArn:BeginTransaction' :: BeginTransaction -> Text
$sel:schema:BeginTransaction' :: BeginTransaction -> Maybe Text
$sel:database:BeginTransaction' :: BeginTransaction -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"database" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
database,
            (Text
"schema" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
schema,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"resourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
resourceArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"secretArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
secretArn)
          ]
      )

instance Core.ToPath BeginTransaction where
  toPath :: BeginTransaction -> ByteString
toPath = ByteString -> BeginTransaction -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/BeginTransaction"

instance Core.ToQuery BeginTransaction where
  toQuery :: BeginTransaction -> QueryString
toQuery = QueryString -> BeginTransaction -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | The response elements represent the output of a request to start a SQL
-- transaction.
--
-- /See:/ 'newBeginTransactionResponse' smart constructor.
data BeginTransactionResponse = BeginTransactionResponse'
  { -- | The transaction ID of the transaction started by the call.
    BeginTransactionResponse -> Maybe Text
transactionId :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    BeginTransactionResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (BeginTransactionResponse -> BeginTransactionResponse -> Bool
(BeginTransactionResponse -> BeginTransactionResponse -> Bool)
-> (BeginTransactionResponse -> BeginTransactionResponse -> Bool)
-> Eq BeginTransactionResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BeginTransactionResponse -> BeginTransactionResponse -> Bool
$c/= :: BeginTransactionResponse -> BeginTransactionResponse -> Bool
== :: BeginTransactionResponse -> BeginTransactionResponse -> Bool
$c== :: BeginTransactionResponse -> BeginTransactionResponse -> Bool
Prelude.Eq, ReadPrec [BeginTransactionResponse]
ReadPrec BeginTransactionResponse
Int -> ReadS BeginTransactionResponse
ReadS [BeginTransactionResponse]
(Int -> ReadS BeginTransactionResponse)
-> ReadS [BeginTransactionResponse]
-> ReadPrec BeginTransactionResponse
-> ReadPrec [BeginTransactionResponse]
-> Read BeginTransactionResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [BeginTransactionResponse]
$creadListPrec :: ReadPrec [BeginTransactionResponse]
readPrec :: ReadPrec BeginTransactionResponse
$creadPrec :: ReadPrec BeginTransactionResponse
readList :: ReadS [BeginTransactionResponse]
$creadList :: ReadS [BeginTransactionResponse]
readsPrec :: Int -> ReadS BeginTransactionResponse
$creadsPrec :: Int -> ReadS BeginTransactionResponse
Prelude.Read, Int -> BeginTransactionResponse -> ShowS
[BeginTransactionResponse] -> ShowS
BeginTransactionResponse -> String
(Int -> BeginTransactionResponse -> ShowS)
-> (BeginTransactionResponse -> String)
-> ([BeginTransactionResponse] -> ShowS)
-> Show BeginTransactionResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BeginTransactionResponse] -> ShowS
$cshowList :: [BeginTransactionResponse] -> ShowS
show :: BeginTransactionResponse -> String
$cshow :: BeginTransactionResponse -> String
showsPrec :: Int -> BeginTransactionResponse -> ShowS
$cshowsPrec :: Int -> BeginTransactionResponse -> ShowS
Prelude.Show, (forall x.
 BeginTransactionResponse -> Rep BeginTransactionResponse x)
-> (forall x.
    Rep BeginTransactionResponse x -> BeginTransactionResponse)
-> Generic BeginTransactionResponse
forall x.
Rep BeginTransactionResponse x -> BeginTransactionResponse
forall x.
BeginTransactionResponse -> Rep BeginTransactionResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep BeginTransactionResponse x -> BeginTransactionResponse
$cfrom :: forall x.
BeginTransactionResponse -> Rep BeginTransactionResponse x
Prelude.Generic)

-- |
-- Create a value of 'BeginTransactionResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'transactionId', 'beginTransactionResponse_transactionId' - The transaction ID of the transaction started by the call.
--
-- 'httpStatus', 'beginTransactionResponse_httpStatus' - The response's http status code.
newBeginTransactionResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  BeginTransactionResponse
newBeginTransactionResponse :: Int -> BeginTransactionResponse
newBeginTransactionResponse Int
pHttpStatus_ =
  BeginTransactionResponse' :: Maybe Text -> Int -> BeginTransactionResponse
BeginTransactionResponse'
    { $sel:transactionId:BeginTransactionResponse' :: Maybe Text
transactionId =
        Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:BeginTransactionResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The transaction ID of the transaction started by the call.
beginTransactionResponse_transactionId :: Lens.Lens' BeginTransactionResponse (Prelude.Maybe Prelude.Text)
beginTransactionResponse_transactionId :: (Maybe Text -> f (Maybe Text))
-> BeginTransactionResponse -> f BeginTransactionResponse
beginTransactionResponse_transactionId = (BeginTransactionResponse -> Maybe Text)
-> (BeginTransactionResponse
    -> Maybe Text -> BeginTransactionResponse)
-> Lens
     BeginTransactionResponse
     BeginTransactionResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransactionResponse' {Maybe Text
transactionId :: Maybe Text
$sel:transactionId:BeginTransactionResponse' :: BeginTransactionResponse -> Maybe Text
transactionId} -> Maybe Text
transactionId) (\s :: BeginTransactionResponse
s@BeginTransactionResponse' {} Maybe Text
a -> BeginTransactionResponse
s {$sel:transactionId:BeginTransactionResponse' :: Maybe Text
transactionId = Maybe Text
a} :: BeginTransactionResponse)

-- | The response's http status code.
beginTransactionResponse_httpStatus :: Lens.Lens' BeginTransactionResponse Prelude.Int
beginTransactionResponse_httpStatus :: (Int -> f Int)
-> BeginTransactionResponse -> f BeginTransactionResponse
beginTransactionResponse_httpStatus = (BeginTransactionResponse -> Int)
-> (BeginTransactionResponse -> Int -> BeginTransactionResponse)
-> Lens BeginTransactionResponse BeginTransactionResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\BeginTransactionResponse' {Int
httpStatus :: Int
$sel:httpStatus:BeginTransactionResponse' :: BeginTransactionResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: BeginTransactionResponse
s@BeginTransactionResponse' {} Int
a -> BeginTransactionResponse
s {$sel:httpStatus:BeginTransactionResponse' :: Int
httpStatus = Int
a} :: BeginTransactionResponse)

instance Prelude.NFData BeginTransactionResponse