Class ExportQueueDAO

java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.plugin.inventory.sync1c.dao.ExportQueueDAO

public class ExportQueueDAO extends CommonDAO
DAO for ExportQueue (inventory_sync1c_export_queue table).
  • Constructor Details

    • ExportQueueDAO

      public ExportQueueDAO(Connection con)
  • Method Details

    • add

      public void add(int processId, int instanceId, String warehouseId) throws SQLException
      Inserts or resets a pending queue entry for the given process/instance pair. If a record already exists (from a previous export), it is reset to pending so the process can be re-exported after status is reverted and re-applied.
      Throws:
      SQLException
    • get

      public ExportQueue get(int id) throws SQLException
      Throws:
      SQLException
    • getPendingByInstance

      public List<ExportQueue> getPendingByInstance(int instanceId) throws SQLException
      Returns all pending queue entries for one instance, regardless of attempts — used by the File-protocol CSV export, which has no attempts/retry concept (there's no HTTP call to fail).
      Throws:
      SQLException
    • getPendingByProtocol

      public List<ExportQueue> getPendingByProtocol(int maxAttempts, String protocol) throws SQLException
      Returns pending queue entries with attempts less than maxAttempts, restricted to instances using the given protocol. Used by ExportPoller so it only auto-sends for HS-protocol instances — File-protocol instances are confirmed manually instead.
      Throws:
      SQLException
    • updateStatus

      public void updateStatus(int id, String status, int attempts, String error) throws SQLException
      Updates status, attempts count and error text for a queue entry.
      Throws:
      SQLException
    • isPending

      public boolean isPending(int id) throws SQLException
      Returns true if the entry is still pending. Used by ExportPoller right before sending to 1C, to catch a concurrent cancellation (process moved for rework) that happened after the poller took its initial snapshot of pending entries.
      Throws:
      SQLException
    • finalizePendingStatus

      public boolean finalizePendingStatus(int id, String status, int attempts, String error) throws SQLException
      Finalizes the outcome of processing a pending entry (success/failed), but only if it's still pending. If a concurrent cancellation flipped it to 'cancelled' in the meantime, this is a no-op — the cancellation wins and doesn't get silently overwritten back to success/failed.
      Returns:
      true if this call actually claimed the row (it was still 'pending'), false if a concurrent request already moved it elsewhere first — callers doing balance-affecting work (e.g. creating writeoff movements) must skip that work when this returns false, otherwise two racing callers can both act on the same entry before either commits.
      Throws:
      SQLException
    • getListByInstance

      public List<ExportQueue> getListByInstance(int instanceId) throws SQLException
      Returns queue entries for a given instance (latest 100, newest first).
      Throws:
      SQLException
    • hasSuccessExport

      public boolean hasSuccessExport(int processId) throws SQLException
      Returns true if the process has at least one successfully sent write-off export. Used to lock materials editing regardless of the process's current status — status alone isn't reliable once a process is moved back after export.
      Throws:
      SQLException
    • markReversed

      public void markReversed(int processId) throws SQLException
      Marks successfully sent entries for the process as reversed, so hasSuccessExport(int) stops locking materials editing. Used when a process is moved back out of the write-off status after the export already succeeded — the write-off is reversed in ERP (see ExportService.reverseWriteoffMovements(int)), and 1C-side reconciliation is out of ERP's scope. Does NOT commit — caller is responsible.
      Throws:
      SQLException
    • cancelPendingByProcessId

      public void cancelPendingByProcessId(int processId) throws SQLException
      Cancels a still-pending queue entry for the given process, so ExportPoller won't pick it up. Used when a process is returned for rework before the write-off was actually sent to 1C. A new entry is added on the next transition into the write-off status. Does NOT commit — caller is responsible.
      Throws:
      SQLException
    • delete

      public void delete(int id) throws SQLException
      Throws:
      SQLException
    • fromRs

      public static ExportQueue fromRs(ResultSet rs) throws SQLException
      Throws:
      SQLException