tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jon Wingfield <jon.wingfi...@mkodo.com>
Subject Re: Custom Tag Lib
Date Fri, 08 Aug 2003 09:08:11 GMT
Yikes, calling release() in doStartTag() stops any state being 
accessible to child (body) tags. That would kill our custom iterator tags.
You could have your tags implement the TryCatchFinally interface, 
instead. That way you'll have a chance to reset state before reuse:
http://jakarta.apache.org/taglibs/guidelines.html

I've seen posts on this list saying that tag pooling has either made 
their site a dog or has given a huge positive performance gain. For our 
site, which has many tags per page, it is the latter case :) If you're 
thinking about turning pooling off you'll need to test the effects on 
performance.

Jon

PS We had to go through this process on the upgrade. I share your pain

Mike Cherichetti (Renegade Internet) wrote:
> Shawn,
> 
> I ran into this problem as well when switching from 4.0 to 4.1.  I think it
> has something to do with 4.1 pooling and re-using tag objects.  What I did
> in all of my doStartTag(), doAfterBody(), etc... methods was manually call
> release() to reset the data in the tags like so:
> 
> public int doStartTag() throws JspException
> {
>   try
>   {
>     ...
>   }
> 
>   catch (Exception exception)
>   {
>     throw new JspException(exception);
>   }
> 
>   finally
>   {
>     release();
>   }
> 
>   return SKIP_BODY;
> }
> 
> Have a nice day ...
> 
> Sincerely,
> 
> Mike Cherichetti
> Renegade Internet
> Internet Advertising Delivery Solutions
> www.renegadeinternet.com
> Phone (724) 658-6346
> Fax (724) 658-6346
> 
> 
> -----Original Message-----
> From: Shawn Zernik [mailto:szernik@internetworkconsulting.net]
> Sent: Thursday, August 07, 2003 10:56 PM
> To: tomcat-user@jakarta.apache.org
> Subject: Custom Tag Lib
> 
> 
> Tomcat Users:
> 
> I've been fighting with some version differences in tom cat wondering why my
> app acts severly different on Tomcat 4.1.27 then 4.0.6.  It appears that
> 4.1.27 is not working from my perspective, and have been fighting with it
> since monday.  None of the books I have touch this subject or ellude to the
> problem, and I've seached high and low for solutions.
> 
> I'm having a problem working with my custom tag library.  The stange part to
> this is it appears to work on tomcat 4.0.6 but not on 4.1.27.  The library
> has a tage called site that extends a base tag, and those tags use other
> classes in my data namespace to hit a database.
> 
> The tags are returning the proper data in both versions, but in 4.1.27, I
> have to "reload" the contect in the manager for it to "register" the changes
> from the database.  I have added some printlns to std out to track what's
> going on.  In tomcat 4.0.6 they are going through all the code as I would
> exspect it to.  I have included each of the class files that are called.  I
> have also included the printouts from both versions of tomcat to clierify
> how each version is handling the calls.
> 
> The object hiarchey goes as follows:
> 
> jPublish.Tags site extends inc_tag.
> jPublish.Data.site_manager extends jPublish.Data.manager, managers contain,
> load, and fill datas.
> jPublish.Data.site_data extends jPublish.Data.data, used for storing data
> and tracking updates.
> 
> 
> --- INDEX.JSP ---
> <%@ page contentType="text/html" %>
> <%@ taglib prefix="inc" uri="inc" %>
> <inc:site site="1" action="none"/>
> <html>
> 	<head><title><inc:site action="title" /></title></head>
> 
> 	<body>
> 		<h1>Welcome to <inc:site action="title"/>!</h1>
> 		&copy; <inc:site action="copyright"/>
> 	</body>
> </html>
> 
> --- TOMCAT 4.0.6 STDOUT ---
> Starting service Tomcat-Standalone
> Apache Tomcat/4.0.6
> Starting service Tomcat-Apache
> Apache Tomcat/4.0.6
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.setSite()
> jPublish.Data.manager()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Shawn
> jPublish.Tags.site.doEndTag(): End
> 
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.setSite()
> jPublish.Data.manager()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> INC
> jPublish.Tags.site.doEndTag(): End
> 
> --- TOMCAT 4.1.27 STDOUT: db INC then Shawn ---
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.setSite()
> jPublish.Data.manager()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.site.doEndTag(): End
> jPublish.Data.manager()
> jPublish.Tags.site()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.inc_tag.loaded(): not instance
> jPublish.Data.manager.load()
> jPublish.Tags.inc_tag.loaded(): load ok
> jPublish.Tags.inc_tag.loaded(): next ok
> jPublish.Tags.inc_tag.loaded(): reached fill.
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.site.loaded()
> INC
> jPublish.Tags.site.doEndTag(): End
> 
> <Change INC to Shawn in DB>
> jPublish.Tags.site.setSite()
> jPublish.Data.manager()
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.site.doEndTag(): End
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.site.loaded()
> Internetwork Consulting
> jPublish.Tags.site.doEndTag(): End
> jPublish.Tags.site.doEndTag(): Begin
> jPublish.Tags.inc_tag.loaded()
> jPublish.Tags.site.loaded()
> INC
> jPublish.Tags.site.doEndTag(): End
> 
> --- SITE TAG "inc:site" ---
> package jPublish.Tags;
> 
> import jPublish.Data.*;
> 
> public class site extends inc_tag {
> 	private site_data objSite;
> 
> 	// Constructors
> ////////////////////////////////////////////////////////////
>  	public site() {
> 		objManager = (manager) new site_manager();
> 		System.out.println("jPublish.Tags.site()");
> 	}
> 
> 	// Properties
> //////////////////////////////////////////////////////////////
> 	public void setSite(String strNew) {
> 		System.out.println("jPublish.Tags.site.setSite()");
> 		objManager = (manager) new site_manager();
> 		objManager.setWhere("id = " + strNew);
> 	}
> 
> 	// Methods
> /////////////////////////////////////////////////////////////////
> 	protected boolean loaded() {
> 		if(super.loaded()) {
> 			objSite = (site_data) objData;
> 			System.out.println("jPublish.Tags.site.loaded()");
> 			return true;
> 		} else
> 			return false;
> 	}
> 
> 	public int doEndTag() {
> 		System.out.println("jPublish.Tags.site.doEndTag(): Begin");
> 
> 		if(strAction.equalsIgnoreCase("id"))
> 			if(loaded()) print(Long.toString(objSite.getID()));
> 
> 		if(strAction.equalsIgnoreCase("design"))
> 			if(loaded()) print(Long.toString(objSite.getDesign()));
> 
> 		if(strAction.equalsIgnoreCase("title"))
> 			if(loaded()) print(objSite.getTitle());
> 
> 		if(strAction.equalsIgnoreCase("webmaster"))
> 			if(loaded()) print(objSite.getWebmaster());
> 
> 		if(strAction.equalsIgnoreCase("email"))
> 			if(loaded()) print(objSite.getEmail());
> 
> 		if(strAction.equalsIgnoreCase("copyright"))
> 			if(loaded()) print(objSite.getCopyright());
> 
> 		if(strAction.equalsIgnoreCase("logo"))
> 			if(loaded()) print(objSite.getLogo());
> 
> 		if(strAction.equalsIgnoreCase("next"))
> 			if(objManager.next()) return this.EVAL_BODY_AGAIN;
> 
> 		System.out.println("jPublish.Tags.site.doEndTag(): End");
> 
> 		return this.SKIP_BODY;
> 	}
> }
> 
> --- INC_TAG ---
> package jPublish.Tags;
> 
> import jPublish.Data.*;
> import javax.servlet.*;
> import javax.servlet.jsp.*;
> import javax.servlet.jsp.tagext.*;
> 
> public abstract class inc_tag extends TagSupport {
>     // Data Menebers
> ///////////////////////////////////////////////////////////
> 	protected manager objManager;
> 	protected data objData;
> 	protected String strWhere;
> 
> 	// Action Data
> 	protected String strAction = "none";
> 	private String strOutput = "none";
> 
> 	// Properties
> //////////////////////////////////////////////////////////////
> 	public void setAction(String strNew) { strAction = strNew; }
> 	public void setOutput(String strNew) { strOutput = strNew; }
> 	public manager getManager() { return objManager; }
> 
> 	// Internal Methods
> ////////////////////////////////////////////////////////
> 	protected boolean loaded() {
> 		System.out.println("jPublish.Tags.inc_tag.loaded()");
> 		if(!(objData instanceof data)) {
> 			System.out.println("jPublish.Tags.inc_tag.loaded(): not instance");
> 			if(objManager.load()) {
> 				System.out.println("jPublish.Tags.inc_tag.loaded(): load ok");
> 				if(objManager.next()) {
> 					System.out.println("jPublish.Tags.inc_tag.loaded(): next ok");
> 					if(objManager.fill()) {
> 						System.out.println("jPublish.Tags.inc_tag.loaded(): reached fill.");
> 						objData = objManager.getData();
> 						return true;
> 					} else
> 						return false;
> 				}
> 			} else
> 				return false;
> 		}
> 
> 		// Data Exist: Loaded
> 		return true;
> 	}
> 
> 	protected void print(String strOut) {
> 		JspWriter out = pageContext.getOut();
> 
> 		System.out.println(strOut);
> 		try { out.print(format(strOut)); }
> 		catch (Exception e) { System.out.println("Exception error: " + e); }
> 	}
> 
> 	protected String format(String strIn) {
> 		String strTemp = new String();
> 		char cTemp;
> 
> 		// String Safe
> 		if(strOutput.equalsIgnoreCase("stringsafe")) {
> 			for(int iCnt = 0; iCnt < strIn.length(); iCnt++) {
> 				cTemp = strIn.charAt(iCnt);
> 				switch(cTemp) {
> 					case '\'':
> 						strTemp += "\\\'";
> 						break;
> 					case '\"':
> 						strTemp += "\\\"";
> 						break;
> 					case '\\':
> 						strTemp += "\\\\";
> 						break;
> 					default:
> 						strTemp += cTemp;
> 						break;
> 				}
> 			}
> 			return strTemp;
> 		}
> 
> 		// Strip String
> 		if(strOutput.equalsIgnoreCase("stringsafe")) {
> 			for(int iCnt = 0; iCnt < strIn.length(); iCnt++) {
> 				cTemp = strIn.charAt(iCnt);
> 				switch(cTemp) {
> 					case '\'':
> 						break;
> 					case '\"':
> 						break;
> 					default:
> 						strTemp += cTemp;
> 						break;
> 				}
> 			}
> 			return strTemp;
> 		}
> 
> 		// HTML Safe
> 		if(strOutput.equalsIgnoreCase("htmlsafe")) {
> 			for(int iCnt = 0; iCnt < strIn.length(); iCnt++) {
> 				cTemp = strIn.charAt(iCnt);
> 				switch(cTemp) {
> 					case '<':
> 						strTemp += "&lt;";
> 						break;
> 					case '>':
> 						strTemp += "&gt;";
> 						break;
> 					default:
> 						strTemp += cTemp;
> 						break;
> 				}
> 			}
> 			return strTemp;
> 		}
> 
> 		// None
> 		return strIn;
> 	}
> }
> 
> --- DATA.SITE_MANAGER ---
> package jPublish.Data;
> 
> public class site_manager extends manager {
>     // Constructors
> ////////////////////////////////////////////////////////////
> 	public site_manager() {
> 		super();
> 		super.setTable("sites");
> 	}
> 
> 	// Methods
> /////////////////////////////////////////////////////////////////
> 	public boolean fill() {
> 		site_data dataNew = new site_data();
> 
> 		try {
> 			dataNew.setID(sqlResults.getLong("id"));
> 			dataNew.setDesign(sqlResults.getLong("design"));
> 			dataNew.setTitle(sqlResults.getString("title"));
> 			dataNew.setWebmaster(sqlResults.getString("webmaster"));
> 			dataNew.setEmail(sqlResults.getString("email"));
> 			dataNew.setCopyright(sqlResults.getString("copyright"));
> 			dataNew.setLogo(sqlResults.getString("logo"));
> 
> 			dataNew.setManager((manager) this);
> 			dataNew.setLoaded();
> 			objData = (data) dataNew;
> 			return true;
> 		}
> 
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 		}
> 
> 		return false;
> 	}
> }
> 
> --- DATA.SITE_DATA ---
> package jPublish.Data;
> 
> public class site_data extends data {
>     // Data Menebers
> ///////////////////////////////////////////////////////////
> 	private long lDesign;
> 	private String strTitle;
> 	private String strWebmaster;
> 	private String strEmail;
> 	private String strCopyright;
> 	private String strLogo;
> 	// Child Relationships
> 	private section_manager objSections;
> 	// Parent Relationships
> 	private design_manager objDesigns;
> 
> 	// Constructors
> ////////////////////////////////////////////////////////////
> 	public site_data() { super(); }
> 
> 	// Properties
> //////////////////////////////////////////////////////////////
> 	public boolean setDesign(long lNew) {
> 		if(lNew > 0) {
> 			lDesign = lNew;
> 			objUpdates.set("design", Long.toString(lNew));
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public boolean setTitle(String strNew) {
> 		if(strNew.length() > 0) {
> 			strTitle = strNew;
> 			objUpdates.set("title", strNew);
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public boolean setWebmaster(String strNew) {
> 		if(strNew.length() > 0) {
> 			strWebmaster = strNew;
> 			objUpdates.set("webmaster", strNew);
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public boolean setEmail(String strNew) {
> 		if(strNew.length() > 0) {
> 			strEmail = strNew;
> 			objUpdates.set("email", strNew);
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public boolean setCopyright(String strNew) {
> 		if(strNew.length() > 0) {
> 			strCopyright = strNew;
> 			objUpdates.set("copyright", strNew);
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public boolean setLogo(String strNew) {
> 		if(strNew.length() > 0) {
> 			strLogo = strNew;
> 			objUpdates.set("logo", strNew);
> 			return true;
> 		}
> 
> 		return false;
> 	}
> 
> 	public long getDesign() { return lDesign; }
> 	public String getTitle() { return strTitle; }
> 	public String getWebmaster() { return strWebmaster; }
> 	public String getEmail() { return strEmail; }
> 	public String getCopyright() { return strCopyright; }
> 	public String getLogo() { return strLogo; }
> 
> 	// Child Relationships
> 	public section_manager getSections() {
> 		if(!(objSections instanceof section_manager)) {
> 			objSections = new section_manager();
> 			objSections.setWhere("site = " + this.getID());
> 			objSections.load();
> 		}
> 		return objSections;
> 	}
> 
> 	// Parent Relationships
> 	public design_manager getParentDesign() {
> 		if(!(objDesigns instanceof design_manager)) {
> 			objDesigns = new design_manager();
> 			objDesigns.setWhere("site = " + this.getDesign());
> 			objDesigns.load();
> 		}
> 		return objDesigns;
> 	}
> }
> 
> --- DATA.MANAGER ---
> package jPublish.Data;
> import java.sql.*;
> 
> public abstract class manager extends Object {
>     // Data Members
> ////////////////////////////////////////////////////////////
>     protected data objData;
>     protected String strError = new String();
> 
>     // SQL Options
>     private String strTable = new String();
>     private String strWhere = new String();
> 
>     // Data SQL Connection
>     protected Connection sqlConnection;
>     protected Statement sqlStatement;
>     protected ResultSet sqlResults;
> 
>     // Constructors
> ////////////////////////////////////////////////////////////
>     manager() {
> 		System.out.println("jPublish.Data.manager()");
> 
> 		try {
> 			Class.forName("com.mysql.jdbc.Driver").newInstance();
> 
> 			sqlConnection = DriverManager.getConnection(
> 			"jdbc:mysql://localhost/jPublish", "root", "");
> 			sqlStatement = sqlConnection.createStatement(
> 			ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
> 		}
> 
> 		catch (Exception e) {
> 			strError = "Execption error: " + e;
> 		}
>     }
> 
>     // Properties
> //////////////////////////////////////////////////////////////
>     public boolean setTable(String strNew) {
> 		if((strNew instanceof String) && (strNew.length() > 0)) {
> 			strTable = strNew;
> 			return true;
> 		} else
> 			return false;
>     }
> 
>     public boolean setWhere(String strNew) {
> 		if((strNew instanceof String) && (strNew.length() > 0)) {
> 			if(strWhere.length() > 0)
> 				strWhere += " AND " + strNew;
> 			else
> 				strWhere = strNew;
> 
> 			return true;
> 		} else
> 			return false;
>     }
> 
>     public data getData() { return objData; }
>     public String getError() { return strError; }
> 
>     public String getTable() { return strTable; }
>     public String getWhere() { return strWhere; }
> 	public int getCount() {
> 		int iCurr = -1;
> 		int iLast = -1;
> 
> 		try {
> 			iCurr = sqlResults.getRow();
> 			sqlResults.last();
> 			iLast = sqlResults.getRow();
> 			sqlResults.absolute(iCurr);
> 		}
> 		catch (Exception e) { strError = "Exception Error: " + e; }
> 
> 		return iLast;
> 	}
> 
>     // Methods
> /////////////////////////////////////////////////////////////////
>     public boolean load() {
> 		String strQuery = "";
> 
> 		System.out.println("jPublish.Data.manager.load()");
> 
> 		// Build the Query
> 		strQuery = strQuery + "SELECT * ";
> 		strQuery = strQuery + " FROM " + strTable;
> 		if(strWhere.length() > 0)
> 			strQuery = strQuery + " WHERE " + strWhere;
> 
> 		// Get Results
> 		try {
> 			sqlResults = sqlStatement.executeQuery(strQuery);
> 		}
> 
> 		// Get Errors
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
> 
>     public boolean loadFrom(String strTable, String strColumn) {
> 		String strQuery = "";
> 
> 		// Build the Query
> 		strQuery = strQuery + "SELECT " + this.strTable + ".* ";
> 		strQuery = strQuery + " FROM " + strTable + ", " + this.strTable;
> 		strQuery = strQuery + " WHERE " + strTable + "." + strColumn;
> 		strQuery = strQuery + " = " + this.strTable + ".id;";
> 
> 		// Get Results
> 		try {
> 			sqlResults = sqlStatement.executeQuery(strQuery);
> 		}
> 
> 		// Get Errors
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
> 
>     public boolean next() {
> 		try { return sqlResults.next(); }
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
>     }
> 
>     public boolean save() {
> 		// Create Varibles
> 		updates objUpdates = objData.getUpdates();
> 		Object[] arrKeys = objUpdates.getKeys();
> 
> 		try {
> 			// Update Record
> 			for(int iCnt = 0; iCnt < arrKeys.length; iCnt++)
> 				sqlResults.updateString(arrKeys[iCnt].toString(),
> 					objUpdates.get(arrKeys[iCnt].toString()));
> 
> 			// Write Changes
> 			if(objData.getID() > 0)
> 				sqlResults.updateRow();
> 			else
> 				sqlResults.insertRow();
> 		}
> 
> 		// Update Errors
> 		catch (Exception e) {
> 			// Set Error
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
>     // Abstract Functions
> //////////////////////////////////////////////////////
>     // These must be implimented since the extended object only know the
> tables.
>     public abstract boolean fill();
> }
> 
> --- DATA.MANAGER ---
> package jPublish.Data;
> import java.sql.*;
> 
> public abstract class manager extends Object {
>     // Data Members
> ////////////////////////////////////////////////////////////
>     protected data objData;
>     protected String strError = new String();
> 
>     // SQL Options
>     private String strTable = new String();
>     private String strWhere = new String();
> 
>     // Data SQL Connection
>     protected Connection sqlConnection;
>     protected Statement sqlStatement;
>     protected ResultSet sqlResults;
> 
>     // Constructors
> ////////////////////////////////////////////////////////////
>     manager() {
> 		System.out.println("jPublish.Data.manager()");
> 
> 		try {
> 			Class.forName("com.mysql.jdbc.Driver").newInstance();
> 
> 			sqlConnection = DriverManager.getConnection(
> 			"jdbc:mysql://localhost/jPublish", "root", "");
> 			sqlStatement = sqlConnection.createStatement(
> 			ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
> 		}
> 
> 		catch (Exception e) {
> 			strError = "Execption error: " + e;
> 		}
>     }
> 
>     // Properties
> //////////////////////////////////////////////////////////////
>     public boolean setTable(String strNew) {
> 		if((strNew instanceof String) && (strNew.length() > 0)) {
> 			strTable = strNew;
> 			return true;
> 		} else
> 			return false;
>     }
> 
>     public boolean setWhere(String strNew) {
> 		if((strNew instanceof String) && (strNew.length() > 0)) {
> 			if(strWhere.length() > 0)
> 				strWhere += " AND " + strNew;
> 			else
> 				strWhere = strNew;
> 
> 			return true;
> 		} else
> 			return false;
>     }
> 
>     public data getData() { return objData; }
>     public String getError() { return strError; }
> 
>     public String getTable() { return strTable; }
>     public String getWhere() { return strWhere; }
> 	public int getCount() {
> 		int iCurr = -1;
> 		int iLast = -1;
> 
> 		try {
> 			iCurr = sqlResults.getRow();
> 			sqlResults.last();
> 			iLast = sqlResults.getRow();
> 			sqlResults.absolute(iCurr);
> 		}
> 		catch (Exception e) { strError = "Exception Error: " + e; }
> 
> 		return iLast;
> 	}
> 
>     // Methods
> /////////////////////////////////////////////////////////////////
>     public boolean load() {
> 		String strQuery = "";
> 
> 		System.out.println("jPublish.Data.manager.load()");
> 
> 		// Build the Query
> 		strQuery = strQuery + "SELECT * ";
> 		strQuery = strQuery + " FROM " + strTable;
> 		if(strWhere.length() > 0)
> 			strQuery = strQuery + " WHERE " + strWhere;
> 
> 		// Get Results
> 		try {
> 			sqlResults = sqlStatement.executeQuery(strQuery);
> 		}
> 
> 		// Get Errors
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
> 
>     public boolean loadFrom(String strTable, String strColumn) {
> 		String strQuery = "";
> 
> 		// Build the Query
> 		strQuery = strQuery + "SELECT " + this.strTable + ".* ";
> 		strQuery = strQuery + " FROM " + strTable + ", " + this.strTable;
> 		strQuery = strQuery + " WHERE " + strTable + "." + strColumn;
> 		strQuery = strQuery + " = " + this.strTable + ".id;";
> 
> 		// Get Results
> 		try {
> 			sqlResults = sqlStatement.executeQuery(strQuery);
> 		}
> 
> 		// Get Errors
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
> 
>     public boolean next() {
> 		try { return sqlResults.next(); }
> 		catch (Exception e) {
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
>     }
> 
>     public boolean save() {
> 		// Create Varibles
> 		updates objUpdates = objData.getUpdates();
> 		Object[] arrKeys = objUpdates.getKeys();
> 
> 		try {
> 			// Update Record
> 			for(int iCnt = 0; iCnt < arrKeys.length; iCnt++)
> 				sqlResults.updateString(arrKeys[iCnt].toString(),
> 					objUpdates.get(arrKeys[iCnt].toString()));
> 
> 			// Write Changes
> 			if(objData.getID() > 0)
> 				sqlResults.updateRow();
> 			else
> 				sqlResults.insertRow();
> 		}
> 
> 		// Update Errors
> 		catch (Exception e) {
> 			// Set Error
> 			strError = "Exception error: " + e;
> 			return false;
> 		}
> 
> 		return true;
>     }
>     // Abstract Functions
> //////////////////////////////////////////////////////
>     // These must be implimented since the extended object only know the
> tables.
>     public abstract boolean fill();
> }
> 
> --- DATA.DATA ---
> package jPublish.Data;
> 
> public abstract class data extends Object {
>     // Data Menebers
> ///////////////////////////////////////////////////////////
>     protected manager objManager;
> 
>     // Update Tracking
>     protected updates objUpdates;
> 
>     // Data
>     protected long lID;
> 
>     // Constructors
> ////////////////////////////////////////////////////////////
>     data () {
> 		objUpdates = new updates();
>     }
> 
>     // Properties
> //////////////////////////////////////////////////////////////
>     public boolean setManager(manager manNew) {
> 		if(manNew != null) {
> 			objManager = manNew;
> 			return true;
> 		}
> 
> 		return false;
>     }
> 
>     public boolean setLoaded() { return objUpdates.setUpdated(); }
> 
>     public manager getManager() { return objManager; }
>     public updates getUpdates() { return objUpdates; }
> 
>     // Data Properties
>     public boolean setID(long lNew) {
> 		if(lNew > 0) {
> 			lID = lNew;
> 			objUpdates.set("id", Long.toString(lNew));
> 			return true;
> 		}
> 
> 		return false;
>     }
> 
>     public long getID() { return lID; }
> }
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
> 




Mime
View raw message