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