Class ExportQueueDAO
java.lang.Object
ru.bgcrm.dao.CommonDAO
org.bgerp.plugin.inventoru.sync1c.dao.ExportQueueDAO
DAO for
ExportQueue (inventoru_sync1c_export_queue table).-
Nested Class Summary
Nested classes/interfaces inherited from class CommonDAO
CommonDAO.ObjectExtractor<T>, CommonDAO.RecordUpdater<T> -
Field Summary
Fields inherited from class CommonDAO
con, log, SQL_AND, SQL_DELETE, SQL_DELETE_FROM, SQL_DESC, SQL_DISTINCT, SQL_FROM, SQL_GROUP_BY, SQL_INNER_JOIN, SQL_INSERT_IGNORE_INTO, SQL_INSERT_INTO, SQL_LEFT_JOIN, SQL_LIMIT, SQL_ON_DUP_KEY_UPDATE, SQL_ORDER_BY, SQL_REPLACE, SQL_SELECT, SQL_SELECT_ALL_FROM, SQL_SELECT_COUNT_ROWS, SQL_SET, SQL_UNION_ALL, SQL_UPDATE, SQL_VALUES, SQL_VALUES_1, SQL_VALUES_2, SQL_VALUES_3, SQL_VALUES_4, SQL_VALUES_5, SQL_WHERE -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidInserts or resets a pending queue entry for the given process/instance/store combination.booleanaddSuccess(int processId, int instanceId, String warehouseId, int storeId) Inserts (or resets) a queue entry directly in 'success' status — nothing is sent anywhere.voidcancelPendingByProcessId(int processId) Cancels a still-pending queue entry for the given process, so ExportPoller won't pick it up.voiddelete(int id) booleanfinalizePendingStatus(int id, String status, int attempts, String error) Finalizes the outcome of processing a pending entry (success/failed), but only if it's still pending.static ExportQueueget(int id) getListByInstance(int instanceId) Returns queue entries for a given instance (latest 100, newest first).getPendingByInstance(int instanceId) 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).getPendingByProtocol(int maxAttempts, String protocol) Returns pending queue entries with attempts less than maxAttempts, restricted to instances using the given protocol.booleanhasSuccessExport(int processId) Returns true if the process has at least one successfully sent write-off export.booleanisPending(int id) Returns true if the entry is still pending.voidmarkReversed(int processId) Marks successfully sent entries for the process as reversed, sohasSuccessExport(int)stops locking materials editing.voidupdateStatus(int id, String status, int attempts, String error) Updates status, attempts count and error text for a queue entry.voidupdateWarehouseId(int id, String warehouseId) 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.Methods inherited from class CommonDAO
deleteById, foundRows, getById, getGroupedIds, getGroupedIds, getIds, getIds, getPageLimit, getPeriodSql, lastInsertId, setPeriodParamValue, setRecordCount, update, updateColumn, updateIds, updateIds, updateOrInsert
-
Constructor Details
-
ExportQueueDAO
-
-
Method Details
-
add
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 sohasSuccessExport(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 asfinalizePendingStatus(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
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
- Throws:
SQLException
-
getPendingByInstance
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
Returns pending queue entries with attempts less than maxAttempts, restricted to instances using the given protocol. Used byExportPollerso it only auto-sends for HS-protocol instances — File-protocol instances are confirmed manually instead.- Throws:
SQLException
-
updateStatus
Updates status, attempts count and error text for a queue entry.- Throws:
SQLException
-
isPending
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
Returns queue entries for a given instance (latest 100, newest first).- Throws:
SQLException
-
hasSuccessExport
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
Marks successfully sent entries for the process as reversed, sohasSuccessExport(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 (seeExportService.reverseWriteoffMovements(int)), and 1C-side reconciliation is out of ERP's scope. Does NOT commit — caller is responsible.- Throws:
SQLException
-
cancelPendingByProcessId
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
- Throws:
SQLException
-
fromRs
- Throws:
SQLException
-