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