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