Class DeviceDAO

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

public class DeviceDAO extends CommonDAO
DAO for Device. Soft delete via deleted_at / deleted_by.
  • Constructor Details

  • Method Details

    • getList

      public List<Device> getList(boolean includeDeleted) throws SQLException
      Throws:
      SQLException
    • getList

      public List<Device> getList(boolean includeDeleted, int equipTypeId) throws SQLException
      Parameters:
      equipTypeId - filters by exact equipment type id; 0 = no filter (all types)
      Throws:
      SQLException
    • getListByStatus

      public List<Device> getListByStatus(String status) throws SQLException
      Throws:
      SQLException
    • getListByParent

      public List<Device> getListByParent(int parentDeviceId) throws SQLException
      Throws:
      SQLException
    • get

      public Device get(int id) throws SQLException
      Throws:
      SQLException
    • getListByStore

      public List<Device> getListByStore(int storeId) throws SQLException
      The units standing on a warehouse — every one of them, whether or not it is tied to a position of the nomenclature. The card used to show units only as serial numbers under a stock row (getSerialsByStore(int)), which needs item_id filled in and the position tracked per unit. Equipment imported without a position is invisible that way: a warehouse holding 63 units of an installer reported "warehouse is empty".
      Throws:
      SQLException
    • getSerialsByStore

      public Map<Integer, List<String>> getSerialsByStore(int storeId) throws SQLException
      Serial numbers standing on a store, grouped by nomenclature — what the store card shows under a serial-tracked position instead of just a number.
      Throws:
      SQLException
    • getBySerial

      public Device getBySerial(String serialNumber) throws SQLException
      Throws:
      SQLException
    • getBySerialLocked

      public Device getBySerialLocked(String serialNumber) throws SQLException
      The unit with this serial, read under a lock the transaction holds until it ends. A plain read decides "no such unit — create one" from a snapshot, and two imports running at the same second both decide it: a file applied twice by a double click made 158 cards out of 79 serial numbers, because neither request saw what the other was inserting. What the lock changes depends on when the second request arrives. Started after the first has committed, it reads the current row and updates the unit instead of creating a twin. Started at the same moment, on a serial that exists nowhere yet, both take a gap lock — those do not conflict with each other — and collide on the insert, where the database throws one of them away whole. Either way no duplicate survives; the caller turns that refusal into an answer a person can act on.
      Throws:
      SQLException
    • update

      public void update(Device d, int userId) throws SQLException
      Inserts or updates a device. Sets id on the object when inserting.
      Throws:
      SQLException
    • update

      public void update(Device d, int userId, boolean logChange) throws SQLException
      Parameters:
      logChange - false for an intermediate write whose outcome is logged later with logChange(Device, Device, int) — a unit saved off-store for a moment before a receipt puts it on one must not show "store: 0" as its history
      Throws:
      SQLException
    • logChange

      public void logChange(Device after, Device before, int userId)
      Logs a change whose writes happened in several steps: before as the unit was (null — created), after as it ended up.
    • delete

      public void delete(int id, int userId) throws SQLException
      Soft-delete.
      Throws:
      SQLException
    • restore

      public void restore(int id) throws SQLException
      Restore soft-deleted device.
      Throws:
      SQLException
    • fromRs

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