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