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