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