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