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