Class ExportQueueDAO

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

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

    • ExportQueueDAO

      public ExportQueueDAO(Connection con)
  • Method Details

    • add

      public void add(int processId, int instanceId, String warehouseId, int storeId) throws SQLException
      Inserts or resets a pending queue entry for the given process/instance/store combination. 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
    • addSuccess

      public boolean addSuccess(int processId, int instanceId, String warehouseId, int storeId) throws SQLException
      Inserts (or resets) a queue entry directly in 'success' status — nothing is sent anywhere. Used for OData connectors, where the write-off is local-only (the protocol has no push channel to 1C): the 'success' row must still exist so hasSuccessExport(int) keeps locking materials editing and the reversal path in Sync1cExportListener works exactly as for the HS/File protocols. Two statements instead of one upsert: the claiming UPDATE is a locking (current) read, so a concurrent duplicate call blocks on the row lock, then sees status='success' and gets 0 affected rows — regardless of the transaction's REPEATABLE READ snapshot, which a SELECT-based check could be fooled by (same race class as finalizePendingStatus(int, String, int, String)).
      Returns:
      true if this call claimed the transition to 'success' — the caller must create the local writeoff movements ONLY then; false = another request already did it.
      Throws:
      SQLException
    • updateWarehouseId

      public void updateWarehouseId(int id, String warehouseId) throws SQLException
      Stores the identifier that actually went to 1C — it is resolved at send time from the store's parameter, and keeping it here makes the queue screen and the CSV export show what was sent rather than what the mapping happened to hold when the entry was created.
      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