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