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