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