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