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