001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * CarrierServiceOptionFactory.java 021 */ 022 023package com.echothree.model.data.carrier.server.factory; 024 025import com.echothree.model.data.carrier.common.pk.CarrierServicePK; 026import com.echothree.model.data.carrier.common.pk.CarrierOptionPK; 027import com.echothree.model.data.selector.common.pk.SelectorPK; 028 029import com.echothree.model.data.carrier.server.entity.CarrierService; 030import com.echothree.model.data.carrier.server.entity.CarrierOption; 031import com.echothree.model.data.selector.server.entity.Selector; 032 033import com.echothree.model.data.carrier.common.CarrierServiceOptionConstants; 034import com.echothree.model.data.carrier.common.pk.CarrierServiceOptionPK; 035import com.echothree.model.data.carrier.server.value.CarrierServiceOptionValue; 036import com.echothree.model.data.carrier.server.entity.CarrierServiceOption; 037import com.echothree.util.common.exception.PersistenceDatabaseException; 038import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 039import com.echothree.util.common.exception.PersistenceNotNullException; 040import com.echothree.util.server.persistence.BaseFactory; 041import com.echothree.util.server.persistence.EntityIdGenerator; 042import com.echothree.util.server.persistence.EntityPermission; 043import com.echothree.util.server.persistence.PersistenceDebugFlags; 044import com.echothree.util.server.persistence.Session; 045import java.sql.PreparedStatement; 046import java.sql.ResultSet; 047import java.sql.SQLException; 048import java.sql.Types; 049import java.io.ByteArrayInputStream; 050import java.io.StringReader; 051import java.util.ArrayList; 052import java.util.Collection; 053import java.util.HashSet; 054import java.util.List; 055import java.util.Map; 056import java.util.Set; 057import javax.enterprise.context.ApplicationScoped; 058import javax.enterprise.inject.spi.CDI; 059import javax.inject.Inject; 060import org.jooq.ResultQuery; 061import org.slf4j.Logger; 062import org.slf4j.LoggerFactory; 063 064@ApplicationScoped 065public class CarrierServiceOptionFactory 066 implements BaseFactory<CarrierServiceOptionPK, CarrierServiceOption> { 067 068 @Inject 069 Session session; 070 071 //private static final Logger log = LoggerFactory.getLogger(CarrierServiceOptionFactory.class); 072 073 final private static String SQL_SELECT_READ_ONLY = "SELECT crrsrvopt_carrierserviceoptionid, crrsrvopt_crrsrv_carrierserviceid, crrsrvopt_crropt_carrieroptionid, crrsrvopt_isrecommended, crrsrvopt_isrequired, crrsrvopt_recommendedgeocodeselectorid, crrsrvopt_requiredgeocodeselectorid, crrsrvopt_recommendeditemselectorid, crrsrvopt_requireditemselectorid, crrsrvopt_recommendedorderselectorid, crrsrvopt_requiredorderselectorid, crrsrvopt_recommendedshipmentselectorid, crrsrvopt_requiredshipmentselectorid, crrsrvopt_fromtime, crrsrvopt_thrutime FROM carrierserviceoptions WHERE crrsrvopt_carrierserviceoptionid = ?"; 074 final private static String SQL_SELECT_READ_WRITE = "SELECT crrsrvopt_carrierserviceoptionid, crrsrvopt_crrsrv_carrierserviceid, crrsrvopt_crropt_carrieroptionid, crrsrvopt_isrecommended, crrsrvopt_isrequired, crrsrvopt_recommendedgeocodeselectorid, crrsrvopt_requiredgeocodeselectorid, crrsrvopt_recommendeditemselectorid, crrsrvopt_requireditemselectorid, crrsrvopt_recommendedorderselectorid, crrsrvopt_requiredorderselectorid, crrsrvopt_recommendedshipmentselectorid, crrsrvopt_requiredshipmentselectorid, crrsrvopt_fromtime, crrsrvopt_thrutime FROM carrierserviceoptions WHERE crrsrvopt_carrierserviceoptionid = ? FOR UPDATE"; 075 final private static String SQL_INSERT = "INSERT INTO carrierserviceoptions (crrsrvopt_carrierserviceoptionid, crrsrvopt_crrsrv_carrierserviceid, crrsrvopt_crropt_carrieroptionid, crrsrvopt_isrecommended, crrsrvopt_isrequired, crrsrvopt_recommendedgeocodeselectorid, crrsrvopt_requiredgeocodeselectorid, crrsrvopt_recommendeditemselectorid, crrsrvopt_requireditemselectorid, crrsrvopt_recommendedorderselectorid, crrsrvopt_requiredorderselectorid, crrsrvopt_recommendedshipmentselectorid, crrsrvopt_requiredshipmentselectorid, crrsrvopt_fromtime, crrsrvopt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; 076 final private static String SQL_UPDATE = "UPDATE carrierserviceoptions SET crrsrvopt_crrsrv_carrierserviceid = ?, crrsrvopt_crropt_carrieroptionid = ?, crrsrvopt_isrecommended = ?, crrsrvopt_isrequired = ?, crrsrvopt_recommendedgeocodeselectorid = ?, crrsrvopt_requiredgeocodeselectorid = ?, crrsrvopt_recommendeditemselectorid = ?, crrsrvopt_requireditemselectorid = ?, crrsrvopt_recommendedorderselectorid = ?, crrsrvopt_requiredorderselectorid = ?, crrsrvopt_recommendedshipmentselectorid = ?, crrsrvopt_requiredshipmentselectorid = ?, crrsrvopt_fromtime = ?, crrsrvopt_thrutime = ? WHERE crrsrvopt_carrierserviceoptionid = ?"; 077 final private static String SQL_DELETE = "DELETE FROM carrierserviceoptions WHERE crrsrvopt_carrierserviceoptionid = ?"; 078 final private static String SQL_VALID = "SELECT COUNT(*) FROM carrierserviceoptions WHERE crrsrvopt_carrierserviceoptionid = ?"; 079 080 final public static String CRRSRVOPT_CARRIERSERVICEOPTIONID = "crrsrvopt_carrierserviceoptionid"; 081 final public static String CRRSRVOPT_CRRSRV_CARRIERSERVICEID = "crrsrvopt_crrsrv_carrierserviceid"; 082 final public static String CRRSRVOPT_CRROPT_CARRIEROPTIONID = "crrsrvopt_crropt_carrieroptionid"; 083 final public static String CRRSRVOPT_ISRECOMMENDED = "crrsrvopt_isrecommended"; 084 final public static String CRRSRVOPT_ISREQUIRED = "crrsrvopt_isrequired"; 085 final public static String CRRSRVOPT_RECOMMENDEDGEOCODESELECTORID = "crrsrvopt_recommendedgeocodeselectorid"; 086 final public static String CRRSRVOPT_REQUIREDGEOCODESELECTORID = "crrsrvopt_requiredgeocodeselectorid"; 087 final public static String CRRSRVOPT_RECOMMENDEDITEMSELECTORID = "crrsrvopt_recommendeditemselectorid"; 088 final public static String CRRSRVOPT_REQUIREDITEMSELECTORID = "crrsrvopt_requireditemselectorid"; 089 final public static String CRRSRVOPT_RECOMMENDEDORDERSELECTORID = "crrsrvopt_recommendedorderselectorid"; 090 final public static String CRRSRVOPT_REQUIREDORDERSELECTORID = "crrsrvopt_requiredorderselectorid"; 091 final public static String CRRSRVOPT_RECOMMENDEDSHIPMENTSELECTORID = "crrsrvopt_recommendedshipmentselectorid"; 092 final public static String CRRSRVOPT_REQUIREDSHIPMENTSELECTORID = "crrsrvopt_requiredshipmentselectorid"; 093 final public static String CRRSRVOPT_FROMTIME = "crrsrvopt_fromtime"; 094 final public static String CRRSRVOPT_THRUTIME = "crrsrvopt_thrutime"; 095 096 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(CarrierServiceOptionConstants.COMPONENT_VENDOR_NAME, CarrierServiceOptionConstants.ENTITY_TYPE_NAME); 097 098 /** Creates a new instance of CarrierServiceOptionFactory */ 099 protected CarrierServiceOptionFactory() { 100 super(); 101 } 102 103 public static CarrierServiceOptionFactory getInstance() { 104 return CDI.current().select(CarrierServiceOptionFactory.class).get(); 105 } 106 107 @Override 108 public String getComponentVendorName() { 109 return CarrierServiceOptionConstants.COMPONENT_VENDOR_NAME; 110 } 111 112 @Override 113 public String getEntityTypeName() { 114 return CarrierServiceOptionConstants.ENTITY_TYPE_NAME; 115 } 116 117 public PreparedStatement prepareStatement(String query) { 118 return session.prepareStatement(query); 119 } 120 121 public CarrierServiceOptionPK getNextPK() { 122 return new CarrierServiceOptionPK(entityIdGenerator.getNextEntityId()); 123 } 124 125 public Set<CarrierServiceOptionPK> getPKsFromResultSetAsSet(ResultSet rs) 126 throws PersistenceDatabaseException { 127 Set<CarrierServiceOptionPK> _result = new HashSet<>(); 128 129 try { 130 while(rs.next()) { 131 _result.add(getPKFromResultSet(rs)); 132 } 133 } catch (SQLException se) { 134 throw new PersistenceDatabaseException(se); 135 } 136 137 return _result; 138 } 139 140 public java.util.List<CarrierServiceOptionPK> getPKsFromResultSetAsList(ResultSet rs) 141 throws PersistenceDatabaseException { 142 java.util.List<CarrierServiceOptionPK> _result = new ArrayList<>(); 143 144 try { 145 while(rs.next()) { 146 _result.add(getPKFromResultSet(rs)); 147 } 148 } catch (SQLException se) { 149 throw new PersistenceDatabaseException(se); 150 } 151 152 return _result; 153 } 154 155 public CarrierServiceOptionPK getPKFromResultSet(ResultSet rs) 156 throws PersistenceDatabaseException { 157 CarrierServiceOptionPK _result; 158 159 try { 160 long crrsrvopt_carrierserviceoptionid = rs.getLong(CRRSRVOPT_CARRIERSERVICEOPTIONID); 161 Long _entityId = rs.wasNull() ? null : crrsrvopt_carrierserviceoptionid; 162 163 _result = new CarrierServiceOptionPK(_entityId); 164 } catch (SQLException se) { 165 throw new PersistenceDatabaseException(se); 166 } 167 168 return _result; 169 } 170 171 public java.util.List<CarrierServiceOptionValue> getValuesFromPKs(Collection<CarrierServiceOptionPK> pks) 172 throws PersistenceDatabaseException { 173 java.util.List<CarrierServiceOptionValue> _values = new ArrayList<>(pks.size()); 174 175 for(CarrierServiceOptionPK _pk: pks) { 176 _values.add(getValueFromPK(_pk)); 177 } 178 179 return _values; 180 } 181 182 public CarrierServiceOptionValue getValueFromPK(CarrierServiceOptionPK pk) 183 throws PersistenceDatabaseException { 184 CarrierServiceOptionValue _value; 185 186 // See if we already have the entity in the session cache 187 CarrierServiceOption _entity = (CarrierServiceOption)session.getEntity(pk); 188 if(_entity == null) 189 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getCarrierServiceOptionValue(); 190 else 191 _value = _entity.getCarrierServiceOptionValue(); 192 193 return _value; 194 } 195 196 public java.util.List<CarrierServiceOptionValue> getValuesFromResultSet(ResultSet rs) 197 throws PersistenceDatabaseException { 198 java.util.List<CarrierServiceOptionValue> _result = new ArrayList<>(); 199 200 try { 201 while(rs.next()) { 202 _result.add(getValueFromResultSet(rs)); 203 } 204 } catch (SQLException se) { 205 throw new PersistenceDatabaseException(se); 206 } 207 208 return _result; 209 } 210 211 public CarrierServiceOptionValue getValueFromResultSet(ResultSet rs) 212 throws PersistenceDatabaseException { 213 CarrierServiceOptionValue _value; 214 215 try { 216 Long crrsrvopt_carrierserviceoptionid = rs.getLong(CRRSRVOPT_CARRIERSERVICEOPTIONID); 217 CarrierServiceOptionPK _pk = new CarrierServiceOptionPK(crrsrvopt_carrierserviceoptionid); 218 219 // See if we already have the entity in the session cache 220 CarrierServiceOption _entity = (CarrierServiceOption)session.getEntity(_pk); 221 222 if(_entity == null) { 223 Long crrsrvopt_crrsrv_carrierserviceid = rs.getLong(CRRSRVOPT_CRRSRV_CARRIERSERVICEID); 224 if(rs.wasNull()) 225 crrsrvopt_crrsrv_carrierserviceid = null; 226 227 Long crrsrvopt_crropt_carrieroptionid = rs.getLong(CRRSRVOPT_CRROPT_CARRIEROPTIONID); 228 if(rs.wasNull()) 229 crrsrvopt_crropt_carrieroptionid = null; 230 231 Boolean crrsrvopt_isrecommended = rs.getInt(CRRSRVOPT_ISRECOMMENDED) == 1; 232 if(rs.wasNull()) 233 crrsrvopt_isrecommended = null; 234 235 Boolean crrsrvopt_isrequired = rs.getInt(CRRSRVOPT_ISREQUIRED) == 1; 236 if(rs.wasNull()) 237 crrsrvopt_isrequired = null; 238 239 Long crrsrvopt_recommendedgeocodeselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDGEOCODESELECTORID); 240 if(rs.wasNull()) 241 crrsrvopt_recommendedgeocodeselectorid = null; 242 243 Long crrsrvopt_requiredgeocodeselectorid = rs.getLong(CRRSRVOPT_REQUIREDGEOCODESELECTORID); 244 if(rs.wasNull()) 245 crrsrvopt_requiredgeocodeselectorid = null; 246 247 Long crrsrvopt_recommendeditemselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDITEMSELECTORID); 248 if(rs.wasNull()) 249 crrsrvopt_recommendeditemselectorid = null; 250 251 Long crrsrvopt_requireditemselectorid = rs.getLong(CRRSRVOPT_REQUIREDITEMSELECTORID); 252 if(rs.wasNull()) 253 crrsrvopt_requireditemselectorid = null; 254 255 Long crrsrvopt_recommendedorderselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDORDERSELECTORID); 256 if(rs.wasNull()) 257 crrsrvopt_recommendedorderselectorid = null; 258 259 Long crrsrvopt_requiredorderselectorid = rs.getLong(CRRSRVOPT_REQUIREDORDERSELECTORID); 260 if(rs.wasNull()) 261 crrsrvopt_requiredorderselectorid = null; 262 263 Long crrsrvopt_recommendedshipmentselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDSHIPMENTSELECTORID); 264 if(rs.wasNull()) 265 crrsrvopt_recommendedshipmentselectorid = null; 266 267 Long crrsrvopt_requiredshipmentselectorid = rs.getLong(CRRSRVOPT_REQUIREDSHIPMENTSELECTORID); 268 if(rs.wasNull()) 269 crrsrvopt_requiredshipmentselectorid = null; 270 271 Long crrsrvopt_fromtime = rs.getLong(CRRSRVOPT_FROMTIME); 272 if(rs.wasNull()) 273 crrsrvopt_fromtime = null; 274 275 Long crrsrvopt_thrutime = rs.getLong(CRRSRVOPT_THRUTIME); 276 if(rs.wasNull()) 277 crrsrvopt_thrutime = null; 278 279 _value = new CarrierServiceOptionValue(_pk, new CarrierServicePK(crrsrvopt_crrsrv_carrierserviceid), new CarrierOptionPK(crrsrvopt_crropt_carrieroptionid), crrsrvopt_isrecommended, crrsrvopt_isrequired, new SelectorPK(crrsrvopt_recommendedgeocodeselectorid), new SelectorPK(crrsrvopt_requiredgeocodeselectorid), new SelectorPK(crrsrvopt_recommendeditemselectorid), new SelectorPK(crrsrvopt_requireditemselectorid), new SelectorPK(crrsrvopt_recommendedorderselectorid), new SelectorPK(crrsrvopt_requiredorderselectorid), new SelectorPK(crrsrvopt_recommendedshipmentselectorid), new SelectorPK(crrsrvopt_requiredshipmentselectorid), crrsrvopt_fromtime, crrsrvopt_thrutime); 280 } else 281 _value = _entity.getCarrierServiceOptionValue(); 282 } catch (SQLException se) { 283 throw new PersistenceDatabaseException(se); 284 } 285 286 return _value; 287 } 288 289 public java.util.List<CarrierServiceOption> getEntitiesFromPKs(EntityPermission entityPermission, Collection<CarrierServiceOptionPK> pks) 290 throws PersistenceDatabaseException { 291 java.util.List<CarrierServiceOption> _entities = new ArrayList<>(pks.size()); 292 293 for(CarrierServiceOptionPK _pk: pks) { 294 _entities.add(getEntityFromPK(entityPermission, _pk)); 295 } 296 297 return _entities; 298 } 299 300 public CarrierServiceOption getEntityFromValue(EntityPermission entityPermission, CarrierServiceOptionValue value) { 301 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 302 } 303 304 public CarrierServiceOption getEntityFromCache(CarrierServiceOptionPK pk) { 305 CarrierServiceOptionValue _value = (CarrierServiceOptionValue)session.getValueCache().get(pk); 306 307 return _value == null ? null : new CarrierServiceOption(_value, EntityPermission.READ_ONLY); 308 } 309 310 public CarrierServiceOption getEntityFromPK(EntityPermission entityPermission, CarrierServiceOptionPK pk) 311 throws PersistenceDatabaseException { 312 CarrierServiceOption _entity; 313 314 // See if we already have the entity in the session cache 315 _entity = (CarrierServiceOption)session.getEntity(pk); 316 if(_entity != null) { 317 // If the requested permission is READ_WRITE, and the cached permission is 318 // READ_ONLY, then pretend that the cached object wasn't found, and create 319 // a new entity that is READ_WRITE. 320 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 321 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 322 _entity = null; 323 } 324 } 325 326 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 327 _entity = getEntityFromCache(pk); 328 } 329 330 if(_entity == null) { 331 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 332 long _entityId = pk.getEntityId(); 333 ResultSet _rs = null; 334 335 try { 336 _ps.setLong(1, _entityId); 337 _rs = _ps.executeQuery(); 338 if(_rs.next()) { 339 _entity = getEntityFromResultSet(entityPermission, _rs); 340 } 341 } catch (SQLException se) { 342 throw new PersistenceDatabaseException(se); 343 } finally { 344 if(_rs != null) { 345 try { 346 _rs.close(); 347 } catch (SQLException se) { 348 // do nothing 349 } 350 } 351 } 352 } 353 354 return _entity; 355 } 356 357 public Set<CarrierServiceOptionPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 358 throws PersistenceDatabaseException { 359 Set<CarrierServiceOptionPK> _pks; 360 ResultSet _rs = null; 361 362 try { 363 if(params.length != 0) { 364 Session.setQueryParams(ps, params); 365 } 366 367 _rs = ps.executeQuery(); 368 _pks = getPKsFromResultSetAsSet(_rs); 369 _rs.close(); 370 } catch (SQLException se) { 371 throw new PersistenceDatabaseException(se); 372 } finally { 373 if(_rs != null) { 374 try { 375 _rs.close(); 376 } catch (SQLException se) { 377 // do nothing 378 } 379 } 380 } 381 382 return _pks; 383 } 384 385 public java.util.List<CarrierServiceOptionPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 386 throws PersistenceDatabaseException { 387 java.util.List<CarrierServiceOptionPK> _pks; 388 ResultSet _rs = null; 389 390 try { 391 if(params.length != 0) { 392 Session.setQueryParams(ps, params); 393 } 394 395 _rs = ps.executeQuery(); 396 _pks = getPKsFromResultSetAsList(_rs); 397 _rs.close(); 398 } catch (SQLException se) { 399 throw new PersistenceDatabaseException(se); 400 } finally { 401 if(_rs != null) { 402 try { 403 _rs.close(); 404 } catch (SQLException se) { 405 // do nothing 406 } 407 } 408 } 409 410 return _pks; 411 } 412 413 public CarrierServiceOptionPK getPKFromQuery(PreparedStatement ps, final Object... params) 414 throws PersistenceDatabaseException { 415 CarrierServiceOptionPK _pk = null; 416 ResultSet _rs = null; 417 418 try { 419 if(params.length != 0) { 420 Session.setQueryParams(ps, params); 421 } 422 423 _rs = ps.executeQuery(); 424 if(_rs.next()) { 425 _pk = getPKFromResultSet(_rs); 426 } 427 _rs.close(); 428 } catch (SQLException se) { 429 throw new PersistenceDatabaseException(se); 430 } finally { 431 if(_rs != null) { 432 try { 433 _rs.close(); 434 } catch (SQLException se) { 435 // do nothing 436 } 437 } 438 } 439 440 return _pk; 441 } 442 443 public java.util.List<CarrierServiceOption> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 444 throws PersistenceDatabaseException { 445 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 446 447 return getEntitiesFromQuery(entityPermission, ps, params); 448 } 449 450 public java.util.List<CarrierServiceOption> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 451 throws PersistenceDatabaseException { 452 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 453 454 return getEntitiesFromQuery(entityPermission, ps); 455 } 456 457 public java.util.List<CarrierServiceOption> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 458 throws PersistenceDatabaseException { 459 PreparedStatement ps = session.prepareStatement(query.getSQL()); 460 461 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 462 } 463 464 public java.util.List<CarrierServiceOption> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 465 throws PersistenceDatabaseException { 466 java.util.List<CarrierServiceOption> _entities; 467 ResultSet _rs = null; 468 469 try { 470 if(params.length != 0) { 471 Session.setQueryParams(ps, params); 472 } 473 474 _rs = ps.executeQuery(); 475 _entities = getEntitiesFromResultSet(entityPermission, _rs); 476 _rs.close(); 477 } catch (SQLException se) { 478 throw new PersistenceDatabaseException(se); 479 } finally { 480 if(_rs != null) { 481 try { 482 _rs.close(); 483 } catch (SQLException se) { 484 // do nothing 485 } 486 } 487 } 488 489 return _entities; 490 } 491 492 public CarrierServiceOption getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 493 throws PersistenceDatabaseException { 494 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 495 496 return getEntityFromQuery(entityPermission, ps, params); 497 } 498 499 public CarrierServiceOption getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 500 throws PersistenceDatabaseException { 501 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 502 503 return getEntityFromQuery(entityPermission, ps); 504 } 505 506 public CarrierServiceOption getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 507 throws PersistenceDatabaseException { 508 PreparedStatement ps = session.prepareStatement(query.getSQL()); 509 510 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 511 } 512 513 public CarrierServiceOption getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 514 throws PersistenceDatabaseException { 515 CarrierServiceOption _entity = null; 516 ResultSet _rs = null; 517 518 try { 519 if(params.length != 0) { 520 Session.setQueryParams(ps, params); 521 } 522 523 _rs = ps.executeQuery(); 524 if(_rs.next()) { 525 _entity = getEntityFromResultSet(entityPermission, _rs); 526 } 527 _rs.close(); 528 } catch (SQLException se) { 529 throw new PersistenceDatabaseException(se); 530 } finally { 531 if(_rs != null) { 532 try { 533 _rs.close(); 534 } catch (SQLException se) { 535 // do nothing 536 } 537 } 538 } 539 540 return _entity; 541 } 542 543 public java.util.List<CarrierServiceOption> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 544 throws PersistenceDatabaseException { 545 java.util.List<CarrierServiceOption> _result = new ArrayList<>(); 546 547 try { 548 while(rs.next()) { 549 _result.add(getEntityFromResultSet(entityPermission, rs)); 550 } 551 } catch (SQLException se) { 552 throw new PersistenceDatabaseException(se); 553 } 554 555 return _result; 556 } 557 558 public CarrierServiceOption getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 559 throws PersistenceDatabaseException { 560 CarrierServiceOption _entity; 561 562 try { 563 Long crrsrvopt_carrierserviceoptionid = rs.getLong(CRRSRVOPT_CARRIERSERVICEOPTIONID); 564 CarrierServiceOptionPK _pk = new CarrierServiceOptionPK(crrsrvopt_carrierserviceoptionid); 565 566 // See if we already have the entity in the session cache 567 _entity = (CarrierServiceOption)session.getEntity(_pk); 568 if(_entity != null) { 569 // If the requested permission is READ_WRITE, and the cached permission is 570 // READ_ONLY, then pretend that the cached object wasn't found, and create 571 // a new entity that is READ_WRITE. 572 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 573 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 574 _entity = null; 575 } 576 } 577 boolean foundInSessionCache = _entity != null; 578 579 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 580 _entity = getEntityFromCache(_pk); 581 } 582 583 if(_entity == null) { 584 Long crrsrvopt_crrsrv_carrierserviceid = rs.getLong(CRRSRVOPT_CRRSRV_CARRIERSERVICEID); 585 if(rs.wasNull()) 586 crrsrvopt_crrsrv_carrierserviceid = null; 587 588 Long crrsrvopt_crropt_carrieroptionid = rs.getLong(CRRSRVOPT_CRROPT_CARRIEROPTIONID); 589 if(rs.wasNull()) 590 crrsrvopt_crropt_carrieroptionid = null; 591 592 Boolean crrsrvopt_isrecommended = rs.getInt(CRRSRVOPT_ISRECOMMENDED) == 1; 593 if(rs.wasNull()) 594 crrsrvopt_isrecommended = null; 595 596 Boolean crrsrvopt_isrequired = rs.getInt(CRRSRVOPT_ISREQUIRED) == 1; 597 if(rs.wasNull()) 598 crrsrvopt_isrequired = null; 599 600 Long crrsrvopt_recommendedgeocodeselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDGEOCODESELECTORID); 601 if(rs.wasNull()) 602 crrsrvopt_recommendedgeocodeselectorid = null; 603 604 Long crrsrvopt_requiredgeocodeselectorid = rs.getLong(CRRSRVOPT_REQUIREDGEOCODESELECTORID); 605 if(rs.wasNull()) 606 crrsrvopt_requiredgeocodeselectorid = null; 607 608 Long crrsrvopt_recommendeditemselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDITEMSELECTORID); 609 if(rs.wasNull()) 610 crrsrvopt_recommendeditemselectorid = null; 611 612 Long crrsrvopt_requireditemselectorid = rs.getLong(CRRSRVOPT_REQUIREDITEMSELECTORID); 613 if(rs.wasNull()) 614 crrsrvopt_requireditemselectorid = null; 615 616 Long crrsrvopt_recommendedorderselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDORDERSELECTORID); 617 if(rs.wasNull()) 618 crrsrvopt_recommendedorderselectorid = null; 619 620 Long crrsrvopt_requiredorderselectorid = rs.getLong(CRRSRVOPT_REQUIREDORDERSELECTORID); 621 if(rs.wasNull()) 622 crrsrvopt_requiredorderselectorid = null; 623 624 Long crrsrvopt_recommendedshipmentselectorid = rs.getLong(CRRSRVOPT_RECOMMENDEDSHIPMENTSELECTORID); 625 if(rs.wasNull()) 626 crrsrvopt_recommendedshipmentselectorid = null; 627 628 Long crrsrvopt_requiredshipmentselectorid = rs.getLong(CRRSRVOPT_REQUIREDSHIPMENTSELECTORID); 629 if(rs.wasNull()) 630 crrsrvopt_requiredshipmentselectorid = null; 631 632 Long crrsrvopt_fromtime = rs.getLong(CRRSRVOPT_FROMTIME); 633 if(rs.wasNull()) 634 crrsrvopt_fromtime = null; 635 636 Long crrsrvopt_thrutime = rs.getLong(CRRSRVOPT_THRUTIME); 637 if(rs.wasNull()) 638 crrsrvopt_thrutime = null; 639 640 CarrierServiceOptionValue _value = new CarrierServiceOptionValue(_pk, crrsrvopt_crrsrv_carrierserviceid == null? null: new CarrierServicePK(crrsrvopt_crrsrv_carrierserviceid), crrsrvopt_crropt_carrieroptionid == null? null: new CarrierOptionPK(crrsrvopt_crropt_carrieroptionid), crrsrvopt_isrecommended, crrsrvopt_isrequired, crrsrvopt_recommendedgeocodeselectorid == null? null: new SelectorPK(crrsrvopt_recommendedgeocodeselectorid), crrsrvopt_requiredgeocodeselectorid == null? null: new SelectorPK(crrsrvopt_requiredgeocodeselectorid), crrsrvopt_recommendeditemselectorid == null? null: new SelectorPK(crrsrvopt_recommendeditemselectorid), crrsrvopt_requireditemselectorid == null? null: new SelectorPK(crrsrvopt_requireditemselectorid), crrsrvopt_recommendedorderselectorid == null? null: new SelectorPK(crrsrvopt_recommendedorderselectorid), crrsrvopt_requiredorderselectorid == null? null: new SelectorPK(crrsrvopt_requiredorderselectorid), crrsrvopt_recommendedshipmentselectorid == null? null: new SelectorPK(crrsrvopt_recommendedshipmentselectorid), crrsrvopt_requiredshipmentselectorid == null? null: new SelectorPK(crrsrvopt_requiredshipmentselectorid), crrsrvopt_fromtime, crrsrvopt_thrutime); 641 _entity = new CarrierServiceOption(_value, entityPermission); 642 } 643 644 if(!foundInSessionCache) { 645 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 646 session.putReadOnlyEntity(_pk, _entity); 647 session.getValueCache().put(_entity.getCarrierServiceOptionValue()); 648 } else { 649 session.putReadWriteEntity(_pk, _entity); 650 } 651 } 652 } catch (SQLException se) { 653 throw new PersistenceDatabaseException(se); 654 } 655 656 return _entity; 657 } 658 659 public CarrierServiceOption create(CarrierService carrierService, CarrierOption carrierOption, Boolean isRecommended, Boolean isRequired, Selector recommendedGeoCodeSelector, Selector requiredGeoCodeSelector, Selector recommendedItemSelector, Selector requiredItemSelector, Selector recommendedOrderSelector, Selector requiredOrderSelector, Selector recommendedShipmentSelector, Selector requiredShipmentSelector, Long fromTime, Long thruTime) 660 throws PersistenceDatabaseException, PersistenceNotNullException { 661 return create(carrierService == null ? null : carrierService.getPrimaryKey(), carrierOption == null ? null : carrierOption.getPrimaryKey(), isRecommended, isRequired, recommendedGeoCodeSelector == null ? null : recommendedGeoCodeSelector.getPrimaryKey(), requiredGeoCodeSelector == null ? null : requiredGeoCodeSelector.getPrimaryKey(), recommendedItemSelector == null ? null : recommendedItemSelector.getPrimaryKey(), requiredItemSelector == null ? null : requiredItemSelector.getPrimaryKey(), recommendedOrderSelector == null ? null : recommendedOrderSelector.getPrimaryKey(), requiredOrderSelector == null ? null : requiredOrderSelector.getPrimaryKey(), recommendedShipmentSelector == null ? null : recommendedShipmentSelector.getPrimaryKey(), requiredShipmentSelector == null ? null : requiredShipmentSelector.getPrimaryKey(), fromTime, thruTime); 662 } 663 664 private void bindForCreate(PreparedStatement _ps, CarrierServiceOptionValue _value) 665 throws SQLException { 666 _ps.setLong(1, _value.getEntityId()); 667 668 CarrierServicePK crrsrvopt_crrsrv_carrierserviceid = _value.getCarrierServicePK(); 669 if(crrsrvopt_crrsrv_carrierserviceid == null) 670 _ps.setNull(2, Types.BIGINT); 671 else 672 _ps.setLong(2, crrsrvopt_crrsrv_carrierserviceid.getEntityId()); 673 674 CarrierOptionPK crrsrvopt_crropt_carrieroptionid = _value.getCarrierOptionPK(); 675 if(crrsrvopt_crropt_carrieroptionid == null) 676 _ps.setNull(3, Types.BIGINT); 677 else 678 _ps.setLong(3, crrsrvopt_crropt_carrieroptionid.getEntityId()); 679 680 Boolean crrsrvopt_isrecommended = _value.getIsRecommended(); 681 if(crrsrvopt_isrecommended == null) 682 _ps.setNull(4, Types.BIT); 683 else 684 _ps.setInt(4, crrsrvopt_isrecommended? 1: 0); 685 686 Boolean crrsrvopt_isrequired = _value.getIsRequired(); 687 if(crrsrvopt_isrequired == null) 688 _ps.setNull(5, Types.BIT); 689 else 690 _ps.setInt(5, crrsrvopt_isrequired? 1: 0); 691 692 SelectorPK crrsrvopt_recommendedgeocodeselectorid = _value.getRecommendedGeoCodeSelectorPK(); 693 if(crrsrvopt_recommendedgeocodeselectorid == null) 694 _ps.setNull(6, Types.BIGINT); 695 else 696 _ps.setLong(6, crrsrvopt_recommendedgeocodeselectorid.getEntityId()); 697 698 SelectorPK crrsrvopt_requiredgeocodeselectorid = _value.getRequiredGeoCodeSelectorPK(); 699 if(crrsrvopt_requiredgeocodeselectorid == null) 700 _ps.setNull(7, Types.BIGINT); 701 else 702 _ps.setLong(7, crrsrvopt_requiredgeocodeselectorid.getEntityId()); 703 704 SelectorPK crrsrvopt_recommendeditemselectorid = _value.getRecommendedItemSelectorPK(); 705 if(crrsrvopt_recommendeditemselectorid == null) 706 _ps.setNull(8, Types.BIGINT); 707 else 708 _ps.setLong(8, crrsrvopt_recommendeditemselectorid.getEntityId()); 709 710 SelectorPK crrsrvopt_requireditemselectorid = _value.getRequiredItemSelectorPK(); 711 if(crrsrvopt_requireditemselectorid == null) 712 _ps.setNull(9, Types.BIGINT); 713 else 714 _ps.setLong(9, crrsrvopt_requireditemselectorid.getEntityId()); 715 716 SelectorPK crrsrvopt_recommendedorderselectorid = _value.getRecommendedOrderSelectorPK(); 717 if(crrsrvopt_recommendedorderselectorid == null) 718 _ps.setNull(10, Types.BIGINT); 719 else 720 _ps.setLong(10, crrsrvopt_recommendedorderselectorid.getEntityId()); 721 722 SelectorPK crrsrvopt_requiredorderselectorid = _value.getRequiredOrderSelectorPK(); 723 if(crrsrvopt_requiredorderselectorid == null) 724 _ps.setNull(11, Types.BIGINT); 725 else 726 _ps.setLong(11, crrsrvopt_requiredorderselectorid.getEntityId()); 727 728 SelectorPK crrsrvopt_recommendedshipmentselectorid = _value.getRecommendedShipmentSelectorPK(); 729 if(crrsrvopt_recommendedshipmentselectorid == null) 730 _ps.setNull(12, Types.BIGINT); 731 else 732 _ps.setLong(12, crrsrvopt_recommendedshipmentselectorid.getEntityId()); 733 734 SelectorPK crrsrvopt_requiredshipmentselectorid = _value.getRequiredShipmentSelectorPK(); 735 if(crrsrvopt_requiredshipmentselectorid == null) 736 _ps.setNull(13, Types.BIGINT); 737 else 738 _ps.setLong(13, crrsrvopt_requiredshipmentselectorid.getEntityId()); 739 740 Long crrsrvopt_fromtime = _value.getFromTime(); 741 if(crrsrvopt_fromtime == null) 742 _ps.setNull(14, Types.BIGINT); 743 else 744 _ps.setLong(14, crrsrvopt_fromtime); 745 746 Long crrsrvopt_thrutime = _value.getThruTime(); 747 if(crrsrvopt_thrutime == null) 748 _ps.setNull(15, Types.BIGINT); 749 else 750 _ps.setLong(15, crrsrvopt_thrutime); 751 752 } 753 754 public CarrierServiceOption create(CarrierServicePK carrierServicePK, CarrierOptionPK carrierOptionPK, Boolean isRecommended, Boolean isRequired, SelectorPK recommendedGeoCodeSelectorPK, SelectorPK requiredGeoCodeSelectorPK, SelectorPK recommendedItemSelectorPK, SelectorPK requiredItemSelectorPK, SelectorPK recommendedOrderSelectorPK, SelectorPK requiredOrderSelectorPK, SelectorPK recommendedShipmentSelectorPK, SelectorPK requiredShipmentSelectorPK, Long fromTime, Long thruTime) 755 throws PersistenceDatabaseException, PersistenceNotNullException { 756 CarrierServiceOptionPK _pk = getNextPK(); 757 CarrierServiceOptionValue _value = new CarrierServiceOptionValue(_pk, carrierServicePK, carrierOptionPK, isRecommended, isRequired, recommendedGeoCodeSelectorPK, requiredGeoCodeSelectorPK, recommendedItemSelectorPK, requiredItemSelectorPK, recommendedOrderSelectorPK, requiredOrderSelectorPK, recommendedShipmentSelectorPK, requiredShipmentSelectorPK, fromTime, thruTime); 758 759 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 760 761 try { 762 bindForCreate(_ps, _value); 763 764 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 765 int _count = _ps.executeUpdate(); 766 767 if(_count != 1) { 768 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 769 } 770 } else { 771 _ps.executeUpdate(); 772 } 773 774 session.getValueCache().put(_value); 775 } catch (SQLException se) { 776 throw new PersistenceDatabaseException(se); 777 } 778 779 CarrierServiceOption _entity = new CarrierServiceOption(_value, EntityPermission.READ_ONLY); 780 session.putReadOnlyEntity(_pk, _entity); 781 782 return _entity; 783 } 784 785 public void create(Collection<CarrierServiceOptionValue> _values) 786 throws PersistenceDatabaseException, PersistenceNotNullException { 787 int _size = _values.size(); 788 789 if(_size > 0) { 790 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 791 List<CarrierServiceOptionValue> _cacheValues = new ArrayList<>(_size); 792 793 try { 794 for(CarrierServiceOptionValue _value : _values) { 795 _value.setEntityId(entityIdGenerator.getNextEntityId()); 796 bindForCreate(_ps, _value); 797 798 _ps.addBatch(); 799 800 _cacheValues.add(_value); 801 } 802 803 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 804 int[] _counts = _ps.executeBatch(); 805 806 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 807 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 808 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 809 } 810 } 811 } else { 812 _ps.executeBatch(); 813 } 814 815 _ps.clearBatch(); 816 } catch (SQLException se) { 817 throw new PersistenceDatabaseException(se); 818 } 819 820 _cacheValues.forEach((_cacheValue) -> { 821 CarrierServiceOption _cacheEntity = new CarrierServiceOption(_cacheValue, EntityPermission.READ_ONLY); 822 823 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 824 }); 825 } 826 } 827 828 private boolean bindForStore(PreparedStatement _ps, CarrierServiceOptionValue _value) 829 throws SQLException { 830 boolean _hasBeenModified = _value.hasBeenModified(); 831 832 if(_hasBeenModified) { 833 CarrierServicePK crrsrvopt_crrsrv_carrierserviceid = _value.getCarrierServicePK(); 834 if(crrsrvopt_crrsrv_carrierserviceid == null) 835 _ps.setNull(1, Types.BIGINT); 836 else 837 _ps.setLong(1, crrsrvopt_crrsrv_carrierserviceid.getEntityId()); 838 839 CarrierOptionPK crrsrvopt_crropt_carrieroptionid = _value.getCarrierOptionPK(); 840 if(crrsrvopt_crropt_carrieroptionid == null) 841 _ps.setNull(2, Types.BIGINT); 842 else 843 _ps.setLong(2, crrsrvopt_crropt_carrieroptionid.getEntityId()); 844 845 Boolean crrsrvopt_isrecommended = _value.getIsRecommended(); 846 if(crrsrvopt_isrecommended == null) 847 _ps.setNull(3, Types.BIT); 848 else 849 _ps.setInt(3, crrsrvopt_isrecommended? 1: 0); 850 851 Boolean crrsrvopt_isrequired = _value.getIsRequired(); 852 if(crrsrvopt_isrequired == null) 853 _ps.setNull(4, Types.BIT); 854 else 855 _ps.setInt(4, crrsrvopt_isrequired? 1: 0); 856 857 SelectorPK crrsrvopt_recommendedgeocodeselectorid = _value.getRecommendedGeoCodeSelectorPK(); 858 if(crrsrvopt_recommendedgeocodeselectorid == null) 859 _ps.setNull(5, Types.BIGINT); 860 else 861 _ps.setLong(5, crrsrvopt_recommendedgeocodeselectorid.getEntityId()); 862 863 SelectorPK crrsrvopt_requiredgeocodeselectorid = _value.getRequiredGeoCodeSelectorPK(); 864 if(crrsrvopt_requiredgeocodeselectorid == null) 865 _ps.setNull(6, Types.BIGINT); 866 else 867 _ps.setLong(6, crrsrvopt_requiredgeocodeselectorid.getEntityId()); 868 869 SelectorPK crrsrvopt_recommendeditemselectorid = _value.getRecommendedItemSelectorPK(); 870 if(crrsrvopt_recommendeditemselectorid == null) 871 _ps.setNull(7, Types.BIGINT); 872 else 873 _ps.setLong(7, crrsrvopt_recommendeditemselectorid.getEntityId()); 874 875 SelectorPK crrsrvopt_requireditemselectorid = _value.getRequiredItemSelectorPK(); 876 if(crrsrvopt_requireditemselectorid == null) 877 _ps.setNull(8, Types.BIGINT); 878 else 879 _ps.setLong(8, crrsrvopt_requireditemselectorid.getEntityId()); 880 881 SelectorPK crrsrvopt_recommendedorderselectorid = _value.getRecommendedOrderSelectorPK(); 882 if(crrsrvopt_recommendedorderselectorid == null) 883 _ps.setNull(9, Types.BIGINT); 884 else 885 _ps.setLong(9, crrsrvopt_recommendedorderselectorid.getEntityId()); 886 887 SelectorPK crrsrvopt_requiredorderselectorid = _value.getRequiredOrderSelectorPK(); 888 if(crrsrvopt_requiredorderselectorid == null) 889 _ps.setNull(10, Types.BIGINT); 890 else 891 _ps.setLong(10, crrsrvopt_requiredorderselectorid.getEntityId()); 892 893 SelectorPK crrsrvopt_recommendedshipmentselectorid = _value.getRecommendedShipmentSelectorPK(); 894 if(crrsrvopt_recommendedshipmentselectorid == null) 895 _ps.setNull(11, Types.BIGINT); 896 else 897 _ps.setLong(11, crrsrvopt_recommendedshipmentselectorid.getEntityId()); 898 899 SelectorPK crrsrvopt_requiredshipmentselectorid = _value.getRequiredShipmentSelectorPK(); 900 if(crrsrvopt_requiredshipmentselectorid == null) 901 _ps.setNull(12, Types.BIGINT); 902 else 903 _ps.setLong(12, crrsrvopt_requiredshipmentselectorid.getEntityId()); 904 905 Long crrsrvopt_fromtime = _value.getFromTime(); 906 if(crrsrvopt_fromtime == null) 907 _ps.setNull(13, Types.BIGINT); 908 else 909 _ps.setLong(13, crrsrvopt_fromtime); 910 911 Long crrsrvopt_thrutime = _value.getThruTime(); 912 if(crrsrvopt_thrutime == null) 913 _ps.setNull(14, Types.BIGINT); 914 else 915 _ps.setLong(14, crrsrvopt_thrutime); 916 917 _ps.setLong(15, _value.getPrimaryKey().getEntityId()); 918 919 _value.clearHasBeenModified(); 920 } 921 922 return _hasBeenModified; 923 } 924 925 @Override 926 public void store(CarrierServiceOption entity) 927 throws PersistenceDatabaseException { 928 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 929 930 try { 931 CarrierServiceOptionValue _value = entity.getCarrierServiceOptionValue(); 932 933 if(bindForStore(_ps, _value)) { 934 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 935 int _count = _ps.executeUpdate(); 936 937 if(_count != 1) { 938 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 939 } 940 } else { 941 _ps.executeUpdate(); 942 } 943 944 session.getValueCache().put(_value); 945 } 946 } catch (SQLException se) { 947 throw new PersistenceDatabaseException(se); 948 } 949 } 950 951 @Override 952 public void store(Collection<CarrierServiceOption> entities) 953 throws PersistenceDatabaseException { 954 if(entities.size() > 0) { 955 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 956 int _modifiedEntities = 0; 957 958 try { 959 for(CarrierServiceOption entity : entities) { 960 if(bindForStore(_ps, entity.getCarrierServiceOptionValue())) { 961 _ps.addBatch(); 962 _modifiedEntities++; 963 } 964 } 965 966 if(_modifiedEntities != 0) { 967 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 968 int[] _counts = _ps.executeBatch(); 969 970 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 971 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 972 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 973 } 974 } 975 } else { 976 _ps.executeBatch(); 977 } 978 979 _ps.clearBatch(); 980 981 entities.forEach((entity) -> { 982 session.getValueCache().put(entity.getCarrierServiceOptionValue()); 983 }); 984 } 985 } catch (SQLException se) { 986 throw new PersistenceDatabaseException(se); 987 } 988 } 989 } 990 991 @Override 992 public void remove(CarrierServiceOption entity) 993 throws PersistenceDatabaseException { 994 remove(entity.getPrimaryKey()); 995 } 996 997 @Override 998 public void remove(CarrierServiceOptionPK pk) 999 throws PersistenceDatabaseException { 1000 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1001 long _entityId = pk.getEntityId(); 1002 1003 try { 1004 _ps.setLong(1, _entityId); 1005 1006 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1007 int _count = _ps.executeUpdate(); 1008 1009 if(_count != 1) { 1010 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 1011 } 1012 } else { 1013 _ps.executeUpdate(); 1014 } 1015 1016 session.getValueCache().remove(pk); 1017 } catch (SQLException se) { 1018 throw new PersistenceDatabaseException(se); 1019 } 1020 1021 session.removed(pk, false); 1022 } 1023 1024 @Override 1025 public void remove(Collection<CarrierServiceOptionPK> pks) 1026 throws PersistenceDatabaseException { 1027 if(pks.size() > 0) { 1028 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 1029 int _modifiedEntities = 0; 1030 1031 try { 1032 for(CarrierServiceOptionPK pk : pks) { 1033 long _entityId = pk.getEntityId(); 1034 1035 _ps.setLong(1, _entityId); 1036 1037 _ps.addBatch(); 1038 _modifiedEntities++; 1039 } 1040 1041 if(_modifiedEntities != 0) { 1042 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 1043 int[] _counts = _ps.executeBatch(); 1044 1045 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 1046 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 1047 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 1048 } 1049 } 1050 } else { 1051 _ps.executeBatch(); 1052 } 1053 1054 _ps.clearBatch(); 1055 1056 pks.forEach((pk) -> { 1057 session.getValueCache().remove(pk); 1058 }); 1059 } 1060 } catch (SQLException se) { 1061 throw new PersistenceDatabaseException(se); 1062 } 1063 1064 pks.forEach((pk) -> { 1065 session.removed(pk, true); 1066 }); 1067 } 1068 } 1069 1070 @Override 1071 public boolean validPK(CarrierServiceOptionPK pk) 1072 throws PersistenceDatabaseException { 1073 boolean valid = false; 1074 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 1075 ResultSet _rs = null; 1076 1077 try { 1078 _ps.setLong(1, pk.getEntityId()); 1079 1080 _rs = _ps.executeQuery(); 1081 if(_rs.next()) { 1082 long _count = _rs.getLong(1); 1083 if(_rs.wasNull()) 1084 _count = 0; 1085 1086 if(_count == 1) 1087 valid = true; 1088 } 1089 } catch (SQLException se) { 1090 throw new PersistenceDatabaseException(se); 1091 } finally { 1092 if(_rs != null) { 1093 try { 1094 _rs.close(); 1095 } catch (SQLException se) { 1096 // do nothing 1097 } 1098 } 1099 } 1100 1101 return valid; 1102 } 1103 1104}