package cleware.serverservlet; import cleware.dbc.*; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class GenericDBServerServlet extends GenericServerServlet implements LiveDataSetProcessor { public static final int MNG_LIST = GenericServerServlet.MODE_USER, MNG_INSERT_FORM = GenericServerServlet.MODE_USER+1, MNG_INSERT_SQL = GenericServerServlet.MODE_USER+2, MNG_UPDATE_FORM = GenericServerServlet.MODE_USER+3, MNG_UPDATE_SQL = GenericServerServlet.MODE_USER+4, MNG_DELETE_SQL = GenericServerServlet.MODE_USER+5, MODE_USER = GenericServerServlet.MODE_USER + 10; public static DataBase db; public static String sDBServerDriver; public static String sDBServerAddress; public static int iDBServerPort; public static String sDBServerUser; public static String sDBserverPassword; public DataSet DefDs; public void init(ServletConfig config) throws ServletException { super.init(config); if (db == null) { if (sDBServerDriver == null) sDBServerDriver = pf.GetParam("DBSERVERDRIVER", "connect.microsoft.MicrosoftDriver"); if (sDBServerAddress == null) sDBServerAddress = pf.GetParam("DBSERVERADDRESS", "127.0.0.1"); if (iDBServerPort == 0) iDBServerPort = pf.GetParamInt("DBSERVERPORT", 1433); if (sDBServerUser == null) sDBServerUser = pf.GetParam( "DBSERVERUSER", "sa" ); if (sDBserverPassword == null) sDBserverPassword = pf.GetParam( "DBSERVERPASSWORD", "" );; db = new DataBase( sDBServerDriver, sDBServerAddress, iDBServerPort, sDBServerUser, sDBserverPassword ); if( !db.Connect() ) throw new ServerServletException( db.sDbError ); } } public synchronized void Destroy() throws ServerServletException { DefDs = null; } public void destroy() { if( db != null ) db.close(); db = null; sDBServerDriver = null; sDBServerAddress = null; sDBServerUser = null; sDBserverPassword = null; super.destroy(); } /** A LiveDataSetProcessor megvalósítása */ public boolean ProcessRow( LiveDataSet ds ) { return true; } /** Default DataSet kijelölése */ public void DefaultDataSet( DataSet ds ) { DefDs = ds; } /** Az adott nevű Request mező értékét átmásolja az adott DataSet mezőjébe */ public void Req2Ds( String sName, DataSet ds ) { if( ds != null ) ds.FieldByName( sName ).AsString( req.FieldStr( sName ) ); } /** Az adott nevű Request mező értékét átmásolja az adott DataSet mezőjébe */ public void Req2Ds( String sName ) { Req2Ds( sName, DefDs ); } public void Field( String sName, int iLen, int iMaxLen, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.Field( sName, iLen, iMaxLen, sValue, bRequired ) ); } public void Field( String sName, int iLen, int iMaxLen ) { Field( sName, iLen, iMaxLen, false ); } public void FieldAndLabel( String sLabel, String sName, int iLen, int iMaxLen, String sFooter, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; FieldAndLabel( sLabel, sName, iLen, iMaxLen, sValue, sFooter, bRequired ); } public void FieldAndLabel( String sLabel, String sName, int iLen, int iMaxLen, String sFooter ) { FieldAndLabel( sLabel, sName, iLen, iMaxLen, sFooter, false ); } public void FieldCell( String sName, int iLen, int iMaxLen, String sFooter, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; FieldCell( sName, iLen, iMaxLen, sValue, sFooter, bRequired ); } public void FieldCell( String sName, int iLen, int iMaxLen, String sFooter ) { FieldCell( sName, iLen, iMaxLen, sFooter, false); } public void FieldCell( String sName, int iLen, int iMaxLen, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.FieldCell( sName, iLen, iMaxLen, sValue, bRequired ) ); } public void FieldCell( String sName, int iLen, int iMaxLen ) { FieldCell( sName, iLen, iMaxLen, false ); } public void FieldRow( String sName, int iRowNum, int iLen, int iMaxLen, String sFooter, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; FieldRow( sName, iRowNum, iLen, iMaxLen, sValue, sFooter, bRequired ); } public void FieldRow( String sName, int iRowNum, int iLen, int iMaxLen, String sFooter ) { FieldRow( sName, iRowNum, iLen, iMaxLen, sFooter, false ); } public void FieldAndLabelCell( String sLabel, String sName, int iLen, int iMaxLen, String sFooter, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.FieldAndLabelCell( sLabel, sName, iLen, iMaxLen, sValue, sFooter, bRequired ) ); } public void FieldAndLabelCell( String sLabel, String sName, int iLen, int iMaxLen, String sFooter ) { FieldAndLabelCell( sLabel, sName, iLen, iMaxLen, sFooter, false ); } public void FieldAndLabelCell( String sLabel, String sName, int iLen, int iMaxLen, boolean bRequired ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.FieldAndLabelCell( sLabel, sName, iLen, iMaxLen, sValue, bRequired ) ); } public void FieldAndLabelCell( String sLabel, String sName, int iLen, int iMaxLen ) { FieldAndLabelCell( sLabel, sName, iLen, iMaxLen, false ); } public void TextArea( String sName, int iRows, int iCols, String sWrap ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextArea( sName, iRows, iCols, sWrap, sValue ) ); } public void TextAreaAndLabel( String sLabel, String sName, int iRows, int iCols, String sWrap, String sFooter ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextAreaAndLabel( sLabel, sName, iRows, iCols, sWrap, sValue, sFooter ) ); } public void TextAreaCell( String sName, int iRows, int iCols, String sWrap, String sFooter ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextAreaCell( sName, iRows, iCols, sWrap, sValue, sFooter ) ); } public void TextAreaCell( String sName, int iRows, int iCols, String sWrap ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextAreaCell( sName, iRows, iCols, sWrap, sValue ) ); } public void TextAreaAndLabelCell( String sLabel, String sName, int iRows, int iCols, String sWrap, String sFooter ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextAreaAndLabelCell( sLabel, sName, iRows, iCols, sWrap, sValue, sFooter ) ); } public void TextAreaAndLabelCell( String sLabel, String sName, int iRows, int iCols, String sWrap ) { String sValue; if( DefDs != null ) sValue = DefDs.FieldByName( sName ).AsString(); else sValue = ""; Print( form.TextAreaAndLabelCell( sLabel, sName, iRows, iCols, sWrap, sValue ) ); } public void CheckBox( String sName, String sFooter ) { boolean bChecked = false; if( DefDs != null ) bChecked = DefDs.FieldByName( sName ).AsBoolean(); CheckBox( sName, sFooter, bChecked ) ; } public void CheckBoxCell( String sName, String sFooter ) { boolean bChecked = false; if( DefDs != null ) bChecked = DefDs.FieldByName( sName ).AsBoolean(); CheckBoxCell( sName, sFooter, bChecked ); } public void CheckBoxAndLabelCell( String sLabel, String sName, String sFooter ) { boolean bChecked = false; if( DefDs != null ) bChecked = DefDs.FieldByName( sName ).AsBoolean(); CheckBoxAndLabelCell( sLabel, sName, sFooter, bChecked ); } public void ComboBox( String sName, String sItems ) { int iSelected = 1; if( DefDs != null ) iSelected = DefDs.FieldByName( sName ).AsInteger(); ComboBox( sName, sItems, iSelected ); } public void ComboBoxCell( String sName, String sItems ) { int iSelected = 1; if( DefDs != null ) iSelected = DefDs.FieldByName( sName ).AsInteger(); ComboBoxCell( sName, sItems, iSelected ); } public void ComboBoxAndLabelCell( String sLabel, String sName, String sItems ) { int iSelected = 1; if( DefDs != null ) iSelected = DefDs.FieldByName( sName ).AsInteger(); ComboBoxAndLabelCell( sLabel, sName, sItems, iSelected ); } }