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 * ShippingMethodDescriptionFactory.java 021 */ 022 023package com.echothree.model.data.shipping.server.factory; 024 025import com.echothree.model.data.shipping.common.pk.ShippingMethodPK; 026import com.echothree.model.data.party.common.pk.LanguagePK; 027 028import com.echothree.model.data.shipping.server.entity.ShippingMethod; 029import com.echothree.model.data.party.server.entity.Language; 030 031import com.echothree.model.data.shipping.common.ShippingMethodDescriptionConstants; 032import com.echothree.model.data.shipping.common.pk.ShippingMethodDescriptionPK; 033import com.echothree.model.data.shipping.server.value.ShippingMethodDescriptionValue; 034import com.echothree.model.data.shipping.server.entity.ShippingMethodDescription; 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 ShippingMethodDescriptionFactory 063 implements BaseFactory<ShippingMethodDescriptionPK, ShippingMethodDescription> { 064 065 //final private static Log log = LogFactory.getLog(ShippingMethodDescriptionFactory.class); 066 067 final private static String SQL_SELECT_READ_ONLY = "SELECT shmd_shippingmethoddescriptionid, shmd_shm_shippingmethodid, shmd_lang_languageid, shmd_description, shmd_fromtime, shmd_thrutime FROM shippingmethoddescriptions WHERE shmd_shippingmethoddescriptionid = ?"; 068 final private static String SQL_SELECT_READ_WRITE = "SELECT shmd_shippingmethoddescriptionid, shmd_shm_shippingmethodid, shmd_lang_languageid, shmd_description, shmd_fromtime, shmd_thrutime FROM shippingmethoddescriptions WHERE shmd_shippingmethoddescriptionid = ? FOR UPDATE"; 069 final private static String SQL_INSERT = "INSERT INTO shippingmethoddescriptions (shmd_shippingmethoddescriptionid, shmd_shm_shippingmethodid, shmd_lang_languageid, shmd_description, shmd_fromtime, shmd_thrutime) VALUES (?, ?, ?, ?, ?, ?)"; 070 final private static String SQL_UPDATE = "UPDATE shippingmethoddescriptions SET shmd_shm_shippingmethodid = ?, shmd_lang_languageid = ?, shmd_description = ?, shmd_fromtime = ?, shmd_thrutime = ? WHERE shmd_shippingmethoddescriptionid = ?"; 071 final private static String SQL_DELETE = "DELETE FROM shippingmethoddescriptions WHERE shmd_shippingmethoddescriptionid = ?"; 072 final private static String SQL_VALID = "SELECT COUNT(*) FROM shippingmethoddescriptions WHERE shmd_shippingmethoddescriptionid = ?"; 073 074 final private static String PK_COLUMN = "shmd_shippingmethoddescriptionid"; 075 final private static String ALL_COLUMNS = "shmd_shippingmethoddescriptionid, shmd_shm_shippingmethodid, shmd_lang_languageid, shmd_description, shmd_fromtime, shmd_thrutime"; 076 final public static String TABLE_NAME = "shippingmethoddescriptions"; 077 078 final public static String SHMD_SHIPPINGMETHODDESCRIPTIONID = "shmd_shippingmethoddescriptionid"; 079 final public static String SHMD_SHM_SHIPPINGMETHODID = "shmd_shm_shippingmethodid"; 080 final public static String SHMD_LANG_LANGUAGEID = "shmd_lang_languageid"; 081 final public static String SHMD_DESCRIPTION = "shmd_description"; 082 final public static String SHMD_FROMTIME = "shmd_fromtime"; 083 final public static String SHMD_THRUTIME = "shmd_thrutime"; 084 085 final private static EntityIdGenerator entityIdGenerator = new EntityIdGenerator(ShippingMethodDescriptionConstants.COMPONENT_VENDOR_NAME, ShippingMethodDescriptionConstants.ENTITY_TYPE_NAME); 086 087 /** Creates a new instance of ShippingMethodDescriptionFactory */ 088 protected ShippingMethodDescriptionFactory() { 089 super(); 090 } 091 092 public static ShippingMethodDescriptionFactory getInstance() { 093 return CDI.current().select(ShippingMethodDescriptionFactory.class).get(); 094 } 095 096 @Override 097 public String getPKColumn() { 098 return PK_COLUMN; 099 } 100 101 @Override 102 public String getAllColumns() { 103 return ALL_COLUMNS; 104 } 105 106 @Override 107 public String getTableName() { 108 return TABLE_NAME; 109 } 110 111 @Override 112 public String getComponentVendorName() { 113 return ShippingMethodDescriptionConstants.COMPONENT_VENDOR_NAME; 114 } 115 116 @Override 117 public String getEntityTypeName() { 118 return ShippingMethodDescriptionConstants.ENTITY_TYPE_NAME; 119 } 120 121 public PreparedStatement prepareStatement(String query) { 122 return ThreadSession.currentSession().prepareStatement(ShippingMethodDescriptionFactory.class, query); 123 } 124 125 public ShippingMethodDescriptionPK getNextPK() { 126 return new ShippingMethodDescriptionPK(entityIdGenerator.getNextEntityId()); 127 } 128 129 public Set<ShippingMethodDescriptionPK> getPKsFromResultSetAsSet(ResultSet rs) 130 throws PersistenceDatabaseException { 131 Set<ShippingMethodDescriptionPK> _result = new HashSet<>(); 132 133 try { 134 while(rs.next()) { 135 _result.add(getPKFromResultSet(rs)); 136 } 137 } catch (SQLException se) { 138 throw new PersistenceDatabaseException(se); 139 } 140 141 return _result; 142 } 143 144 public java.util.List<ShippingMethodDescriptionPK> getPKsFromResultSetAsList(ResultSet rs) 145 throws PersistenceDatabaseException { 146 java.util.List<ShippingMethodDescriptionPK> _result = new ArrayList<>(); 147 148 try { 149 while(rs.next()) { 150 _result.add(getPKFromResultSet(rs)); 151 } 152 } catch (SQLException se) { 153 throw new PersistenceDatabaseException(se); 154 } 155 156 return _result; 157 } 158 159 public ShippingMethodDescriptionPK getPKFromResultSet(ResultSet rs) 160 throws PersistenceDatabaseException { 161 ShippingMethodDescriptionPK _result; 162 163 try { 164 long shmd_shippingmethoddescriptionid = rs.getLong(SHMD_SHIPPINGMETHODDESCRIPTIONID); 165 Long _entityId = rs.wasNull() ? null : shmd_shippingmethoddescriptionid; 166 167 _result = new ShippingMethodDescriptionPK(_entityId); 168 } catch (SQLException se) { 169 throw new PersistenceDatabaseException(se); 170 } 171 172 return _result; 173 } 174 175 public java.util.List<ShippingMethodDescriptionValue> getValuesFromPKs(Session session, Collection<ShippingMethodDescriptionPK> pks) 176 throws PersistenceDatabaseException { 177 java.util.List<ShippingMethodDescriptionValue> _values = new ArrayList<>(pks.size()); 178 179 for(ShippingMethodDescriptionPK _pk: pks) { 180 _values.add(getValueFromPK(session, _pk)); 181 } 182 183 return _values; 184 } 185 186 public ShippingMethodDescriptionValue getValueFromPK(Session session, ShippingMethodDescriptionPK pk) 187 throws PersistenceDatabaseException { 188 ShippingMethodDescriptionValue _value; 189 190 // See if we already have the entity in the session cache 191 ShippingMethodDescription _entity = (ShippingMethodDescription)session.getEntity(pk); 192 if(_entity == null) 193 _value = getEntityFromPK(session, EntityPermission.READ_ONLY, pk).getShippingMethodDescriptionValue(); 194 else 195 _value = _entity.getShippingMethodDescriptionValue(); 196 197 return _value; 198 } 199 200 public java.util.List<ShippingMethodDescriptionValue> getValuesFromResultSet(Session session, ResultSet rs) 201 throws PersistenceDatabaseException { 202 java.util.List<ShippingMethodDescriptionValue> _result = new ArrayList<>(); 203 204 try { 205 while(rs.next()) { 206 _result.add(getValueFromResultSet(session, rs)); 207 } 208 } catch (SQLException se) { 209 throw new PersistenceDatabaseException(se); 210 } 211 212 return _result; 213 } 214 215 public ShippingMethodDescriptionValue getValueFromResultSet(Session session, ResultSet rs) 216 throws PersistenceDatabaseException { 217 ShippingMethodDescriptionValue _value; 218 219 try { 220 Long shmd_shippingmethoddescriptionid = rs.getLong(SHMD_SHIPPINGMETHODDESCRIPTIONID); 221 ShippingMethodDescriptionPK _pk = new ShippingMethodDescriptionPK(shmd_shippingmethoddescriptionid); 222 223 // See if we already have the entity in the session cache 224 ShippingMethodDescription _entity = (ShippingMethodDescription)session.getEntity(_pk); 225 226 if(_entity == null) { 227 Long shmd_shm_shippingmethodid = rs.getLong(SHMD_SHM_SHIPPINGMETHODID); 228 if(rs.wasNull()) 229 shmd_shm_shippingmethodid = null; 230 231 Long shmd_lang_languageid = rs.getLong(SHMD_LANG_LANGUAGEID); 232 if(rs.wasNull()) 233 shmd_lang_languageid = null; 234 235 String shmd_description = rs.getString(SHMD_DESCRIPTION); 236 if(rs.wasNull()) 237 shmd_description = null; 238 239 Long shmd_fromtime = rs.getLong(SHMD_FROMTIME); 240 if(rs.wasNull()) 241 shmd_fromtime = null; 242 243 Long shmd_thrutime = rs.getLong(SHMD_THRUTIME); 244 if(rs.wasNull()) 245 shmd_thrutime = null; 246 247 _value = new ShippingMethodDescriptionValue(_pk, new ShippingMethodPK(shmd_shm_shippingmethodid), new LanguagePK(shmd_lang_languageid), shmd_description, shmd_fromtime, shmd_thrutime); 248 } else 249 _value = _entity.getShippingMethodDescriptionValue(); 250 } catch (SQLException se) { 251 throw new PersistenceDatabaseException(se); 252 } 253 254 return _value; 255 } 256 257 public java.util.List<ShippingMethodDescription> getEntitiesFromPKs(EntityPermission entityPermission, Collection<ShippingMethodDescriptionPK> pks) 258 throws PersistenceDatabaseException { 259 return getEntitiesFromPKs(ThreadSession.currentSession(), entityPermission, pks); 260 } 261 262 public java.util.List<ShippingMethodDescription> getEntitiesFromPKs(Session session, EntityPermission entityPermission, Collection<ShippingMethodDescriptionPK> pks) 263 throws PersistenceDatabaseException { 264 java.util.List<ShippingMethodDescription> _entities = new ArrayList<>(pks.size()); 265 266 for(ShippingMethodDescriptionPK _pk: pks) { 267 _entities.add(getEntityFromPK(session, entityPermission, _pk)); 268 } 269 270 return _entities; 271 } 272 273 public ShippingMethodDescription getEntityFromValue(EntityPermission entityPermission, ShippingMethodDescriptionValue value) { 274 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, value.getPrimaryKey()); 275 } 276 277 public ShippingMethodDescription getEntityFromValue(Session session, EntityPermission entityPermission, ShippingMethodDescriptionValue value) { 278 return getEntityFromPK(session, entityPermission, value.getPrimaryKey()); 279 } 280 281 public ShippingMethodDescription getEntityFromPK(EntityPermission entityPermission, ShippingMethodDescriptionPK pk) 282 throws PersistenceDatabaseException { 283 return getEntityFromPK(ThreadSession.currentSession(), entityPermission, pk); 284 } 285 286 public ShippingMethodDescription getEntityFromCache(Session session, ShippingMethodDescriptionPK pk) { 287 ShippingMethodDescriptionValue _value = (ShippingMethodDescriptionValue)session.getValueCache().get(pk); 288 289 return _value == null ? null : new ShippingMethodDescription(_value, EntityPermission.READ_ONLY); 290 } 291 292 public ShippingMethodDescription getEntityFromPK(Session session, EntityPermission entityPermission, ShippingMethodDescriptionPK pk) 293 throws PersistenceDatabaseException { 294 ShippingMethodDescription _entity; 295 296 // See if we already have the entity in the session cache 297 _entity = (ShippingMethodDescription)session.getEntity(pk); 298 if(_entity != null) { 299 // If the requested permission is READ_WRITE, and the cached permission is 300 // READ_ONLY, then pretend that the cached object wasn't found, and create 301 // a new entity that is READ_WRITE. 302 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 303 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 304 _entity = null; 305 } 306 } 307 308 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 309 _entity = getEntityFromCache(session, pk); 310 } 311 312 if(_entity == null) { 313 PreparedStatement _ps = session.prepareStatement(entityPermission.equals(EntityPermission.READ_ONLY)? SQL_SELECT_READ_ONLY: SQL_SELECT_READ_WRITE); 314 long _entityId = pk.getEntityId(); 315 ResultSet _rs = null; 316 317 try { 318 _ps.setLong(1, _entityId); 319 _rs = _ps.executeQuery(); 320 if(_rs.next()) { 321 _entity = getEntityFromResultSet(session, entityPermission, _rs); 322 } 323 } catch (SQLException se) { 324 throw new PersistenceDatabaseException(se); 325 } finally { 326 if(_rs != null) { 327 try { 328 _rs.close(); 329 } catch (SQLException se) { 330 // do nothing 331 } 332 } 333 } 334 } 335 336 return _entity; 337 } 338 339 public Set<ShippingMethodDescriptionPK> getPKsFromQueryAsSet(PreparedStatement ps, final Object... params) 340 throws PersistenceDatabaseException { 341 Set<ShippingMethodDescriptionPK> _pks; 342 ResultSet _rs = null; 343 344 try { 345 if(params.length != 0) { 346 Session.setQueryParams(ps, params); 347 } 348 349 _rs = ps.executeQuery(); 350 _pks = getPKsFromResultSetAsSet(_rs); 351 _rs.close(); 352 } catch (SQLException se) { 353 throw new PersistenceDatabaseException(se); 354 } finally { 355 if(_rs != null) { 356 try { 357 _rs.close(); 358 } catch (SQLException se) { 359 // do nothing 360 } 361 } 362 } 363 364 return _pks; 365 } 366 367 public java.util.List<ShippingMethodDescriptionPK> getPKsFromQueryAsList(PreparedStatement ps, final Object... params) 368 throws PersistenceDatabaseException { 369 java.util.List<ShippingMethodDescriptionPK> _pks; 370 ResultSet _rs = null; 371 372 try { 373 if(params.length != 0) { 374 Session.setQueryParams(ps, params); 375 } 376 377 _rs = ps.executeQuery(); 378 _pks = getPKsFromResultSetAsList(_rs); 379 _rs.close(); 380 } catch (SQLException se) { 381 throw new PersistenceDatabaseException(se); 382 } finally { 383 if(_rs != null) { 384 try { 385 _rs.close(); 386 } catch (SQLException se) { 387 // do nothing 388 } 389 } 390 } 391 392 return _pks; 393 } 394 395 public ShippingMethodDescriptionPK getPKFromQuery(PreparedStatement ps, final Object... params) 396 throws PersistenceDatabaseException { 397 ShippingMethodDescriptionPK _pk = null; 398 ResultSet _rs = null; 399 400 try { 401 if(params.length != 0) { 402 Session.setQueryParams(ps, params); 403 } 404 405 _rs = ps.executeQuery(); 406 if(_rs.next()) { 407 _pk = getPKFromResultSet(_rs); 408 } 409 _rs.close(); 410 } catch (SQLException se) { 411 throw new PersistenceDatabaseException(se); 412 } finally { 413 if(_rs != null) { 414 try { 415 _rs.close(); 416 } catch (SQLException se) { 417 // do nothing 418 } 419 } 420 } 421 422 return _pk; 423 } 424 425 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 426 throws PersistenceDatabaseException { 427 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 428 429 return getEntitiesFromQuery(session, entityPermission, ps, params); 430 } 431 432 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 433 throws PersistenceDatabaseException { 434 Session session = ThreadSession.currentSession(); 435 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 436 437 return getEntitiesFromQuery(session, entityPermission, ps, params); 438 } 439 440 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 441 throws PersistenceDatabaseException { 442 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 443 444 return getEntitiesFromQuery(session, entityPermission, ps); 445 } 446 447 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 448 throws PersistenceDatabaseException { 449 Session session = ThreadSession.currentSession(); 450 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 451 452 return getEntitiesFromQuery(session, entityPermission, ps); 453 } 454 455 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps) 456 throws PersistenceDatabaseException { 457 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps); 458 } 459 460 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 461 throws PersistenceDatabaseException { 462 return getEntitiesFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 463 } 464 465 public java.util.List<ShippingMethodDescription> getEntitiesFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 466 throws PersistenceDatabaseException { 467 java.util.List<ShippingMethodDescription> _entities; 468 ResultSet _rs = null; 469 470 try { 471 if(params.length != 0) { 472 Session.setQueryParams(ps, params); 473 } 474 475 _rs = ps.executeQuery(); 476 _entities = getEntitiesFromResultSet(session, entityPermission, _rs); 477 _rs.close(); 478 } catch (SQLException se) { 479 throw new PersistenceDatabaseException(se); 480 } finally { 481 if(_rs != null) { 482 try { 483 _rs.close(); 484 } catch (SQLException se) { 485 // do nothing 486 } 487 } 488 } 489 490 return _entities; 491 } 492 493 public ShippingMethodDescription getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 494 throws PersistenceDatabaseException { 495 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 496 497 return getEntityFromQuery(session, entityPermission, ps, params); 498 } 499 500 public ShippingMethodDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap, final Object... params) 501 throws PersistenceDatabaseException { 502 Session session = ThreadSession.currentSession(); 503 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 504 505 return getEntityFromQuery(session, entityPermission, ps, params); 506 } 507 508 public ShippingMethodDescription getEntityFromQuery(Session session, EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 509 throws PersistenceDatabaseException { 510 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 511 512 return getEntityFromQuery(session, entityPermission, ps); 513 } 514 515 public ShippingMethodDescription getEntityFromQuery(EntityPermission entityPermission, Map<EntityPermission, String>queryMap) 516 throws PersistenceDatabaseException { 517 Session session = ThreadSession.currentSession(); 518 PreparedStatement ps = session.prepareStatement(ShippingMethodDescriptionFactory.class, queryMap.get(entityPermission)); 519 520 return getEntityFromQuery(session, entityPermission, ps); 521 } 522 523 public ShippingMethodDescription getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps) 524 throws PersistenceDatabaseException { 525 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps); 526 } 527 528 public ShippingMethodDescription getEntityFromQuery(EntityPermission entityPermission, PreparedStatement ps, final Object... params) 529 throws PersistenceDatabaseException { 530 return getEntityFromQuery(ThreadSession.currentSession(), entityPermission, ps, params); 531 } 532 533 public ShippingMethodDescription getEntityFromQuery(Session session, EntityPermission entityPermission, PreparedStatement ps, final Object... params) 534 throws PersistenceDatabaseException { 535 ShippingMethodDescription _entity = null; 536 ResultSet _rs = null; 537 538 try { 539 if(params.length != 0) { 540 Session.setQueryParams(ps, params); 541 } 542 543 _rs = ps.executeQuery(); 544 if(_rs.next()) { 545 _entity = getEntityFromResultSet(session, entityPermission, _rs); 546 } 547 _rs.close(); 548 } catch (SQLException se) { 549 throw new PersistenceDatabaseException(se); 550 } finally { 551 if(_rs != null) { 552 try { 553 _rs.close(); 554 } catch (SQLException se) { 555 // do nothing 556 } 557 } 558 } 559 560 return _entity; 561 } 562 563 public java.util.List<ShippingMethodDescription> getEntitiesFromResultSet(EntityPermission entityPermission, ResultSet rs) 564 throws PersistenceDatabaseException { 565 return getEntitiesFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 566 } 567 568 public java.util.List<ShippingMethodDescription> getEntitiesFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 569 throws PersistenceDatabaseException { 570 java.util.List<ShippingMethodDescription> _result = new ArrayList<>(); 571 572 try { 573 while(rs.next()) { 574 _result.add(getEntityFromResultSet(session, entityPermission, rs)); 575 } 576 } catch (SQLException se) { 577 throw new PersistenceDatabaseException(se); 578 } 579 580 return _result; 581 } 582 583 public ShippingMethodDescription getEntityFromResultSet(EntityPermission entityPermission, ResultSet rs) 584 throws PersistenceDatabaseException { 585 return getEntityFromResultSet(ThreadSession.currentSession(), entityPermission, rs); 586 } 587 588 public ShippingMethodDescription getEntityFromResultSet(Session session, EntityPermission entityPermission, ResultSet rs) 589 throws PersistenceDatabaseException { 590 ShippingMethodDescription _entity; 591 592 try { 593 Long shmd_shippingmethoddescriptionid = rs.getLong(SHMD_SHIPPINGMETHODDESCRIPTIONID); 594 ShippingMethodDescriptionPK _pk = new ShippingMethodDescriptionPK(shmd_shippingmethoddescriptionid); 595 596 // See if we already have the entity in the session cache 597 _entity = (ShippingMethodDescription)session.getEntity(_pk); 598 if(_entity != null) { 599 // If the requested permission is READ_WRITE, and the cached permission is 600 // READ_ONLY, then pretend that the cached object wasn't found, and create 601 // a new entity that is READ_WRITE. 602 if(entityPermission.equals(EntityPermission.READ_WRITE)) { 603 if(_entity.getEntityPermission().equals(EntityPermission.READ_ONLY)) 604 _entity = null; 605 } 606 } 607 boolean foundInSessionCache = _entity != null; 608 609 if(_entity == null && entityPermission.equals(EntityPermission.READ_ONLY)) { 610 _entity = getEntityFromCache(session, _pk); 611 } 612 613 if(_entity == null) { 614 Long shmd_shm_shippingmethodid = rs.getLong(SHMD_SHM_SHIPPINGMETHODID); 615 if(rs.wasNull()) 616 shmd_shm_shippingmethodid = null; 617 618 Long shmd_lang_languageid = rs.getLong(SHMD_LANG_LANGUAGEID); 619 if(rs.wasNull()) 620 shmd_lang_languageid = null; 621 622 String shmd_description = rs.getString(SHMD_DESCRIPTION); 623 if(rs.wasNull()) 624 shmd_description = null; 625 626 Long shmd_fromtime = rs.getLong(SHMD_FROMTIME); 627 if(rs.wasNull()) 628 shmd_fromtime = null; 629 630 Long shmd_thrutime = rs.getLong(SHMD_THRUTIME); 631 if(rs.wasNull()) 632 shmd_thrutime = null; 633 634 ShippingMethodDescriptionValue _value = new ShippingMethodDescriptionValue(_pk, shmd_shm_shippingmethodid == null? null: new ShippingMethodPK(shmd_shm_shippingmethodid), shmd_lang_languageid == null? null: new LanguagePK(shmd_lang_languageid), shmd_description, shmd_fromtime, shmd_thrutime); 635 _entity = new ShippingMethodDescription(_value, entityPermission); 636 } 637 638 if(!foundInSessionCache) { 639 if(entityPermission.equals(EntityPermission.READ_ONLY)) { 640 session.putReadOnlyEntity(_pk, _entity); 641 session.getValueCache().put(_entity.getShippingMethodDescriptionValue()); 642 } else { 643 session.putReadWriteEntity(_pk, _entity); 644 } 645 } 646 } catch (SQLException se) { 647 throw new PersistenceDatabaseException(se); 648 } 649 650 return _entity; 651 } 652 653 public ShippingMethodDescription create(Session session, ShippingMethod shippingMethod, Language language, String description, Long fromTime, Long thruTime) 654 throws PersistenceDatabaseException, PersistenceNotNullException { 655 return create(session, shippingMethod == null ? null : shippingMethod.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, fromTime, thruTime); 656 } 657 658 public ShippingMethodDescription create(ShippingMethod shippingMethod, Language language, String description, Long fromTime, Long thruTime) 659 throws PersistenceDatabaseException, PersistenceNotNullException { 660 return create(ThreadSession.currentSession(), shippingMethod == null ? null : shippingMethod.getPrimaryKey(), language == null ? null : language.getPrimaryKey(), description, fromTime, thruTime); 661 } 662 663 private void bindForCreate(PreparedStatement _ps, ShippingMethodDescriptionValue _value) 664 throws SQLException { 665 _ps.setLong(1, _value.getEntityId()); 666 667 ShippingMethodPK shmd_shm_shippingmethodid = _value.getShippingMethodPK(); 668 if(shmd_shm_shippingmethodid == null) 669 _ps.setNull(2, Types.BIGINT); 670 else 671 _ps.setLong(2, shmd_shm_shippingmethodid.getEntityId()); 672 673 LanguagePK shmd_lang_languageid = _value.getLanguagePK(); 674 if(shmd_lang_languageid == null) 675 _ps.setNull(3, Types.BIGINT); 676 else 677 _ps.setLong(3, shmd_lang_languageid.getEntityId()); 678 679 String shmd_description = _value.getDescription(); 680 if(shmd_description == null) 681 _ps.setNull(4, Types.VARCHAR); 682 else 683 _ps.setString(4, shmd_description); 684 685 Long shmd_fromtime = _value.getFromTime(); 686 if(shmd_fromtime == null) 687 _ps.setNull(5, Types.BIGINT); 688 else 689 _ps.setLong(5, shmd_fromtime); 690 691 Long shmd_thrutime = _value.getThruTime(); 692 if(shmd_thrutime == null) 693 _ps.setNull(6, Types.BIGINT); 694 else 695 _ps.setLong(6, shmd_thrutime); 696 697 } 698 699 public ShippingMethodDescription create(Session session, ShippingMethodPK shippingMethodPK, LanguagePK languagePK, String description, Long fromTime, Long thruTime) 700 throws PersistenceDatabaseException, PersistenceNotNullException { 701 ShippingMethodDescriptionPK _pk = getNextPK(); 702 ShippingMethodDescriptionValue _value = new ShippingMethodDescriptionValue(_pk, shippingMethodPK, languagePK, description, fromTime, thruTime); 703 704 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 705 706 try { 707 bindForCreate(_ps, _value); 708 709 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 710 int _count = _ps.executeUpdate(); 711 712 if(_count != 1) { 713 throw new PersistenceDatabaseUpdateException("insert failed, _count = " + _count); 714 } 715 } else { 716 _ps.executeUpdate(); 717 } 718 719 session.getValueCache().put(_value); 720 } catch (SQLException se) { 721 throw new PersistenceDatabaseException(se); 722 } 723 724 ShippingMethodDescription _entity = new ShippingMethodDescription(_value, EntityPermission.READ_ONLY); 725 session.putReadOnlyEntity(_pk, _entity); 726 727 return _entity; 728 } 729 730 public ShippingMethodDescription create(ShippingMethodPK shippingMethodPK, LanguagePK languagePK, String description, Long fromTime, Long thruTime) 731 throws PersistenceDatabaseException, PersistenceNotNullException { 732 return create(ThreadSession.currentSession(), shippingMethodPK, languagePK, description, fromTime, thruTime); 733 } 734 735 public void create(Session session, Collection<ShippingMethodDescriptionValue> _values) 736 throws PersistenceDatabaseException, PersistenceNotNullException { 737 int _size = _values.size(); 738 739 if(_size > 0) { 740 PreparedStatement _ps = session.prepareStatement(SQL_INSERT); 741 List<ShippingMethodDescriptionValue> _cacheValues = new ArrayList<>(_size); 742 743 try { 744 for(ShippingMethodDescriptionValue _value : _values) { 745 _value.setEntityId(entityIdGenerator.getNextEntityId()); 746 bindForCreate(_ps, _value); 747 748 _ps.addBatch(); 749 750 _cacheValues.add(_value); 751 } 752 753 if(PersistenceDebugFlags.CheckEntityInsertRowCount) { 754 int[] _counts = _ps.executeBatch(); 755 756 for(int _countOffset = 0 ; _countOffset < _size ; _countOffset++) { 757 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 758 throw new PersistenceDatabaseUpdateException("batch insert failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 759 } 760 } 761 } else { 762 _ps.executeBatch(); 763 } 764 765 _ps.clearBatch(); 766 } catch (SQLException se) { 767 throw new PersistenceDatabaseException(se); 768 } 769 770 _cacheValues.forEach((_cacheValue) -> { 771 ShippingMethodDescription _cacheEntity = new ShippingMethodDescription(_cacheValue, EntityPermission.READ_ONLY); 772 773 session.putReadOnlyEntity(_cacheValue.getPrimaryKey(), _cacheEntity); 774 }); 775 } 776 } 777 778 public void create(Collection<ShippingMethodDescriptionValue> _values) 779 throws PersistenceDatabaseException, PersistenceNotNullException { 780 create(ThreadSession.currentSession(), _values); 781 } 782 783 private boolean bindForStore(PreparedStatement _ps, ShippingMethodDescriptionValue _value) 784 throws SQLException { 785 boolean _hasBeenModified = _value.hasBeenModified(); 786 787 if(_hasBeenModified) { 788 ShippingMethodPK shmd_shm_shippingmethodid = _value.getShippingMethodPK(); 789 if(shmd_shm_shippingmethodid == null) 790 _ps.setNull(1, Types.BIGINT); 791 else 792 _ps.setLong(1, shmd_shm_shippingmethodid.getEntityId()); 793 794 LanguagePK shmd_lang_languageid = _value.getLanguagePK(); 795 if(shmd_lang_languageid == null) 796 _ps.setNull(2, Types.BIGINT); 797 else 798 _ps.setLong(2, shmd_lang_languageid.getEntityId()); 799 800 String shmd_description = _value.getDescription(); 801 if(shmd_description == null) 802 _ps.setNull(3, Types.VARCHAR); 803 else 804 _ps.setString(3, shmd_description); 805 806 Long shmd_fromtime = _value.getFromTime(); 807 if(shmd_fromtime == null) 808 _ps.setNull(4, Types.BIGINT); 809 else 810 _ps.setLong(4, shmd_fromtime); 811 812 Long shmd_thrutime = _value.getThruTime(); 813 if(shmd_thrutime == null) 814 _ps.setNull(5, Types.BIGINT); 815 else 816 _ps.setLong(5, shmd_thrutime); 817 818 _ps.setLong(6, _value.getPrimaryKey().getEntityId()); 819 820 _value.clearHasBeenModified(); 821 } 822 823 return _hasBeenModified; 824 } 825 826 @Override 827 public void store(Session session, ShippingMethodDescription entity) 828 throws PersistenceDatabaseException { 829 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 830 831 try { 832 ShippingMethodDescriptionValue _value = entity.getShippingMethodDescriptionValue(); 833 834 if(bindForStore(_ps, _value)) { 835 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 836 int _count = _ps.executeUpdate(); 837 838 if(_count != 1) { 839 throw new PersistenceDatabaseUpdateException("update failed, _count = " + _count); 840 } 841 } else { 842 _ps.executeUpdate(); 843 } 844 845 session.getValueCache().put(_value); 846 } 847 } catch (SQLException se) { 848 throw new PersistenceDatabaseException(se); 849 } 850 } 851 852 @Override 853 public void store(Session session, Collection<ShippingMethodDescription> entities) 854 throws PersistenceDatabaseException { 855 if(entities.size() > 0) { 856 PreparedStatement _ps = session.prepareStatement(SQL_UPDATE); 857 int _modifiedEntities = 0; 858 859 try { 860 for(ShippingMethodDescription entity : entities) { 861 if(bindForStore(_ps, entity.getShippingMethodDescriptionValue())) { 862 _ps.addBatch(); 863 _modifiedEntities++; 864 } 865 } 866 867 if(_modifiedEntities != 0) { 868 if(PersistenceDebugFlags.CheckEntityUpdateRowCount) { 869 int[] _counts = _ps.executeBatch(); 870 871 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 872 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 873 throw new PersistenceDatabaseUpdateException("batch update failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 874 } 875 } 876 } else { 877 _ps.executeBatch(); 878 } 879 880 _ps.clearBatch(); 881 882 entities.forEach((entity) -> { 883 session.getValueCache().put(entity.getShippingMethodDescriptionValue()); 884 }); 885 } 886 } catch (SQLException se) { 887 throw new PersistenceDatabaseException(se); 888 } 889 } 890 } 891 892 @Override 893 public void store(Collection<ShippingMethodDescription> entities) 894 throws PersistenceDatabaseException { 895 store(ThreadSession.currentSession(), entities); 896 } 897 898 @Override 899 public void remove(Session session, ShippingMethodDescription entity) 900 throws PersistenceDatabaseException { 901 remove(session, entity.getPrimaryKey()); 902 } 903 904 @Override 905 public void remove(Session session, ShippingMethodDescriptionPK pk) 906 throws PersistenceDatabaseException { 907 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 908 long _entityId = pk.getEntityId(); 909 910 try { 911 _ps.setLong(1, _entityId); 912 913 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 914 int _count = _ps.executeUpdate(); 915 916 if(_count != 1) { 917 throw new PersistenceDatabaseUpdateException("remove failed, _count = " + _count); 918 } 919 } else { 920 _ps.executeUpdate(); 921 } 922 923 session.getValueCache().remove(pk); 924 } catch (SQLException se) { 925 throw new PersistenceDatabaseException(se); 926 } 927 928 session.removed(pk, false); 929 } 930 931 @Override 932 public void remove(Session session, Collection<ShippingMethodDescriptionPK> pks) 933 throws PersistenceDatabaseException { 934 if(pks.size() > 0) { 935 PreparedStatement _ps = session.prepareStatement(SQL_DELETE); 936 int _modifiedEntities = 0; 937 938 try { 939 for(ShippingMethodDescriptionPK pk : pks) { 940 long _entityId = pk.getEntityId(); 941 942 _ps.setLong(1, _entityId); 943 944 _ps.addBatch(); 945 _modifiedEntities++; 946 } 947 948 if(_modifiedEntities != 0) { 949 if(PersistenceDebugFlags.CheckEntityDeleteRowCount) { 950 int[] _counts = _ps.executeBatch(); 951 952 for(int _countOffset = 0 ; _countOffset < _modifiedEntities ; _countOffset++) { 953 if(_counts[_countOffset] != 1 && _counts[_countOffset] != PreparedStatement.SUCCESS_NO_INFO) { 954 throw new PersistenceDatabaseUpdateException("batch remove failed, _counts[" + _countOffset + "] = " + _counts[_countOffset]); 955 } 956 } 957 } else { 958 _ps.executeBatch(); 959 } 960 961 _ps.clearBatch(); 962 963 pks.forEach((pk) -> { 964 session.getValueCache().remove(pk); 965 }); 966 } 967 } catch (SQLException se) { 968 throw new PersistenceDatabaseException(se); 969 } 970 971 pks.forEach((pk) -> { 972 session.removed(pk, true); 973 }); 974 } 975 } 976 977 @Override 978 public void remove(Collection<ShippingMethodDescriptionPK> pks) 979 throws PersistenceDatabaseException { 980 remove(ThreadSession.currentSession(), pks); 981 } 982 983 @Override 984 public boolean validPK(Session session, ShippingMethodDescriptionPK pk) 985 throws PersistenceDatabaseException { 986 boolean valid = false; 987 PreparedStatement _ps = session.prepareStatement(SQL_VALID); 988 ResultSet _rs = null; 989 990 try { 991 _ps.setLong(1, pk.getEntityId()); 992 993 _rs = _ps.executeQuery(); 994 if(_rs.next()) { 995 long _count = _rs.getLong(1); 996 if(_rs.wasNull()) 997 _count = 0; 998 999 if(_count == 1) 1000 valid = true; 1001 } 1002 } catch (SQLException se) { 1003 throw new PersistenceDatabaseException(se); 1004 } finally { 1005 if(_rs != null) { 1006 try { 1007 _rs.close(); 1008 } catch (SQLException se) { 1009 // do nothing 1010 } 1011 } 1012 } 1013 1014 return valid; 1015 } 1016 1017}