code: public void insertOrUpdate(Token token) {
          EntityManager entityManager = getEntityManager();
          EntityTransaction entityTransaction = null;
  
          try {
              entityTransaction = entityManager.getTransaction();
              entityTransaction.begin();
  			if (token.getId() == null) {
  				entityManager.persist(token);
  			} else {
  				entityManager.merge(token);
  			}
              entityTransaction.commit();
          } catch (Exception e) {
              if (entityTransaction != null && entityTransaction.isActive()) {
                  entityTransaction.rollback();
              }
              throw e;
          } finally {
  			entityManager.close();
  		}
  	}
docs: insertOrUpdate
  
  @param token