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