docs: @Override
      public void setUserLayout(
              final IPerson person,
              final IUserProfile profile,
              final Document layoutXML,
              final boolean channelsAdded) {
          final long startTime = System.currentTimeMillis();
          final int userId = person.getID();
          final int profileId = profile.getProfileId();
  
          // don't try to save null layouts.
          if (layoutXML == null) {
              logger.error(
                      "Invalid attempt to save NULL user layout for user "
                              + person.getUserName()
                              + ". Skipping!");
              return;
          }
  
          transactionOperations.execute(
                  status ->
                          jdbcOperations.execute(
                                  (ConnectionCallback<Object>)
                                          con -> {
                                              int layoutId;
                                              ResultSet rs;
  
                                              // Eventually we want to be able to just get layoutId
                                              // from
                                              // the
                                              // profile, but because of the template user layouts we
                                              // have
                                              // to do this for now ...
                                              layoutId = getLayoutID(userId, profileId);
  
                                              boolean firstLayout = false;
                                              if (layoutId == 0) {
                                                  // First personal layout for this user/profile
                                                  layoutId = 1;
                                                  firstLayout = true;
                                              }
  
                                              String sql =
                                                      "DELETE FROM UP_LAYOUT_PARAM WHERE USER_ID=? AND LAYOUT_ID=?";
                                              PreparedStatement pstmt = con.prepareStatement(sql);
                                              try {
                                                  pstmt.clearParameters();
                                                  pstmt.setInt(1, userId);
                                                  pstmt.setInt(2, layoutId);
                                                  logger.debug(sql);
                                                  pstmt.executeUpdate();
                                              } finally {
                                                  pstmt.close();
                                              }
  
                                              sql =
                                                      "DELETE FROM UP_LAYOUT_STRUCT WHERE USER_ID=? AND LAYOUT_ID=?";
                                              pstmt = con.prepareStatement(sql);
                                              try {
                                                  pstmt.clearParameters();
                                                  pstmt.setInt(1, userId);
                                                  pstmt.setInt(2, layoutId);
                                                  logger.debug(sql);
                                                  pstmt.executeUpdate();
                                              } finally {
                                                  pstmt.close();
                                              }
  
                                              int firstStructId;
                                              try (PreparedStatement structStmt =
                                                              con.prepareStatement(
                                                                      "INSERT INTO UP_LAYOUT_STRUCT "
                                                                              + "(USER_ID, LAYOUT_ID, STRUCT_ID, NEXT_STRUCT_ID, CHLD_STRUCT_ID,EXTERNAL_ID,CHAN_ID,NAME,TYPE,HIDDEN,IMMUTABLE,UNREMOVABLE) "
                                                                              + "VALUES ("
                                                                              + userId
                                                                              + ","
                                                                              + layoutId
                                                                              + ",?,?,?,?,?,?,?,?,?,?)");
                                                      PreparedStatement parmStmt =
                                                              con.prepareStatement(
                                                                      "INSERT INTO UP_LAYOUT_PARAM "
                                                                              + "(USER_ID, LAYOUT_ID, STRUCT_ID, STRUCT_PARM_NM, STRUCT_PARM_VAL) "
                                                                              + "VALUES ("
                                                                              + userId
                                                                              + ","
                                                                              + layoutId
                                                                              + ",?,?,?)")) {
                                                  firstStructId =
                                                          saveStructure(
                                                                  layoutXML
                                                                          .getFirstChild()
                                                                          .getFirstChild(),
                                                                  structStmt,
                                                                  parmStmt);
                                              }
  
                                              // Check to see if the user has a matching layout
                                              sql =
                                                      "SELECT * FROM UP_USER_LAYOUT WHERE USER_ID=? AND LAYOUT_ID=?";
                                              pstmt = con.prepareStatement(sql);
                                              try {
                                                  pstmt.clearParameters();
                                                  pstmt.setInt(1, userId);
                                                  pstmt.setInt(2, layoutId);
                                                  logger.debug(sql);
                                                  rs = pstmt.executeQuery();
  
                                                  try {
                                                      if (!rs.next()) {
                                                          /*
                                                           * In ancient times, uPortal had a notion of
                                                           * a "template user," and here we used to
                                                           * set up profiles based on the emplate
                                                           * user.  Now we use the 'system' user.
                                                           */
                                                          final int defaultUserId =
                                                                  getSystemUser().getID();
  
                                                          // Add to UP_USER_LAYOUT
                                                          sql =
                                                                  "SELECT USER_ID,LAYOUT_ID,LAYOUT_TITLE,INIT_STRUCT_ID FROM UP_USER_LAYOUT WHERE USER_ID=?";
                                                          try (PreparedStatement pstmt2 =
                                                                  con.prepareStatement(sql)) {
                                                              pstmt2.clearParameters();
                                                              pstmt2.setInt(1, defaultUserId);
                                                              logger.debug(sql);
                                                              try (ResultSet rs2 =
                                                                      pstmt2.executeQuery()) {
                                                                  if (rs2.next()) {
                                                                      // There is a row for this
                                                                      // user's
                                                                      // template user...
                                                                      sql =
                                                                              "INSERT INTO UP_USER_LAYOUT (USER_ID, LAYOUT_ID, LAYOUT_TITLE, INIT_STRUCT_ID) VALUES (?,?,?,?)";
                                                                      try (PreparedStatement pstmt3 =
                                                                              con.prepareStatement(
                                                                                      sql)) {
                                                                          pstmt3.clearParameters();
                                                                          pstmt3.setInt(1, userId);
                                                                          pstmt3.setInt(
                                                                                  2,
                                                                                  rs2.getInt(
                                                                                          "LAYOUT_ID"));
                                                                          pstmt3.setString(
                                                                                  3,
                                                                                  rs2.getString(
                                                                                          "LAYOUT_TITLE"));
                                                                          pstmt3.setInt(
                                                                                  4,
                                                                                  rs2.getInt(
                                                                                          "INIT_STRUCT_ID"));
                                                                          logger.debug(sql);
                                                                          pstmt3.executeUpdate();
                                                                      }
                                                                  } else {
                                                                      // We can't rely on the template
                                                                      // user, but we still need a
                                                                      // row...
                                                                      sql =
                                                                              "INSERT INTO UP_USER_LAYOUT (USER_ID, LAYOUT_ID, LAYOUT_TITLE, INIT_STRUCT_ID) VALUES (?,?,?,?)";
                                                                      try (PreparedStatement pstmt3 =
                                                                              con.prepareStatement(
                                                                                      sql)) {
                                                                          pstmt3.clearParameters();
                                                                          pstmt3.setInt(1, userId);
                                                                          pstmt3.setInt(2, layoutId);
                                                                          pstmt3.setString(
                                                                                  3,
                                                                                  "default layout");
                                                                          pstmt3.setInt(4, 1);
                                                                          logger.debug(sql);
                                                                          pstmt3.executeUpdate();
                                                                      }
                                                                  }
                                                              }
                                                          }
                                                      }
                                                  } finally {
                                                      rs.close();
                                                  }
                                              } finally {
                                                  pstmt.close();
                                              }
  
                                              // Update the users layout with the correct inital
                                              // structure
                                              // ID
                                              sql =
                                                      "UPDATE UP_USER_LAYOUT SET INIT_STRUCT_ID=? WHERE USER_ID=? AND LAYOUT_ID=?";
                                              pstmt = con.prepareStatement(sql);
                                              try {
                                                  pstmt.clearParameters();
                                                  pstmt.setInt(1, firstStructId);
                                                  pstmt.setInt(2, userId);
                                                  pstmt.setInt(3, layoutId);
                                                  logger.debug(sql);
                                                  pstmt.executeUpdate();
                                              } finally {
                                                  pstmt.close();
                                              }
  
                                              // Update the last time the user saw the list of
                                              // available
                                              // channels
                                              if (channelsAdded) {
                                                  sql =
                                                          "UPDATE UP_USER SET LST_CHAN_UPDT_DT=? WHERE USER_ID=?";
                                                  pstmt = con.prepareStatement(sql);
                                                  try {
                                                      pstmt.clearParameters();
                                                      pstmt.setDate(
                                                              1,
                                                              new Date(System.currentTimeMillis()));
                                                      pstmt.setInt(2, userId);
                                                      logger.debug(sql);
                                                      pstmt.executeUpdate();
                                                  } finally {
                                                      pstmt.close();
                                                  }
                                              }
  
                                              if (firstLayout) {
                                                  sql =
                                                          "UPDATE UP_USER_PROFILE SET LAYOUT_ID=1 WHERE USER_ID=? AND PROFILE_ID=?";
                                                  pstmt = con.prepareStatement(sql);
                                                  try {
                                                      pstmt.clearParameters();
                                                      pstmt.setInt(1, userId);
                                                      pstmt.setInt(2, profileId);
                                                      logger.debug(sql);
                                                      pstmt.executeUpdate();
                                                  } finally {
                                                      pstmt.close();
                                                  }
                                              }
  
                                              return null;
                                          }));
          if (logger.isDebugEnabled()) {
              long stopTime = System.currentTimeMillis();
              long timeTook = stopTime - startTime;
              logger.debug(
                      "setUserLayout(): Layout document for user {} took {} milliseconds to save",
                      userId,
                      timeTook);
          }
      }