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