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