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