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