package com.adventnet.nms.store.relational;  
import java.sql.*; 
import java.util.*; 
import com.adventnet.nms.store.*; 
import com.adventnet.management.transaction.PreparedStatementWrapper;   
import PACKAGE.*; 

public class RelationalTABLENAME extends CommonRelationalObject
{
	static boolean initialized = false ; 
	static int psIDForGet; 
	static int psIDForAdd; 
	static int psIDForDelete; 
	static int psIDForUpdate; 
	
  public RelationalTABLENAME() 
  {
  }
  public void init(RelationalAPI relapi)  
	{ 
	  super.init(relapi);
	   if (initialized) return;  
		String prepareSqlStringForGet = GETSTATEMENT; 
		
		psIDForGet = relapi.getPreparedStatementID 
		( prepareSqlStringForGet ); 
		
		String prepareSqlStringForAdd = ADDSTATEMENT; 
		
		psIDForAdd = relapi.getPreparedStatementID 
		( prepareSqlStringForAdd ); 
		
		String prepareSqlStringForUpdate = UPDATESTATEMENT; 
		
		psIDForUpdate = relapi.getPreparedStatementID 
		( prepareSqlStringForUpdate ); 
		
		String prepareSqlStringForDelete = DELETESTATEMENT; 
		
		psIDForDelete = relapi.getPreparedStatementID 
		( prepareSqlStringForDelete ); 
		initialized=true;  
	}
	
	public Object  fillPropertiesForObject(Properties p) 
	{
		TABLENAME obj = new TABLENAME(); 
		obj.SETMETHOD(p.getProperty(PRIMARYKEY));
		return obj; 
	}

	public Vector getStatementsForGet(String args) 
	{ 
		Vector v = GETVECTOR(args); 
		PreparedStatementWrapper ps = relapi.fetchPreparedStatement(psIDForGet);
        PreparedStatement preparedStatementForGet = ps.getPreparedStatement();            
		if (preparedStatementForGet!=null) 
		{ 
			try 
			{
				StringTokenizer strTok = new StringTokenizer(args,"\t");
				int index = 1;
				while(strTok.hasMoreTokens())
				{
                              preparedStatementForGet.setString(index,strTok.nextToken());
					index++;
				}
				v.addElement(ps); 
			}
			catch (SQLException sqle) 
			{ 
				System.err.println("Exception setting prepared statement for " 
				+" TABLENAME "+args+":"+sqle); 
			}
		}
		return v; 
	}
	public Vector getStatementsForAdd(Object dbObj) 
	{ 
		TABLENAME obj = (TABLENAME)dbObj; 
		Vector v = ADDVECTOR(dbObj);
		PreparedStatementWrapper ps = relapi.fetchPreparedStatement(psIDForAdd);
                PreparedStatement preparedStatementForAdd = ps.getPreparedStatement();            
		if (preparedStatementForAdd!=null) 
		{ 
			Properties p = obj.getProperties(); 
			try 
			{ 
				
				preparedStatementForAdd.set
				v.addElement(ps); 
			}
			catch (SQLException sqle) 
			{ 
				System.err.println("Exception setting preparedStatement for " 
				+ " TABLENAME :"+sqle); 
				sqle.printStackTrace(); 
			}
		}
		return v; 
	}
	public Vector getStatementsForDelete(Object dbObj) 
	{ 
		TABLENAME obj = (TABLENAME)dbObj; 
		Vector v = DELVECTOR(dbObj); 
		PreparedStatementWrapper ps = relapi.fetchPreparedStatement(psIDForDelete);
        PreparedStatement preparedStatementForDelete = ps.getPreparedStatement();         
		if (preparedStatementForDelete!=null) 
		{ 
			try 
			{ 
				preparedStatementForDelete.setString(1,db2str(obj.GETMETHOD())); 
				v.addElement(ps); 
			}
			catch (SQLException sqle) 
			{ 
				System.err.println("Exception setting preparedStatement for " 
				+" TABLENAME :"+sqle); 
			}
		}
		return v; 
	}
	public Vector getStatementsForUpdate(Object dbObj) 
	{ 
		TABLENAME obj = (TABLENAME)dbObj; 
		Vector v = UPDVECTOR(dbObj);
		PreparedStatementWrapper ps = relapi.fetchPreparedStatement(psIDForUpdate);
                PreparedStatement preparedStatementForUpdate = ps.getPreparedStatement(); 
		if (preparedStatementForUpdate!=null) 
		{ 
			Properties p = obj.getProperties(); 
			try 
			{ 
				preparedStatementForUpdate.setString 
				v.addElement(ps); 
			}
			catch (SQLException sqle) 
			{ 
				System.err.println("Exception setting preparedStatement for " 
				+" TABLENAME :"+sqle); 
				sqle.printStackTrace(); 
			}
		}
		return v; 
	}
}
