Exemplo n.º 1
0
 private void setHistObj(final JerHistObj jho) {
   if (jho == null) {
     jerInfoMsgHandler.showMsg(JerResourceBundleAccessor.get("mainModel_noHistObj"));
   } else {
     setModelAndIDAndNotify(jho.getModel(), jho.getId());
   }
 }
Exemplo n.º 2
0
 public void setModelAndIDAndNotify(final JerModel jm, final int selID) {
   selectedModel = jm;
   selectedID = selID;
   setChanged();
   notifyObservers(new JerObserverMsg(JerMsgType.SELECTION));
   jerInfoMsgHandler.setMsgBoxToNormal();
 }
Exemplo n.º 3
0
 private List<Object> readDB(final String sql) {
   final List<Object> columnList = new ArrayList<>();
   try {
     conn.setAutoCommit(false);
     try (PreparedStatement stmt = conn.prepareStatement(sql);
         ResultSet rs = stmt.executeQuery()) {
       while (rs.next()) {
         final int columnCount = rs.getMetaData().getColumnCount();
         final List<Object> rowList = new ArrayList<>(columnCount);
         for (int i = 1; i <= columnCount; i++) {
           rowList.add(rs.getObject(i));
         }
         columnList.add(rowList);
       }
       conn.commit();
     } catch (final SQLException e) {
       conn.rollback();
       throw e;
     } finally {
       conn.setAutoCommit(true);
     }
   } catch (final SQLException e1) {
     jerInfoMsgHandler.showMsg(e1.getLocalizedMessage());
   }
   return columnList;
 }
Exemplo n.º 4
0
 private void writeDB(
     final JerModel jerModel,
     final boolean isInsert,
     final boolean isUpdate,
     final boolean isDelete) {
   try {
     try {
       conn.setAutoCommit(false);
       if (isInsert) {
         try (PreparedStatement psJm = jerModel.getPreparer().createInsertStmt(conn)) {
           psJm.executeUpdate();
         }
         conn.commit();
         for (final PreparedStatement stmt :
             jerModel
                 .getPreparer()
                 .getPrepStmtsFromMultiFields(conn, getMaxIDValueForTable(jerModel))) {
           try (PreparedStatement psJm = stmt) {
             psJm.executeUpdate();
           }
         }
       } else if (isUpdate) {
         for (final PreparedStatement stmt : jerModel.getPreparer().createUpdateStmts(conn)) {
           try (PreparedStatement psJm = stmt) {
             psJm.executeUpdate();
           }
         }
       } else if (isDelete) {
         for (final PreparedStatement stmt : jerModel.getPreparer().createDelStmts(conn)) {
           try (PreparedStatement psJm = stmt) {
             psJm.executeUpdate();
           }
         }
       }
       conn.commit();
       setChanged();
       notifyObservers(new JerObserverMsg(JerMsgType.DB_UPDATE));
     } catch (SQLException | NumberFormatException nfe) {
       conn.rollback();
       conn.setAutoCommit(true);
       throw nfe;
     } finally {
       conn.setAutoCommit(true);
     }
   } catch (final SQLException e1) {
     LOGGER.severe(e1.getMessage());
     setModelAndID(jerModel, -1);
     jerInfoMsgHandler.showMsg("@" + jerModel.getIdName() + ": " + e1.getLocalizedMessage());
   }
 }