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