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