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