1515import jooq .steve .db .tables .records .ChargeBoxRecord ;
1616import lombok .extern .slf4j .Slf4j ;
1717import org .joda .time .DateTime ;
18- import org .jooq .Configuration ;
1918import org .jooq .DSLContext ;
2019import org .jooq .Field ;
2120import org .jooq .Record1 ;
2726import org .jooq .exception .DataAccessException ;
2827import org .jooq .impl .DSL ;
2928import org .springframework .beans .factory .annotation .Autowired ;
30- import org .springframework .beans .factory .annotation .Qualifier ;
3129import org .springframework .stereotype .Repository ;
3230
3331import java .util .List ;
4745@ Repository
4846public class ChargePointRepositoryImpl implements ChargePointRepository {
4947
50- @ Autowired
51- @ Qualifier ("jooqConfig" )
52- private Configuration config ;
53-
48+ @ Autowired private DSLContext ctx ;
5449 @ Autowired private AddressRepository addressRepository ;
5550
5651 @ Override
5752 public boolean isRegistered (String chargeBoxId ) {
58- Record1 <Integer > r = DSL .using (config )
59- .selectOne ()
53+ Record1 <Integer > r = ctx .selectOne ()
6054 .from (CHARGE_BOX )
6155 .where (CHARGE_BOX .CHARGE_BOX_ID .eq (chargeBoxId ))
6256 .fetchOne ();
@@ -68,8 +62,7 @@ public boolean isRegistered(String chargeBoxId) {
6862 public List <ChargePointSelect > getChargePointSelect (OcppProtocol protocol ) {
6963 final OcppTransport transport = protocol .getTransport ();
7064
71- return DSL .using (config )
72- .select (CHARGE_BOX .CHARGE_BOX_ID , CHARGE_BOX .ENDPOINT_ADDRESS )
65+ return ctx .select (CHARGE_BOX .CHARGE_BOX_ID , CHARGE_BOX .ENDPOINT_ADDRESS )
7366 .from (CHARGE_BOX )
7467 .where (CHARGE_BOX .OCPP_PROTOCOL .equal (protocol .getCompositeValue ()))
7568 .and (CHARGE_BOX .ENDPOINT_ADDRESS .isNotNull ())
@@ -79,16 +72,14 @@ public List<ChargePointSelect> getChargePointSelect(OcppProtocol protocol) {
7972
8073 @ Override
8174 public List <String > getChargeBoxIds () {
82- return DSL .using (config )
83- .select (CHARGE_BOX .CHARGE_BOX_ID )
75+ return ctx .select (CHARGE_BOX .CHARGE_BOX_ID )
8476 .from (CHARGE_BOX )
8577 .fetch (CHARGE_BOX .CHARGE_BOX_ID );
8678 }
8779
8880 @ Override
8981 public Map <String , Integer > getChargeBoxIdPkPair (List <String > chargeBoxIdList ) {
90- return DSL .using (config )
91- .select (CHARGE_BOX .CHARGE_BOX_ID , CHARGE_BOX .CHARGE_BOX_PK )
82+ return ctx .select (CHARGE_BOX .CHARGE_BOX_ID , CHARGE_BOX .CHARGE_BOX_PK )
9283 .from (CHARGE_BOX )
9384 .where (CHARGE_BOX .CHARGE_BOX_ID .in (chargeBoxIdList ))
9485 .fetchMap (CHARGE_BOX .CHARGE_BOX_ID , CHARGE_BOX .CHARGE_BOX_PK );
@@ -109,7 +100,7 @@ public List<ChargePoint.Overview> getOverview(ChargePointQueryForm form) {
109100
110101 @ SuppressWarnings ("unchecked" )
111102 private Result <Record5 <Integer , String , String , String , DateTime >> getOverviewInternal (ChargePointQueryForm form ) {
112- SelectQuery selectQuery = DSL . using ( config ) .selectQuery ();
103+ SelectQuery selectQuery = ctx .selectQuery ();
113104 selectQuery .addFrom (CHARGE_BOX );
114105 selectQuery .addSelect (
115106 CHARGE_BOX .CHARGE_BOX_PK ,
@@ -163,8 +154,6 @@ private Result<Record5<Integer, String, String, String, DateTime>> getOverviewIn
163154
164155 @ Override
165156 public ChargePoint .Details getDetails (int chargeBoxPk ) {
166- DSLContext ctx = DSL .using (config );
167-
168157 ChargeBoxRecord cbr = ctx .selectFrom (CHARGE_BOX )
169158 .where (CHARGE_BOX .CHARGE_BOX_PK .equal (chargeBoxPk ))
170159 .fetchOne ();
@@ -185,13 +174,12 @@ public List<ConnectorStatus> getChargePointConnectorStatus() {
185174 // Prepare for the inner select of the second join
186175 Field <Integer > t1Pk = CONNECTOR_STATUS .CONNECTOR_PK .as ("t1_pk" );
187176 Field <DateTime > t1Max = DSL .max (CONNECTOR_STATUS .STATUS_TIMESTAMP ).as ("t1_max" );
188- TableLike <?> t1 = DSL .select (t1Pk , t1Max )
177+ TableLike <?> t1 = ctx .select (t1Pk , t1Max )
189178 .from (CONNECTOR_STATUS )
190179 .groupBy (CONNECTOR_STATUS .CONNECTOR_PK )
191180 .asTable ("t1" );
192181
193- return DSL .using (config )
194- .select (CHARGE_BOX .CHARGE_BOX_PK ,
182+ return ctx .select (CHARGE_BOX .CHARGE_BOX_PK ,
195183 CONNECTOR .CHARGE_BOX_ID ,
196184 CONNECTOR .CONNECTOR_ID ,
197185 CONNECTOR_STATUS .STATUS_TIMESTAMP ,
@@ -220,16 +208,15 @@ public List<ConnectorStatus> getChargePointConnectorStatus() {
220208
221209 @ Override
222210 public List <Integer > getConnectorIds (String chargeBoxId ) {
223- return DSL .using (config )
224- .select (CONNECTOR .CONNECTOR_ID )
211+ return ctx .select (CONNECTOR .CONNECTOR_ID )
225212 .from (CONNECTOR )
226213 .where (CONNECTOR .CHARGE_BOX_ID .equal (chargeBoxId ))
227214 .fetch (CONNECTOR .CONNECTOR_ID );
228215 }
229216
230217 @ Override
231218 public void addChargePoint (ChargePointForm form ) {
232- DSL . using ( config ) .transaction (configuration -> {
219+ ctx .transaction (configuration -> {
233220 DSLContext ctx = DSL .using (configuration );
234221 try {
235222 Integer addressId = addressRepository .updateOrInsert (ctx , form .getAddress ());
@@ -244,7 +231,7 @@ public void addChargePoint(ChargePointForm form) {
244231
245232 @ Override
246233 public void updateChargePoint (ChargePointForm form ) {
247- DSL . using ( config ) .transaction (configuration -> {
234+ ctx .transaction (configuration -> {
248235 DSLContext ctx = DSL .using (configuration );
249236 try {
250237 Integer addressId = addressRepository .updateOrInsert (ctx , form .getAddress ());
@@ -259,7 +246,7 @@ public void updateChargePoint(ChargePointForm form) {
259246
260247 @ Override
261248 public void deleteChargePoint (int chargeBoxPk ) {
262- DSL . using ( config ) .transaction (configuration -> {
249+ ctx .transaction (configuration -> {
263250 DSLContext ctx = DSL .using (configuration );
264251 try {
265252 addressRepository .delete (ctx , selectAddressId (chargeBoxPk ));
@@ -276,7 +263,7 @@ public void deleteChargePoint(int chargeBoxPk) {
276263 // -------------------------------------------------------------------------
277264
278265 private SelectConditionStep <Record1 <Integer >> selectAddressId (int chargeBoxPk ) {
279- return DSL .select (CHARGE_BOX .ADDRESS_PK )
266+ return ctx .select (CHARGE_BOX .ADDRESS_PK )
280267 .from (CHARGE_BOX )
281268 .where (CHARGE_BOX .CHARGE_BOX_PK .eq (chargeBoxPk ));
282269 }
0 commit comments