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