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