org.opensubsystems.inventory.persist.db
Class UnitDatabaseFactory

java.lang.Object
  extended by org.opensubsystems.core.persist.db.DatabaseFactoryImpl
      extended by org.opensubsystems.patterns.listdata.persist.db.impl.ListDatabaseFactoryImpl
          extended by org.opensubsystems.inventory.persist.db.UnitDatabaseFactory
All Implemented Interfaces:
org.opensubsystems.core.persist.BasicDataFactory, org.opensubsystems.core.persist.DataFactory, org.opensubsystems.core.persist.db.BasicDatabaseFactory, org.opensubsystems.core.persist.db.DatabaseFactory, org.opensubsystems.core.persist.db.ModifiableDatabaseFactory, org.opensubsystems.core.persist.ModifiableDataFactory, UnitFactory, org.opensubsystems.patterns.listdata.persist.db.ListDatabaseFactory, org.opensubsystems.patterns.listdata.persist.ListFactory

public class UnitDatabaseFactory
extends org.opensubsystems.patterns.listdata.persist.db.impl.ListDatabaseFactoryImpl
implements UnitFactory, org.opensubsystems.core.persist.db.ModifiableDatabaseFactory

Data factory to retrieve and manipulate units in persistence store.

Version:
$Id: UnitDatabaseFactory.java,v 1.16 2007/01/28 06:54:43 bastafidli Exp $
Author:
Martin Cerba
Code reviewer:
Miro Halas
Code reviewed:
1.13 2006/08/11 00:29:37 jlegeny

Field Summary
protected  UnitDatabaseSchema m_schema
          Schema to use to execute database dependent operations.
 
Fields inherited from class org.opensubsystems.patterns.listdata.persist.db.impl.ListDatabaseFactoryImpl
m_arrOrderColumnCodes, m_arrOrderDirections, m_arrShowColumnCodes, m_listSchema
 
Fields inherited from class org.opensubsystems.core.persist.db.DatabaseFactoryImpl
m_connectionFactory, m_iConcurrencySelectListResultSet, m_iDataType, m_iTypeSelectListResultSet, m_transactionFactory
 
Constructor Summary
UnitDatabaseFactory()
          Default constructor.
 
Method Summary
 boolean changeAvailableCount(int iUnitId, int iValue)
          Change the available count for specified unit by specified relative value.
 boolean changeAvailableCount(java.util.List lstChanges)
          Change the available count for specified unit by specified relative values.
protected  int changeAvailableCount(java.sql.PreparedStatement updateStatement, int iUnitId, int iValue)
          Change the available count for specified units by specified relative values.
 boolean changeShippedAndAvailableCount(int iUnitId, int iValue)
          Change the shipped and available count for specified unit by specified relative value.
protected  int changeShippedAndAvailableCount(java.sql.PreparedStatement updateStatement, int iUnitId, int iValue, boolean isSecure)
          Change the shipped and available count for specified units by specified relative values.
 boolean changeShippedAndAvailableCountSecure(int iUnitId, int iValue)
          Change the shipped and available count for specified unit by specified relative value.
 int create(java.util.Collection colDataObject)
          
 org.opensubsystems.core.data.DataObject create(org.opensubsystems.core.data.DataObject data)
          
 void delete(int iId, int iDomainId)
          
 Unit get(int iItemId, double dCost)
          Get unit based on the item it belongs to and cost of this unit.
 org.opensubsystems.core.data.DataObject get(int iId, int iDomainId)
          
 java.util.List getAvailableItems(int iItemId)
          This method returnd ids of all units for specified item which are available (that is the available count > 0)
 java.util.List getExceptFoundHolder(int iItemId)
          Get all units for specified item except the "found holder" (if any exists).
 Unit getFoundHolderItem(int iItemId)
          Get unit which is marked as "found holder".
 org.opensubsystems.core.data.DataObject load(java.sql.ResultSet rsQueryResults, int initialIndex)
          
 org.opensubsystems.core.data.DataObject load(java.sql.ResultSet rsQueryResults, int[] selectedColumns, int initialIndex)
          
 int resetCounts(int iInventoryId)
          Reset all counts of all items in the inventory to 0.
 int save(java.util.Collection colUnits)
          Update collection of Units
 org.opensubsystems.core.data.ModifiableDataObject save(org.opensubsystems.core.data.ModifiableDataObject data)
          
 int setValuesForInsert(java.sql.PreparedStatement insertStatement, org.opensubsystems.core.data.DataObject data, int iIndex)
          
 int setValuesForUpdate(java.sql.PreparedStatement updateStatement, org.opensubsystems.core.data.DataObject data, int iIndex)
          
 
Methods inherited from class org.opensubsystems.patterns.listdata.persist.db.impl.ListDatabaseFactoryImpl
get, getDefaultListDefinition, getListDatabaseSchema
 
Methods inherited from class org.opensubsystems.core.persist.db.DatabaseFactoryImpl
getConcurrencySelectListResultSet, getDataType, getTypeSelectListResultSet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.opensubsystems.core.persist.DataFactory
getDataType
 
Methods inherited from interface org.opensubsystems.patterns.listdata.persist.ListFactory
get, getDefaultListDefinition
 

Field Detail

m_schema

protected UnitDatabaseSchema m_schema
Schema to use to execute database dependent operations.

Constructor Detail

UnitDatabaseFactory

public UnitDatabaseFactory()
                    throws org.opensubsystems.core.error.OSSException
Default constructor.

Throws:
org.opensubsystems.core.error.OSSException - - an error has occured
Method Detail

load

public org.opensubsystems.core.data.DataObject load(java.sql.ResultSet rsQueryResults,
                                                    int[] selectedColumns,
                                                    int initialIndex)
                                             throws org.opensubsystems.core.error.OSSDatabaseAccessException

Specified by:
load in interface org.opensubsystems.patterns.listdata.persist.db.ListDatabaseFactory
Throws:
org.opensubsystems.core.error.OSSDatabaseAccessException

setValuesForInsert

public int setValuesForInsert(java.sql.PreparedStatement insertStatement,
                              org.opensubsystems.core.data.DataObject data,
                              int iIndex)
                       throws org.opensubsystems.core.error.OSSException,
                              java.sql.SQLException

Specified by:
setValuesForInsert in interface org.opensubsystems.core.persist.db.BasicDatabaseFactory
Throws:
org.opensubsystems.core.error.OSSException
java.sql.SQLException

setValuesForUpdate

public int setValuesForUpdate(java.sql.PreparedStatement updateStatement,
                              org.opensubsystems.core.data.DataObject data,
                              int iIndex)
                       throws org.opensubsystems.core.error.OSSException,
                              java.sql.SQLException

Specified by:
setValuesForUpdate in interface org.opensubsystems.core.persist.db.ModifiableDatabaseFactory
Throws:
org.opensubsystems.core.error.OSSException
java.sql.SQLException

get

public org.opensubsystems.core.data.DataObject get(int iId,
                                                   int iDomainId)
                                            throws org.opensubsystems.core.error.OSSException

Specified by:
get in interface org.opensubsystems.core.persist.DataFactory
Throws:
org.opensubsystems.core.error.OSSException

load

public org.opensubsystems.core.data.DataObject load(java.sql.ResultSet rsQueryResults,
                                                    int initialIndex)
                                             throws org.opensubsystems.core.error.OSSDatabaseAccessException

Specified by:
load in interface org.opensubsystems.core.persist.db.DatabaseFactory
Throws:
org.opensubsystems.core.error.OSSDatabaseAccessException

create

public org.opensubsystems.core.data.DataObject create(org.opensubsystems.core.data.DataObject data)
                                               throws org.opensubsystems.core.error.OSSException

Specified by:
create in interface org.opensubsystems.core.persist.BasicDataFactory
Throws:
org.opensubsystems.core.error.OSSException

create

public int create(java.util.Collection colDataObject)
           throws org.opensubsystems.core.error.OSSException

Specified by:
create in interface org.opensubsystems.core.persist.BasicDataFactory
Throws:
org.opensubsystems.core.error.OSSException

delete

public void delete(int iId,
                   int iDomainId)
            throws org.opensubsystems.core.error.OSSException

Specified by:
delete in interface org.opensubsystems.core.persist.BasicDataFactory
Throws:
org.opensubsystems.core.error.OSSException

save

public org.opensubsystems.core.data.ModifiableDataObject save(org.opensubsystems.core.data.ModifiableDataObject data)
                                                       throws org.opensubsystems.core.error.OSSException

Specified by:
save in interface org.opensubsystems.core.persist.ModifiableDataFactory
Throws:
org.opensubsystems.core.error.OSSException

save

public int save(java.util.Collection colUnits)
         throws org.opensubsystems.core.error.OSSException
Update collection of Units

Specified by:
save in interface UnitFactory
Parameters:
colUnits - - collection of units that have to be updated
Returns:
int - number of updated records
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

get

public Unit get(int iItemId,
                double dCost)
         throws org.opensubsystems.core.error.OSSException
Get unit based on the item it belongs to and cost of this unit. TODO: For Miro: Here we have assumption that units are unique for a given item based on their cost. I am not sure what was the original design thought. Review this.

Specified by:
get in interface UnitFactory
Parameters:
iItemId - - id of item to get unit for
dCost - - cost of unit to get
Returns:
Unit - specified Unit or null if not found.
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getFoundHolderItem

public Unit getFoundHolderItem(int iItemId)
                        throws org.opensubsystems.core.error.OSSException
Get unit which is marked as "found holder". Found holder is used to track information such as counts for all found items that is items we cannot otherwise decide what unit they belong to. There can be only one such item per item.

Specified by:
getFoundHolderItem in interface UnitFactory
Parameters:
iItemId - - id of item to get found holder unit for
Returns:
Unit - specified Unit or null if not found.
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getAvailableItems

public java.util.List getAvailableItems(int iItemId)
                                 throws org.opensubsystems.core.error.OSSException
This method returnd ids of all units for specified item which are available (that is the available count > 0)

Specified by:
getAvailableItems in interface UnitFactory
Parameters:
iItemId - - item id to get the units for
Returns:
List - list of Unit objects
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

getExceptFoundHolder

public java.util.List getExceptFoundHolder(int iItemId)
                                    throws org.opensubsystems.core.error.OSSException
Get all units for specified item except the "found holder" (if any exists).

Specified by:
getExceptFoundHolder in interface UnitFactory
Parameters:
iItemId - - id of item to get units for
Returns:
List - list of units
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

resetCounts

public int resetCounts(int iInventoryId)
                throws org.opensubsystems.core.error.OSSException
Reset all counts of all items in the inventory to 0. The sum of these values is cached in the Item and these has to always be in sync therefore those counts needs to be reset as well.

Specified by:
resetCounts in interface UnitFactory
Parameters:
iInventoryId - - inventory id where to reset count of items
Returns:
int - number of updated items
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

changeAvailableCount

public boolean changeAvailableCount(int iUnitId,
                                    int iValue)
                             throws org.opensubsystems.core.error.OSSException
Change the available count for specified unit by specified relative value. If the value is positive the available item count will be increased otherwise it will be decreased. The sum of these values is cached in the Item and these has to always be in sync.

Specified by:
changeAvailableCount in interface UnitFactory
Parameters:
iUnitId - - unit id to change the available count for
iValue - - value to add (if positive) or remove (if negative)
Returns:
boolean - sucess flag
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

changeAvailableCount

public boolean changeAvailableCount(java.util.List lstChanges)
                             throws org.opensubsystems.core.error.OSSException
Change the available count for specified unit by specified relative values. If the value is positive the available item count will be increased otherwise it will be decreased. The sum of these values is cached in the Item and these has to always be in sync.

Specified by:
changeAvailableCount in interface UnitFactory
Parameters:
lstChanges - - list of TwoIntStructs where the first int is the unit id and the second int is the integer value (positive or negative to change the count by)
Returns:
boolean - sucess flag
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

changeShippedAndAvailableCount

public boolean changeShippedAndAvailableCount(int iUnitId,
                                              int iValue)
                                       throws org.opensubsystems.core.error.OSSException
Change the shipped and available count for specified unit by specified relative value. If the value is positive the available item count will be increased otherwise it will be decreased. The sum of these values is cached in the Item and these has to always be in sync.

Specified by:
changeShippedAndAvailableCount in interface UnitFactory
Parameters:
iUnitId - - unit id to change the available count for
iValue - - value to add (if positive) or remove (if negative)
Returns:
boolean - sucess flag
Throws:
org.opensubsystems.core.error.OSSException - - an error has occured

changeShippedAndAvailableCountSecure

public boolean changeShippedAndAvailableCountSecure(int iUnitId,
                                                    int iValue)
                                             throws org.opensubsystems.core.error.OSSException
Change the shipped and available count for specified unit by specified relative value. If the value is positive the available item count will be increased otherwise it will be decreased. The sum of these values is cached in the ItemType and these has to always be in sync. Because shipped have to be always >= 0 and availble can be < 0 only in foud holder this function remove max shipped and available from item

Specified by:
changeShippedAndAvailableCountSecure in interface UnitFactory
Parameters:
iUnitId - - Unit id
iValue - - value to add ( have to be >= 0 )
Returns:
boolean - sucess flag
Throws:
org.opensubsystems.core.error.OSSException - - error in database

changeAvailableCount

protected int changeAvailableCount(java.sql.PreparedStatement updateStatement,
                                   int iUnitId,
                                   int iValue)
                            throws org.opensubsystems.core.error.OSSException
Change the available count for specified units by specified relative values. If the value is positive the available item count will be increased otherwise it will be decreased.

Parameters:
updateStatement - - JDBC statement to use
iUnitId - - Unit id
iValue - - value to add or subtract
Returns:
updateCout - how many items were updated
Throws:
org.opensubsystems.core.error.OSSException - - database error

changeShippedAndAvailableCount

protected int changeShippedAndAvailableCount(java.sql.PreparedStatement updateStatement,
                                             int iUnitId,
                                             int iValue,
                                             boolean isSecure)
                                      throws org.opensubsystems.core.error.OSSException
Change the shipped and available count for specified units by specified relative values. If the value is positive the available item count will be increased otherwise it will be decreased.

Parameters:
updateStatement - - JDBC statement to use
iUnitId - - Unit id
iValue - - value to add or subtract
isSecure - - if true it is called from secure variant
Returns:
updateCout - how many items were updated
Throws:
org.opensubsystems.core.error.OSSException - - database error


Copyright © 2003 - 2006 OpenSubsystems s.r.o.