package Ġdev . cap y bar al abs . d 4 j . store . postgres . repository Ċ Ċ import Ġdev . cap y bar al abs . d 4 j . store . common . repository . Emoji Repository Ċ import Ġdev . cap y bar al abs . d 4 j . store . common . to Long Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . Postgres Ser de Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . deserialize Many From Data Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . deserialize One From Data Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . execute Consum ing All Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . execute Consum ing Single Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . map To Count Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . with Connection Ċ import Ġdev . cap y bar al abs . d 4 j . store . postgres . with Connection Many Ċ import Ġdiscord 4 j . discord json . json . Emoji Data Ċ import Ġio . r 2 dbc . spi . ConnectionFactory Ċ import Ġreactor . core . publisher . Flux Ċ import Ġreactor . core . publisher . Mono Ċ Ċ /** Ċ Ġ* ĠCon cern ed Ġwith Ġoperations Ġon Ġthe Ġemoji Ġtable Ċ Ġ*/ Ċ internal Ġclass ĠPostgres Emoji Repository ( private Ġval Ġfactory : ĠConnection Factory , Ġprivate Ġval Ġserde : ĠPostgres Ser de ) Ġ: Ċ ĉ Emoji Repository Ġ{ ĊĊ ĉ init Ġ{ Ċĉ ĉ with Connection Many ( factory , Ġ" Postgres Emoji Repository . init ") Ġ{ Ċĉĉ ĉ it . createStatement ( Ċĉĉĉ ĉ """ Ċĉĉĉ ĉ CREATE ĠUN LOG GED ĠTABLE ĠIF ĠNOT ĠEXISTS Ġd 4 j _ discord _ emoji Ġ( ĊĉĉĉĉĠĠĠ Ġemoji _ id ĠBIGINT ĠNOT ĠNULL , Ċĉĉĉĉ ĉ guild _ id ĠBIGINT ĠNOT ĠNULL , Ċĉĉĉĉ ĉ data ĠBYTE A ĠNOT ĠNULL , Ċĉĉĉĉ ĉ shard _ index ĠINT ĠNOT ĠNULL , Ċĉĉĉĉ ĉ CONSTRAINT Ġd 4 j _ discord _ emoji _ pkey ĠPRIMARY ĠKEY Ġ( emoji _ id ) Ċĉĉĉ ĉ ) Ċĉĉĉ ĉ """. trim Indent () Ċĉĉ ĉ ). execute Consum ing All () Ċĉ ĉ }. block Last () Ċ ĉ } ĊĊ ĉ override Ġfun Ġsave ( guild Id : ĠLong , Ġemoji : ĠEmoji Data , Ġshard Id : ĠInt ): ĠMono < Void > Ġ{ Ċĉ ĉ return Ġsave All ( map Of ( Pair ( guild Id , ĠlistOf ( emoji ))), Ġshard Id ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġsave All ( emo jis By Guild : ĠMap < Long , ĠList < Emoji Data >>, Ġshard Id : ĠInt ): ĠMono < Void > Ġ{ Ċĉ ĉ val Ġfiltered Ġ= Ġemo jis By Guild . entries Ċĉĉ ĉ . map Ġ{ ĠPair ( it . key , Ġit . value . filter Ġ{ Ġemoji Data Ġ-> Ġemoji Data . id (). isPresent Ġ}) Ġ} Ċĉĉ ĉ . filter Ġ{ Ġit . second . isNotEmpty () Ġ} Ċĉ ĉ if Ġ( filtered . isEmpty ()) Ġ{ Ċĉĉ ĉ return ĠMono . empty () Ċĉ ĉ } ĊĊĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . save All ", Ġfiltered . sum Of Ġ{ Ġit . second . size Ġ}) Ġ{ Ċĉĉĉ ĉ val Ġstatement Ġ= Ġit . createStatement ( Ċĉĉĉĉ ĉ """ Ċĉĉĉĉ ĉ INSERT ĠINTO Ġd 4 j _ discord _ emoji ĠVALUES Ġ($ 1 , Ġ$ 2 , Ġ$ 3 , Ġ$ 4 ) Ċĉĉĉĉĉ ĉ ON ĠCON FLI CT Ġ( emoji _ id ) ĠDO ĠUPDATE ĠSET Ġdata Ġ= Ġ$ 3 , Ġshard _ index Ġ= Ġ$ 4 Ċĉĉĉĉ ĉ """. trim Indent () Ċĉĉĉ ĉ ) ĊĊĉĉĉ ĉ for Ġ( guild E moj is Ġin Ġfiltered ) Ġ{ Ċĉĉĉĉ ĉ val Ġguild Id Ġ= Ġguild E moj is . first Ċĉĉĉĉ ĉ for Ġ( emoji Ġin Ġguild E moj is . second ) Ġ{ Ċĉĉĉĉĉ ĉ statement Ċĉĉĉĉĉĉ ĉ . bind ("$ 1 ", Ġemoji . id (). orElse Throw (). as Long ()) Ċĉĉĉĉĉĉ ĉ . bind ("$ 2 ", Ġguild Id ) Ċĉĉĉĉĉĉ ĉ . bind ("$ 3 ", Ġserde . serialize ( emoji )) Ċĉĉĉĉĉĉ ĉ . bind ("$ 4 ", Ġshard Id ) Ċĉĉĉĉĉĉ ĉ . add () Ċĉĉĉĉ ĉ } Ċĉĉĉ ĉ } Ċĉĉĉ ĉ statement . execute Consum ing All (). then () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete ById s ( emoji Ids : ĠList < Long >, Ġguild Id : ĠLong ): ĠMono < Long > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . delete ById s ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" DELETE ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġemoji _ id Ġ= ĠANY ($ 1 ) ĠAND Ġguild _ id Ġ= Ġ$ 2 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġemoji Ids . to Typed Array ()) Ċĉĉĉĉ ĉ . bind ("$ 2 ", Ġguild Id ) Ċĉĉĉĉ ĉ . execute Consum ing Single (). to Long () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġdelete By Guild Id ( guild Id : ĠLong ): ĠMono < Long > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository l . delete By Guild Id ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" DELETE ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġguild _ id Ġ= Ġ$ 1 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġguild Id ) Ċĉĉĉĉ ĉ . execute Consum ing Single (). to Long () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊĊ ĉ override Ġfun Ġdelete By Shard Id ( shard Id : ĠInt ): ĠMono < Long > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . delete By Shard Id ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" DELETE ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġshard _ index Ġ= Ġ$ 1 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġshard Id ) Ċĉĉĉĉ ĉ . execute Consum ing Single (). to Long () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġcount E moj is (): ĠMono < Long > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . count E moj is ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" SELECT Ġcount (*) ĠAS Ġcount ĠFROM Ġd 4 j _ discord _ emoji ") Ċĉĉĉĉ ĉ . execute (). map To Count () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġcount E moj isIn Guild ( guild Id : ĠLong ): ĠMono < Long > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . count E moj isIn Guild ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" SELECT Ġcount (*) ĠAS Ġcount ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġguild _ id Ġ= Ġ$ 1 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġguild Id ) Ċĉĉĉĉ ĉ . execute (). map To Count () Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġget E moj is (): ĠFlux < Emoji Data > Ġ{ Ċĉ ĉ return ĠFlux . defer Ġ{ Ċĉĉ ĉ with Connection Many ( factory , Ġ" Postgres Emoji Repository . get E moj is ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" SELECT Ġdata ĠFROM Ġd 4 j _ discord _ emoji ") Ċĉĉĉĉ ĉ . execute (). deserialize Many From Data ( Emoji Data :: class . java , Ġserde ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġget E moj isIn Guild ( guild Id : ĠLong ): ĠFlux < Emoji Data > Ġ{ Ċĉ ĉ return ĠFlux . defer Ġ{ Ċĉĉ ĉ with Connection Many ( factory , Ġ" Postgres Emoji Repository . get E moj isIn Guild ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" SELECT Ġdata ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġguild _ id Ġ= Ġ$ 1 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġguild Id ) Ċĉĉĉĉ ĉ . execute (). deserialize Many From Data ( Emoji Data :: class . java , Ġserde ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġget Emoji ById ( guild Id : ĠLong , Ġemoji Id : ĠLong ): ĠMono < Emoji Data > Ġ{ Ċĉ ĉ return ĠMono . defer Ġ{ Ċĉĉ ĉ with Connection ( factory , Ġ" Postgres Emoji Repository . get Emoji ById ") Ġ{ Ċĉĉĉ ĉ it . createStatement (" SELECT Ġdata ĠFROM Ġd 4 j _ discord _ emoji ĠWHERE Ġguild _ id Ġ= Ġ$ 1 ĠAND Ġemoji _ id Ġ= Ġ$ 2 ") Ċĉĉĉĉ ĉ . bind ("$ 1 ", Ġguild Id ) Ċĉĉĉĉ ĉ . bind ("$ 2 ", Ġemoji Id ) Ċĉĉĉĉ ĉ . execute (). deserialize One From Data ( Emoji Data :: class . java , Ġserde ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } Ċ } Ċ