@ -41,26 +41,7 @@ public class SqliteDb extends BaseDb implements StockDb {
				@@ -41,26 +41,7 @@ public class SqliteDb extends BaseDb implements StockDb {
					 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						@Override   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						public  Property  setProperty ( long  ownerId ,  long  itemId ,  long  existingPropId ,  Object  value )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							try  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								Property  prop  =  null ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								var  rs  =  select ( ALL ) . from ( TABLE_PROPERTIES ) . where ( ID , equal ( existingPropId ) ) . exec ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( rs . next ( ) )  prop  =  Property . of ( rs ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								rs . close ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( prop  = =  null )  throw  databaseException ( "Failed to add new property to item {0}" , itemId ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( "" . equals ( value ) ) {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
									delete ( ) . from ( TABLE_ITEM_PROPERTIES ) . where ( OWNER , equal ( ownerId ) ) . where ( ITEM_ID , equal ( itemId ) ) . where ( PROPERTY_ID , equal ( existingPropId ) ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								}  else  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
									replaceInto ( TABLE_ITEM_PROPERTIES , OWNER , ITEM_ID , PROPERTY_ID , VALUE ) . values ( ownerId , itemId , existingPropId , value ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								return  prop . value ( value ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}  catch  ( SQLException  e )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								throw  databaseException ( "Failed to add new property to item {0}" , itemId ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						@Override   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						public  Property  addNewProperty ( long  ownerId ,  long  itemId ,  String  name ,  Object  value ,  String  unit )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						public  Property  addNewProperty ( long  itemId ,  String  name ,  Object  value ,  String  unit )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							try  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								db . setAutoCommit ( false ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								var  rs  =  insertInto ( TABLE_PROPERTIES , NAME , TYPE , UNIT ) . values ( name , 0 , unit ) . execute ( db ) . getGeneratedKeys ( ) ;   
				
			 
			
		
	
	
		
			
				
					
						
						
						
							
								 
							 
						
					 
				
				 
				 
				
					@ -68,7 +49,7 @@ public class SqliteDb extends BaseDb implements StockDb {
				@@ -68,7 +49,7 @@ public class SqliteDb extends BaseDb implements StockDb {
					 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( rs . next ( ) )  propertyId  =  rs . getLong ( 1 ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								rs . close ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( propertyId  = =  null  | |  propertyId  = =  0 )  throw  databaseException ( "Failed to create new property {0} to DB" , name ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								insertInto ( TABLE_ITEM_PROPERTIES , OWNER , ITEM_ID , PROPERTY_ID , VALUE ) . values ( ownerId , itemId , propertyId , value ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								insertInto ( TABLE_ITEM_PROPERTIES , ITEM_ID , PROPERTY_ID , VALUE ) . values ( itemId , propertyId , value ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								return  new  Property ( propertyId , name , value , unit ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}  catch  ( SQLException  e )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								throw  databaseException ( "Failed to create new property {0} to DB" , name ) ;   
				
			 
			
		
	
	
		
			
				
					
						
							
								 
							 
						
						
							
								 
							 
						
						
					 
				
				 
				 
				
					@ -323,6 +304,25 @@ public class SqliteDb extends BaseDb implements StockDb {
				@@ -323,6 +304,25 @@ public class SqliteDb extends BaseDb implements StockDb {
					 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							return  item ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						@Override   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						public  Property  setProperty ( long  itemId ,  long  existingPropId ,  Object  value )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							try  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								Property  prop  =  null ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								var  rs  =  select ( ALL ) . from ( TABLE_PROPERTIES ) . where ( ID , equal ( existingPropId ) ) . exec ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( rs . next ( ) )  prop  =  Property . of ( rs ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								rs . close ( ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( prop  = =  null )  throw  databaseException ( "Failed to add new property to item {0}" , itemId ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								if  ( "" . equals ( value ) ) {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
									delete ( ) . from ( TABLE_ITEM_PROPERTIES ) . where ( ITEM_ID , equal ( itemId ) ) . where ( PROPERTY_ID , equal ( existingPropId ) ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								}  else  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
									replaceInto ( TABLE_ITEM_PROPERTIES , ITEM_ID , PROPERTY_ID , VALUE ) . values ( itemId , existingPropId , value ) . execute ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								return  prop . value ( value ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}  catch  ( SQLException  e )  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
								throw  databaseException ( "Failed to add new property to item {0}" , itemId ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						}   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
					
 
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
						private  HashMap < String ,  Long >  transformItems ( Map < String ,  Long >  oldLocationIdsToNew )  throws  SQLException  {   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var  rs  =  select ( ALL ) . from ( TABLE_ITEMS ) . exec ( db ) ;   
				
			 
			
		
	
		
			
				
					 
					 
				
				 
				 
				
							var  insert  =  insertInto ( "items_temp" , OWNER ,  OWNER_NUMBER ,  LOCATION_ID ,  CODE ,  NAME ) ;