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