001// -------------------------------------------------------------------------------- 002// Copyright 2002-2026 Echo Three, LLC 003// 004// Licensed under the Apache License, Version 2.0 (the "License"); 005// you may not use this file except in compliance with the License. 006// You may obtain a copy of the License at 007// 008// http://www.apache.org/licenses/LICENSE-2.0 009// 010// Unless required by applicable law or agreed to in writing, software 011// distributed under the License is distributed on an "AS IS" BASIS, 012// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013// See the License for the specific language governing permissions and 014// limitations under the License. 015// -------------------------------------------------------------------------------- 016// Generated File -- DO NOT EDIT BY HAND 017// -------------------------------------------------------------------------------- 018 019/** 020 * GeoCodeScopeDetailFactory.java 021 */ 022 023package com.echothree.model.data.geo.server.factory; 024 025import com.echothree.model.data.geo.common.pk.GeoCodeScopePK; 026 027import com.echothree.model.data.geo.server.entity.GeoCodeScope; 028 029import com.echothree.model.data.geo.common.GeoCodeScopeDetailConstants; 030import com.echothree.model.data.geo.common.pk.GeoCodeScopeDetailPK; 031import com.echothree.model.data.geo.server.value.GeoCodeScopeDetailValue; 032import com.echothree.model.data.geo.server.entity.GeoCodeScopeDetail; 033import com.echothree.util.common.exception.PersistenceDatabaseException; 034import com.echothree.util.common.exception.PersistenceDatabaseUpdateException; 035import com.echothree.util.common.exception.PersistenceNotNullException; 036import com.echothree.util.server.persistence.BaseFactory; 037import com.echothree.util.server.persistence.EntityIdGenerator; 038import com.echothree.util.server.persistence.EntityPermission; 039import com.echothree.util.server.persistence.PersistenceDebugFlags; 040import com.echothree.util.server.persistence.Session; 041import java.sql.PreparedStatement; 042import java.sql.ResultSet; 043import java.sql.SQLException; 044import java.sql.Types; 045import java.io.ByteArrayInputStream; 046import java.io.StringReader; 047import java.util.ArrayList; 048import java.util.Collection; 049import java.util.HashSet; 050import java.util.List; 051import java.util.Map; 052import java.util.Set; 053import javax.enterprise.context.ApplicationScoped; 054import javax.enterprise.inject.spi.CDI; 055import javax.inject.Inject; 056import org.jooq.ResultQuery; 057import org.slf4j.Logger; 058import org.slf4j.LoggerFactory; 059 060@ApplicationScoped 061public class GeoCodeScopeDetailFactory 062 implements BaseFactory<GeoCodeScopeDetailPK, GeoCodeScopeDetail> { 063 064 @Inject 065 Session session; 066 067 //private static final Logger log = LoggerFactory.getLogger(GeoCodeScopeDetailFactory.class); 068 069 final private static String SQL_SELECT_READ_ONLY = "SELECT geosdt_geocodescopedetailid, geosdt_geos_geocodescopeid, geosdt_geocodescopename, geosdt_isdefault, geosdt_sortorder, geosdt_fromtime, geosdt_thrutime FROM geocodescopedetails WHERE geosdt_geocodescopedetailid = ?"; 070 final private static String SQL_SELECT_READ_WRITE = "SELECT geosdt_geocodescopedetailid, geosdt_geos_geocodescopeid, geosdt_geocodescopename, geosdt_isdefault, geosdt_sortorder, geosdt_fromtime, geosdt_thrutime FROM geocodescopedetails WHERE geosdt_geocodescopedetailid = ? FOR UPDATE"; 071 final private static String SQL_INSERT = "INSERT INTO geocodescopedetails (geosdt_geocodescopedetailid, geosdt_geos_geocodescopeid, geosdt_geocodescopename, geosdt_isdefault, geosdt_sortorder, geosdt_fromtime, geosdt_thrutime) VALUES (?, ?, ?, ?, ?, ?, ?)"; 072 final private static String SQL_UPDATE = "UPDATE geocodescopedetails SET geosdt_geos_geocodescopeid = ?, geosdt_geocodescopename = ?, geosdt_isdefault = ?, geosdt_sortorder = ?, geosdt_fromtime = ?, geosdt_thrutime = ? WHERE geosdt_geocodescopedetailid = ?"; 073 final private static String SQL_DELETE = "DELETE FROM geocodescopedetails WHERE geosdt_geocodescopedetailid = ?"; 074 final private static String SQL_VALID = "SELECT COUNT(*) FROM geocodescopedetails WHERE geosdt_geocodescopedetailid = ?"; 075 076 final public static String GEOSDT_GEOCODESCOPEDETAILID = "geosdt_geocodescopedetailid"; 077 final public static String GEOSDT_GEOS_GEOCODESCOPEID = "geosdt_geos_geocodescopeid"; 078 final public static String GEOSDT_GEOCODESCOPENAME = "geosdt_geocodescopename"; 079 final public static String GEOSDT_ISDEFAULT = "geosdt_isdefault"; 080 final public static String GEOSDT_SORTORDER = "geosdt_sortorder"; 081 final public static String GEOSDT_FROMTIME = "geosdt_fromtime"; 082 final public static String GEOSDT_THRUTIME = "geosdt_thrutime"; 083 084 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(GeoCodeScopeDetailConstants.COMPONENT_VENDOR_NAME, GeoCodeScopeDetailConstants.ENTITY_TYPE_NAME); 085 086 /** Creates a new instance of GeoCodeScopeDetailFactory */ 087 protected GeoCodeScopeDetailFactory() { 088 super(); 089 } 090 091 public static GeoCodeScopeDetailFactory getInstance() { 092 return CDI.current().select(GeoCodeScopeDetailFactory.class).get(); 093 } 094 095 @Override 096 public String getComponentVendorName() { 097 return GeoCodeScopeDetailConstants.COMPONENT_VENDOR_NAME; 098 } 099 100 @Override 101 public String getEntityTypeName() { 102 return GeoCodeScopeDetailConstants.ENTITY_TYPE_NAME; 103 } 104 105 public PreparedStatement prepareStatement(String query) { 106 return session.prepareStatement(query); 107 } 108 109 public GeoCodeScopeDetailPK getNextPK() { 110 return new GeoCodeScopeDetailPK(entityIdGenerator.getNextEntityId()); 111 } 112 113 public Set<GeoCodeScopeDetailPK> getPKsFromResultSetAsSet(ResultSet rs) 114 throws PersistenceDatabaseException { 115 Set<GeoCodeScopeDetailPK> _result = new HashSet<>(); 116 117 try { 118 while(rs.next()) { 119 _result.add(getPKFromResultSet(rs)); 120 } 121 } catch (SQLException se) { 122 throw new PersistenceDatabaseException(se); 123 } 124 125 return _result; 126 } 127 128 public java.util.List<GeoCodeScopeDetailPK> getPKsFromResultSetAsList(ResultSet rs) 129 throws PersistenceDatabaseException { 130 java.util.List<GeoCodeScopeDetailPK> _result = new ArrayList<>(); 131 132 try { 133 while(rs.next()) { 134 _result.add(getPKFromResultSet(rs)); 135 } 136 } catch (SQLException se) { 137 throw new PersistenceDatabaseException(se); 138 } 139 140 return _result; 141 } 142 143 public GeoCodeScopeDetailPK getPKFromResultSet(ResultSet rs) 144 throws PersistenceDatabaseException { 145 GeoCodeScopeDetailPK _result; 146 147 try { 148 long geosdt_geocodescopedetailid = rs.getLong(GEOSDT_GEOCODESCOPEDETAILID); 149 Long _entityId = rs.wasNull() ? null : geosdt_geocodescopedetailid; 150 151 _result = new GeoCodeScopeDetailPK(_entityId); 152 } catch (SQLException se) { 153 throw new PersistenceDatabaseException(se); 154 } 155 156 return _result; 157 } 158 159 public java.util.List<GeoCodeScopeDetailValue> getValuesFromPKs(Collection<GeoCodeScopeDetailPK> pks) 160 throws PersistenceDatabaseException { 161 java.util.List<GeoCodeScopeDetailValue> _values = new ArrayList<>(pks.size()); 162 163 for(GeoCodeScopeDetailPK _pk: pks) { 164 _values.add(getValueFromPK(_pk)); 165 } 166 167 return _values; 168 } 169 170 public GeoCodeScopeDetailValue getValueFromPK(GeoCodeScopeDetailPK pk) 171 throws PersistenceDatabaseException { 172 GeoCodeScopeDetailValue _value; 173 174 // See if we already have the entity in the session cache 175 GeoCodeScopeDetail _entity = (GeoCodeScopeDetail)session.getEntity(pk); 176 if(_entity == null) 177 _value = getEntityFromPK(EntityPermission.READ_ONLY, pk).getGeoCodeScopeDetailValue(); 178 else 179 _value = _entity.getGeoCodeScopeDetailValue(); 180 181 return _value; 182 } 183 184 public java.util.List<GeoCodeScopeDetailValue> getValuesFromResultSet(ResultSet rs) 185 throws PersistenceDatabaseException { 186 java.util.List<GeoCodeScopeDetailValue> _result = new ArrayList<>(); 187 188 try { 189 while(rs.next()) { 190 _result.add(getValueFromResultSet(rs)); 191 } 192 } catch (SQLException se) { 193 throw new PersistenceDatabaseException(se); 194 } 195 196 return _result; 197 } 198 199 public GeoCodeScopeDetailValue getValueFromResultSet(ResultSet rs) 200 throws PersistenceDatabaseException { 201 GeoCodeScopeDetailValue _value; 202 203 try { 204 Long geosdt_geocodescopedetailid = rs.getLong(GEOSDT_GEOCODESCOPEDETAILID); 205 GeoCodeScopeDetailPK _pk = new GeoCodeScopeDetailPK(geosdt_geocodescopedetailid); 206 207 // See if we already have the entity in the session cache 208 GeoCodeScopeDetail _entity = (GeoCodeScopeDetail)session.getEntity(_pk); 209 210 if(_entity == null) { 211 Long geosdt_geos_geocodescopeid = rs.getLong(GEOSDT_GEOS_GEOCODESCOPEID); 212 if(rs.wasNull()) 213 geosdt_geos_geocodescopeid = null; 214 215 String geosdt_geocodescopename = rs.getString(GEOSDT_GEOCODESCOPENAME); 216 if(rs.wasNull()) 217 geosdt_geocodescopename = null; 218 219 Boolean geosdt_isdefault = rs.getInt(GEOSDT_ISDEFAULT) == 1; 220 if(rs.wasNull()) 221 geosdt_isdefault = null; 222 223 Integer geosdt_sortorder = rs.getInt(GEOSDT_SORTORDER); 224 if(rs.wasNull()) 225 geosdt_sortorder = null; 226 227 Long geosdt_fromtime = rs.getLong(GEOSDT_FROMTIME); 228 if(rs.wasNull()) 229 geosdt_fromtime = null; 230 231 Long geosdt_thrutime = rs.getLong(GEOSDT_THRUTIME); 232 if(rs.wasNull()) 233 geosdt_thrutime = null; 234 235 _value = new GeoCodeScopeDetailValue(_pk, new GeoCodeScopePK(geosdt_geos_geocodescopeid), geosdt_geocodescopename, geosdt_isdefault, geosdt_sortorder, geosdt_fromtime, geosdt_thrutime); 236 } else 237 _value = _entity.getGeoCodeScopeDetailValue(); 238 } catch (SQLException se) { 239 throw new PersistenceDatabaseException(se); 240 } 241 242 return _value; 243 } 244 245 public java.util.List<GeoCodeScopeDetail> getEntitiesFromPKs(EntityPermission entityPermission, Collection<GeoCodeScopeDetailPK> pks) 246 throws PersistenceDatabaseException { 247 java.util.List<GeoCodeScopeDetail> _entities = new ArrayList<>(pks.size()); 248 249 for(GeoCodeScopeDetailPK _pk: pks) { 250 _entities.add(getEntityFromPK(entityPermission, _pk)); 251 } 252 253 return _entities; 254 } 255 256 public GeoCodeScopeDetail getEntityFromValue(EntityPermission entityPermission, GeoCodeScopeDetailValue value) { 257 return getEntityFromPK(entityPermission, value.getPrimaryKey()); 258 } 259 260 public GeoCodeScopeDetail getEntityFromCache(GeoCodeScopeDetailPK pk) { 261 GeoCodeScopeDetailValue _value = (GeoCodeScopeDetailValue)session.getValueCache().get(pk); 262 263 return _value == null ? null : new GeoCodeScopeDetail(_value, EntityPermission.READ_ONLY); 264 } 265 266 public GeoCodeScopeDetail getEntityFromPK(EntityPermission entityPermission, GeoCodeScopeDetailPK pk) 267 throws PersistenceDatabaseException { 268 GeoCodeScopeDetail _entity; 269 270 // See if we already have the entity in the session cache 271 _entity = (GeoCodeScopeDetail)session.getEntity(pk); 272 if(_entity != null) { 273 // If the requested permission is READ_WRITE, and the cached permission is 274 // READ_ONLY, then pretend that the cached object wasn't found, and create 275 // a new entity that is READ_WRITE. 276 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 277 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 278 _entity = null; 279 } 280 } 281 282 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 283 _entity = getEntityFromCache(pk); 284 } 285 286 if(_entity == null) { 287 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 288 long _entityId = pk.getEntityId(); 289 ResultSet _rs = null; 290 291 try { 292 _ps.setLong(1, _entityId); 293 _rs = _ps.executeQuery(); 294 if(_rs.next()) { 295 _entity = getEntityFromResultSet(entityPermission, _rs); 296 } 297 } catch (SQLException se) { 298 throw new PersistenceDatabaseException(se); 299 } finally { 300 if(_rs != null) { 301 try { 302 _rs.close(); 303 } catch (SQLException se) { 304 // do nothing 305 } 306 } 307 } 308 } 309 310 return _entity; 311 } 312 313 public Set<GeoCodeScopeDetailPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 314 throws PersistenceDatabaseException { 315 Set<GeoCodeScopeDetailPK> _pks; 316 ResultSet _rs = null; 317 318 try { 319 if(params.length != 0) { 320 Session.setQueryParams(ps, params); 321 } 322 323 _rs = ps.executeQuery(); 324 _pks = getPKsFromResultSetAsSet(_rs); 325 _rs.close(); 326 } catch (SQLException se) { 327 throw new PersistenceDatabaseException(se); 328 } finally { 329 if(_rs != null) { 330 try { 331 _rs.close(); 332 } catch (SQLException se) { 333 // do nothing 334 } 335 } 336 } 337 338 return _pks; 339 } 340 341 public java.util.List<GeoCodeScopeDetailPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 342 throws PersistenceDatabaseException { 343 java.util.List<GeoCodeScopeDetailPK> _pks; 344 ResultSet _rs = null; 345 346 try { 347 if(params.length != 0) { 348 Session.setQueryParams(ps, params); 349 } 350 351 _rs = ps.executeQuery(); 352 _pks = getPKsFromResultSetAsList(_rs); 353 _rs.close(); 354 } catch (SQLException se) { 355 throw new PersistenceDatabaseException(se); 356 } finally { 357 if(_rs != null) { 358 try { 359 _rs.close(); 360 } catch (SQLException se) { 361 // do nothing 362 } 363 } 364 } 365 366 return _pks; 367 } 368 369 public GeoCodeScopeDetailPK getPKFromQuery(PreparedStatement ps, final Object... params) 370 throws PersistenceDatabaseException { 371 GeoCodeScopeDetailPK _pk = null; 372 ResultSet _rs = null; 373 374 try { 375 if(params.length != 0) { 376 Session.setQueryParams(ps, params); 377 } 378 379 _rs = ps.executeQuery(); 380 if(_rs.next()) { 381 _pk = getPKFromResultSet(_rs); 382 } 383 _rs.close(); 384 } catch (SQLException se) { 385 throw new PersistenceDatabaseException(se); 386 } finally { 387 if(_rs != null) { 388 try { 389 _rs.close(); 390 } catch (SQLException se) { 391 // do nothing 392 } 393 } 394 } 395 396 return _pk; 397 } 398 399 public java.util.List<GeoCodeScopeDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 400 throws PersistenceDatabaseException { 401 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 402 403 return getEntitiesFromQuery(entityPermission, ps, params); 404 } 405 406 public java.util.List<GeoCodeScopeDetail> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 407 throws PersistenceDatabaseException { 408 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 409 410 return getEntitiesFromQuery(entityPermission, ps); 411 } 412 413 public java.util.List<GeoCodeScopeDetail> getEntitiesFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 414 throws PersistenceDatabaseException { 415 PreparedStatement ps = session.prepareStatement(query.getSQL()); 416 417 return getEntitiesFromQuery(entityPermission, ps, query.getBindValues().toArray()); 418 } 419 420 public java.util.List<GeoCodeScopeDetail> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 421 throws PersistenceDatabaseException { 422 java.util.List<GeoCodeScopeDetail> _entities; 423 ResultSet _rs = null; 424 425 try { 426 if(params.length != 0) { 427 Session.setQueryParams(ps, params); 428 } 429 430 _rs = ps.executeQuery(); 431 _entities = getEntitiesFromResultSet(entityPermission, _rs); 432 _rs.close(); 433 } catch (SQLException se) { 434 throw new PersistenceDatabaseException(se); 435 } finally { 436 if(_rs != null) { 437 try { 438 _rs.close(); 439 } catch (SQLException se) { 440 // do nothing 441 } 442 } 443 } 444 445 return _entities; 446 } 447 448 public GeoCodeScopeDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 449 throws PersistenceDatabaseException { 450 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 451 452 return getEntityFromQuery(entityPermission, ps, params); 453 } 454 455 public GeoCodeScopeDetail getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 456 throws PersistenceDatabaseException { 457 PreparedStatement ps = session.prepareStatement(queryMap.get(entityPermission)); 458 459 return getEntityFromQuery(entityPermission, ps); 460 } 461 462 public GeoCodeScopeDetail getEntityFromQuery(EntityPermission entityPermission, ResultQuery<?> query) 463 throws PersistenceDatabaseException { 464 PreparedStatement ps = session.prepareStatement(query.getSQL()); 465 466 return getEntityFromQuery(entityPermission, ps, query.getBindValues().toArray()); 467 } 468 469 public GeoCodeScopeDetail getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 470 throws PersistenceDatabaseException { 471 GeoCodeScopeDetail _entity = null; 472 ResultSet _rs = null; 473 474 try { 475 if(params.length != 0) { 476 Session.setQueryParams(ps, params); 477 } 478 479 _rs = ps.executeQuery(); 480 if(_rs.next()) { 481 _entity = getEntityFromResultSet(entityPermission, _rs); 482 } 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 _entity; 497 } 498 499 public java.util.List<GeoCodeScopeDetail> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 500 throws PersistenceDatabaseException { 501 java.util.List<GeoCodeScopeDetail> _result = new ArrayList<>(); 502 503 try { 504 while(rs.next()) { 505 _result.add(getEntityFromResultSet(entityPermission, rs)); 506 } 507 } catch (SQLException se) { 508 throw new PersistenceDatabaseException(se); 509 } 510 511 return _result; 512 } 513 514 public GeoCodeScopeDetail getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 515 throws PersistenceDatabaseException { 516 GeoCodeScopeDetail _entity; 517 518 try { 519 Long geosdt_geocodescopedetailid = rs.getLong(GEOSDT_GEOCODESCOPEDETAILID); 520 GeoCodeScopeDetailPK _pk = new GeoCodeScopeDetailPK(geosdt_geocodescopedetailid); 521 522 // See if we already have the entity in the session cache 523 _entity = (GeoCodeScopeDetail)session.getEntity(_pk); 524 if(_entity != null) { 525 // If the requested permission is READ_WRITE, and the cached permission is 526 // READ_ONLY, then pretend that the cached object wasn't found, and create 527 // a new entity that is READ_WRITE. 528 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 529 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 530 _entity = null; 531 } 532 } 533 boolean foundInSessionCache = _entity != null; 534 535 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 536 _entity = getEntityFromCache(_pk); 537 } 538 539 if(_entity == null) { 540 Long geosdt_geos_geocodescopeid = rs.getLong(GEOSDT_GEOS_GEOCODESCOPEID); 541 if(rs.wasNull()) 542 geosdt_geos_geocodescopeid = null; 543 544 String geosdt_geocodescopename = rs.getString(GEOSDT_GEOCODESCOPENAME); 545 if(rs.wasNull()) 546 geosdt_geocodescopename = null; 547 548 Boolean geosdt_isdefault = rs.getInt(GEOSDT_ISDEFAULT) == 1; 549 if(rs.wasNull()) 550 geosdt_isdefault = null; 551 552 Integer geosdt_sortorder = rs.getInt(GEOSDT_SORTORDER); 553 if(rs.wasNull()) 554 geosdt_sortorder = null; 555 556 Long geosdt_fromtime = rs.getLong(GEOSDT_FROMTIME); 557 if(rs.wasNull()) 558 geosdt_fromtime = null; 559 560 Long geosdt_thrutime = rs.getLong(GEOSDT_THRUTIME); 561 if(rs.wasNull()) 562 geosdt_thrutime = null; 563 564 GeoCodeScopeDetailValue _value = new GeoCodeScopeDetailValue(_pk, geosdt_geos_geocodescopeid == null? null: new GeoCodeScopePK(geosdt_geos_geocodescopeid), geosdt_geocodescopename, geosdt_isdefault, geosdt_sortorder, geosdt_fromtime, geosdt_thrutime); 565 _entity = new GeoCodeScopeDetail(_value, entityPermission); 566 } 567 568 if(!foundInSessionCache) { 569 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 570 session.putReadOnlyEntity(_pk, _entity); 571 session.getValueCache().put(_entity.getGeoCodeScopeDetailValue()); 572 } else { 573 session.putReadWriteEntity(_pk, _entity); 574 } 575 } 576 } catch (SQLException se) { 577 throw new PersistenceDatabaseException(se); 578 } 579 580 return _entity; 581 } 582 583 public GeoCodeScopeDetail create(GeoCodeScope geoCodeScope, String geoCodeScopeName, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 584 throws PersistenceDatabaseException, PersistenceNotNullException { 585 return create(geoCodeScope == null ? null : geoCodeScope.getPrimaryKey(), geoCodeScopeName, isDefault, sortOrder, fromTime, thruTime); 586 } 587 588 private void bindForCreate(PreparedStatement _ps, GeoCodeScopeDetailValue _value) 589 throws SQLException { 590 _ps.setLong(1, _value.getEntityId()); 591 592 GeoCodeScopePK geosdt_geos_geocodescopeid = _value.getGeoCodeScopePK(); 593 if(geosdt_geos_geocodescopeid == null) 594 _ps.setNull(2, Types.BIGINT); 595 else 596 _ps.setLong(2, geosdt_geos_geocodescopeid.getEntityId()); 597 598 String geosdt_geocodescopename = _value.getGeoCodeScopeName(); 599 if(geosdt_geocodescopename == null) 600 _ps.setNull(3, Types.VARCHAR); 601 else 602 _ps.setString(3, geosdt_geocodescopename); 603 604 Boolean geosdt_isdefault = _value.getIsDefault(); 605 if(geosdt_isdefault == null) 606 _ps.setNull(4, Types.BIT); 607 else 608 _ps.setInt(4, geosdt_isdefault? 1: 0); 609 610 Integer geosdt_sortorder = _value.getSortOrder(); 611 if(geosdt_sortorder == null) 612 _ps.setNull(5, Types.INTEGER); 613 else 614 _ps.setInt(5, geosdt_sortorder); 615 616 Long geosdt_fromtime = _value.getFromTime(); 617 if(geosdt_fromtime == null) 618 _ps.setNull(6, Types.BIGINT); 619 else 620 _ps.setLong(6, geosdt_fromtime); 621 622 Long geosdt_thrutime = _value.getThruTime(); 623 if(geosdt_thrutime == null) 624 _ps.setNull(7, Types.BIGINT); 625 else 626 _ps.setLong(7, geosdt_thrutime); 627 628 } 629 630 public GeoCodeScopeDetail create(GeoCodeScopePK geoCodeScopePK, String geoCodeScopeName, Boolean isDefault, Integer sortOrder, Long fromTime, Long thruTime) 631 throws PersistenceDatabaseException, PersistenceNotNullException { 632 GeoCodeScopeDetailPK _pk = getNextPK(); 633 GeoCodeScopeDetailValue _value = new GeoCodeScopeDetailValue(_pk, geoCodeScopePK, geoCodeScopeName, isDefault, sortOrder, fromTime, thruTime); 634 635 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 636 637 try { 638 bindForCreate(_ps, _value); 639 640 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 641 int _count = _ps.executeUpdate(); 642 643 if(_count != 1) { 644 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 645 } 646 } else { 647 _ps.executeUpdate(); 648 } 649 650 session.getValueCache().put(_value); 651 } catch (SQLException se) { 652 throw new PersistenceDatabaseException(se); 653 } 654 655 GeoCodeScopeDetail _entity = new GeoCodeScopeDetail(_value, EntityPermission.READ_ONLY); 656 session.putReadOnlyEntity(_pk, _entity); 657 658 return _entity; 659 } 660 661 public void create(Collection<GeoCodeScopeDetailValue> _values) 662 throws PersistenceDatabaseException, PersistenceNotNullException { 663 int _size = _values.size(); 664 665 if(_size > 0) { 666 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 667 List<GeoCodeScopeDetailValue> _cacheValues = new ArrayList<>(_size); 668 669 try { 670 for(GeoCodeScopeDetailValue _value : _values) { 671 _value.setEntityId(entityIdGenerator.getNextEntityId()); 672 bindForCreate(_ps, _value); 673 674 _ps.addBatch(); 675 676 _cacheValues.add(_value); 677 } 678 679 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 680 int[] _counts = _ps.executeBatch(); 681 682 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 683 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 684 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 685 } 686 } 687 } else { 688 _ps.executeBatch(); 689 } 690 691 _ps.clearBatch(); 692 } catch (SQLException se) { 693 throw new PersistenceDatabaseException(se); 694 } 695 696 _cacheValues.forEach((_cacheValue) -> { 697 GeoCodeScopeDetail _cacheEntity = new GeoCodeScopeDetail(_cacheValue, EntityPermission.READ_ONLY); 698 699 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 700 }); 701 } 702 } 703 704 private boolean bindForStore(PreparedStatement _ps, GeoCodeScopeDetailValue _value) 705 throws SQLException { 706 boolean _hasBeenModified = _value.hasBeenModified(); 707 708 if(_hasBeenModified) { 709 GeoCodeScopePK geosdt_geos_geocodescopeid = _value.getGeoCodeScopePK(); 710 if(geosdt_geos_geocodescopeid == null) 711 _ps.setNull(1, Types.BIGINT); 712 else 713 _ps.setLong(1, geosdt_geos_geocodescopeid.getEntityId()); 714 715 String geosdt_geocodescopename = _value.getGeoCodeScopeName(); 716 if(geosdt_geocodescopename == null) 717 _ps.setNull(2, Types.VARCHAR); 718 else 719 _ps.setString(2, geosdt_geocodescopename); 720 721 Boolean geosdt_isdefault = _value.getIsDefault(); 722 if(geosdt_isdefault == null) 723 _ps.setNull(3, Types.BIT); 724 else 725 _ps.setInt(3, geosdt_isdefault? 1: 0); 726 727 Integer geosdt_sortorder = _value.getSortOrder(); 728 if(geosdt_sortorder == null) 729 _ps.setNull(4, Types.INTEGER); 730 else 731 _ps.setInt(4, geosdt_sortorder); 732 733 Long geosdt_fromtime = _value.getFromTime(); 734 if(geosdt_fromtime == null) 735 _ps.setNull(5, Types.BIGINT); 736 else 737 _ps.setLong(5, geosdt_fromtime); 738 739 Long geosdt_thrutime = _value.getThruTime(); 740 if(geosdt_thrutime == null) 741 _ps.setNull(6, Types.BIGINT); 742 else 743 _ps.setLong(6, geosdt_thrutime); 744 745 _ps.setLong(7, _value.getPrimaryKey().getEntityId()); 746 747 _value.clearHasBeenModified(); 748 } 749 750 return _hasBeenModified; 751 } 752 753 @Override 754 public void store(GeoCodeScopeDetail entity) 755 throws PersistenceDatabaseException { 756 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 757 758 try { 759 GeoCodeScopeDetailValue _value = entity.getGeoCodeScopeDetailValue(); 760 761 if(bindForStore(_ps, _value)) { 762 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 763 int _count = _ps.executeUpdate(); 764 765 if(_count != 1) { 766 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 767 } 768 } else { 769 _ps.executeUpdate(); 770 } 771 772 session.getValueCache().put(_value); 773 } 774 } catch (SQLException se) { 775 throw new PersistenceDatabaseException(se); 776 } 777 } 778 779 @Override 780 public void store(Collection<GeoCodeScopeDetail> entities) 781 throws PersistenceDatabaseException { 782 if(entities.size() > 0) { 783 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 784 int _modifiedEntities = 0; 785 786 try { 787 for(GeoCodeScopeDetail entity : entities) { 788 if(bindForStore(_ps, entity.getGeoCodeScopeDetailValue())) { 789 _ps.addBatch(); 790 _modifiedEntities++; 791 } 792 } 793 794 if(_modifiedEntities != 0) { 795 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 796 int[] _counts = _ps.executeBatch(); 797 798 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 799 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 800 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 801 } 802 } 803 } else { 804 _ps.executeBatch(); 805 } 806 807 _ps.clearBatch(); 808 809 entities.forEach((entity) -> { 810 session.getValueCache().put(entity.getGeoCodeScopeDetailValue()); 811 }); 812 } 813 } catch (SQLException se) { 814 throw new PersistenceDatabaseException(se); 815 } 816 } 817 } 818 819 @Override 820 public void remove(GeoCodeScopeDetail entity) 821 throws PersistenceDatabaseException { 822 remove(entity.getPrimaryKey()); 823 } 824 825 @Override 826 public void remove(GeoCodeScopeDetailPK pk) 827 throws PersistenceDatabaseException { 828 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 829 long _entityId = pk.getEntityId(); 830 831 try { 832 _ps.setLong(1, _entityId); 833 834 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 835 int _count = _ps.executeUpdate(); 836 837 if(_count != 1) { 838 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 839 } 840 } else { 841 _ps.executeUpdate(); 842 } 843 844 session.getValueCache().remove(pk); 845 } catch (SQLException se) { 846 throw new PersistenceDatabaseException(se); 847 } 848 849 session.removed(pk, false); 850 } 851 852 @Override 853 public void remove(Collection<GeoCodeScopeDetailPK> pks) 854 throws PersistenceDatabaseException { 855 if(pks.size() > 0) { 856 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 857 int _modifiedEntities = 0; 858 859 try { 860 for(GeoCodeScopeDetailPK pk : pks) { 861 long _entityId = pk.getEntityId(); 862 863 _ps.setLong(1, _entityId); 864 865 _ps.addBatch(); 866 _modifiedEntities++; 867 } 868 869 if(_modifiedEntities != 0) { 870 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 871 int[] _counts = _ps.executeBatch(); 872 873 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 874 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 875 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 876 } 877 } 878 } else { 879 _ps.executeBatch(); 880 } 881 882 _ps.clearBatch(); 883 884 pks.forEach((pk) -> { 885 session.getValueCache().remove(pk); 886 }); 887 } 888 } catch (SQLException se) { 889 throw new PersistenceDatabaseException(se); 890 } 891 892 pks.forEach((pk) -> { 893 session.removed(pk, true); 894 }); 895 } 896 } 897 898 @Override 899 public boolean validPK(GeoCodeScopeDetailPK pk) 900 throws PersistenceDatabaseException { 901 boolean valid = false; 902 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 903 ResultSet _rs = null; 904 905 try { 906 _ps.setLong(1, pk.getEntityId()); 907 908 _rs = _ps.executeQuery(); 909 if(_rs.next()) { 910 long _count = _rs.getLong(1); 911 if(_rs.wasNull()) 912 _count = 0; 913 914 if(_count == 1) 915 valid = true; 916 } 917 } catch (SQLException se) { 918 throw new PersistenceDatabaseException(se); 919 } finally { 920 if(_rs != null) { 921 try { 922 _rs.close(); 923 } catch (SQLException se) { 924 // do nothing 925 } 926 } 927 } 928 929 return valid; 930 } 931 932}