Converted database connections to use JNDI naming over DriverManager connections. So LexConstantsSecure.java is no longer needed.

This commit is contained in:
dubtraxis 2003-10-06 16:19:11 +00:00
parent ee70f862c9
commit c532303425
2 changed files with 216 additions and 64 deletions

View file

@ -4,86 +4,225 @@ package org.thdl.lex;
/**
* Description of the Class
*
*@author travis
*@created October 1, 2003
* @author travis
* @created October 1, 2003
*/
public class LexConstants
{
/*
* REQUEST PARAM/ATTR NAMES AND VALUES USED BY LexComponentFilter.java
REQUEST PARAM/ATTR NAMES AND VALUES USED BY LexComponentFilter.java
*/
//form field req params
/**
* Description of the Field
*/
//form field req params
public final static String LABEL_REQ_PARAM = "comp";
/**
* Description of the Field
*/
public final static String TERMLABEL_VALUE = "term";
/**
* Description of the Field
*/
public final static String PRONUNCIATIONLABEL_VALUE = "pronunciation";
/**
* Description of the Field
*/
public final static String SPELLINGLABEL_VALUE = "spelling";
/**
* Description of the Field
*/
public final static String ETYMOLOGYLABEL_VALUE = "etymology";
/**
* Description of the Field
*/
public final static String FUNCTIONLABEL_VALUE = "function";
/**
* Description of the Field
*/
public final static String ENCYCLOPEDIA_ARTICLE_LABEL_VALUE = "encyclopediaArticle";
/**
* Description of the Field
*/
public final static String DEFINITIONLABEL_VALUE = "definition";
/**
* Description of the Field
*/
public final static String SUBDEFINITIONLABEL_VALUE = "subdefinition";
/**
* Description of the Field
*/
public final static String MODELSENTENCELABEL_VALUE = "modelSentence";
/**
* Description of the Field
*/
public final static String PASSAGELABEL_VALUE = "passage";
/**
* Description of the Field
*/
public final static String TRANSLATIONLABEL_VALUE = "translationEquivalent";
/**
* Description of the Field
*/
public final static String RELATEDTERMLABEL_VALUE = "relatedTerm";
/**
* Description of the Field
*/
public final static String REGISTERLABEL_VALUE = "register";
/**
* Description of the Field
*/
public final static String KEYWORDLABEL_VALUE = "keyword";
/**
* Description of the Field
*/
public final static String PREFERENCESLABEL_VALUE = "preferences";
/**
* Description of the Field
*/
public final static String ANALYTICALNOTELABEL_VALUE = "analyticalNote";
/*
* REQUEST PARAM NAMES AND VALUES USED BY LexActionServlet.java
REQUEST PARAM NAMES AND VALUES USED BY LexActionServlet.java
*/
/**
* Description of the Field
*/
public final static String COMMAND_REQ_PARAM = "cmd";
/*
* REQUEST PARAM NAMES AND VALUES USED BY LoginServlet.java
REQUEST PARAM NAMES AND VALUES USED BY LoginServlet.java
*/
/**
* Description of the Field
*/
public final static String USERNAME_REQ_PARAM = "username";
/**
* Description of the Field
*/
public final static String PASSWORD_REQ_PARAM = "password";
/*
* --------------------------
* REQUEST PARAM NAMES USED BY LexComponent.scrapeRequest(req) METHODS
* --------------------------
--------------------------
REQUEST PARAM NAMES USED BY LexComponent.scrapeRequest(req) METHODS
--------------------------
*/
//Meta Data Request Params
/**
* Description of the Field
*/
//Meta Data Request Params
public final static String NOTE_REQ_PARAM = "note";
/**
* Description of the Field
*/
public final static String LANGUAGE_REQ_PARAM = "language";
/**
* Description of the Field
*/
public final static String TRANSLATIONOF_REQ_PARAM = "translationOf";
/**
* Description of the Field
*/
public final static String DIALECT_REQ_PARAM = "dialect";
/**
* Description of the Field
*/
public final static String SOURCE_REQ_PARAM = "source";
/**
* Description of the Field
*/
public final static String PROJSUB_REQ_PARAM = "projectSubject";
/**
* Description of the Field
*/
public final static String SCRIPT_REQ_PARAM = "script";
//Term Data Request Params
//Term Data Request Params
/**
* Description of the Field
*/
public final static String TERM_REQ_PARAM = "term";
/**
* Description of the Field
*/
public final static String TERMID_REQ_PARAM = "termId";
// public static final String SPELLINGNOTE_REQ_PARAM = "spellingNote";
// public static final String SPELLINGNOTE_REQ_PARAM = "spellingNote";
/**
* Description of the Field
*/
public final static String PRECEDENCE_REQ_PARAM = "precedence";
//Definition Data Request Params
//Definition Data Request Params
/**
* Description of the Field
*/
public final static String SUBDEFINITION_REQ_PARAM = "subdefinition";
//outgoing request attributes to jsp
/**
* Description of the Field
*/
public final static String COMPONENT_REQ_ATTR = "component";
/**
* Description of the Field
*/
public final static String ORIGINALBEAN_REQ_ATTR = "original";
/**
* Description of the Field
*/
public final static String MESSAGE_REQ_ATTR = "message";
//session attributes used by filters, servlet, commands and jsp
/**
* Description of the Field
*/
public final static String USER_SESS_ATTR = "user";
/**
* Description of the Field
*/
public final static String PREFERENCES_SESS_ATTR = "preferences";
/**
* Description of the Field
*/
public final static String LOGINTARGET_SESS_PARAM = "loginTarget";
/**
* Description of the Field
*/
public final static String DISPLAYMODE_SESS_ATTR = "displayMode";
/**
* Description of the Field
*/
public final static String QUERY_SESS_ATTR = "query";
/**
* Description of the Field
*/
public final static String TERMENTRYBEAN_SESS_ATTR = "termEntry";
//used by Servlet
/**
* Description of the Field
*/
public final static String JSP_DIR = "/jsp/";
/**
* Description of the Field
*/
public final static String WELCOME_PAGE = "action?cmd=menu";
/**
* Description of the Field
*/
public final static String ERROR_PAGE = "error.jsp";
//used by Repository
/**
* Description of the Field
*/
public final static String DRIVER = "com.mysql.jdbc.Driver";
/**
* Description of the Field
*/
public final static String DATASOURCE_NAME = "java:comp/env/jdbc/lex-datasource";
/**
* Description of the Field
*/
public final static String HIBERNATE_SESSION_KEY = "hib";
//public final static String URL = "jdbc:mysql://localhost/LexTorque";
//public final static String URL = "jdbc:mysql://localhost/LexTorque";
}

View file

@ -1,14 +1,16 @@
package org.thdl.lex;
import java.sql.*;
import java.util.*;
import java.sql.*;
import javax.naming.*;
import javax.sql.*;
/**
* Description of the Class
*
*@author travis
*@created September 26, 2002
* @author travis
* @created September 26, 2002
*/
public class LexRepository
{
@ -25,8 +27,8 @@ public class LexRepository
/**
* Sets the connection attribute of the LexRepository object
*
*@param connection The new connection value
*@since
* @param connection The new connection value
* @since
*/
private void setConnection( Connection connection )
{
@ -37,8 +39,8 @@ public class LexRepository
/**
* Sets the queryStatement attribute of the LexRepository object
*
*@param queryStatement The new queryStatement value
*@since
* @param queryStatement The new queryStatement value
* @since
*/
public void setQueryStatement( Statement queryStatement )
{
@ -49,8 +51,8 @@ public class LexRepository
/**
* Sets the updateStatement attribute of the LexRepository object
*
*@param updateStatement The new updateStatement value
*@since
* @param updateStatement The new updateStatement value
* @since
*/
public void setUpdateStatement( Statement updateStatement )
{
@ -61,9 +63,9 @@ public class LexRepository
/**
* Gets the instance attribute of the LexRepository class
*
*@return The instance value
*@exception LexRepositoryException Description of the Exception
*@since
* @return The instance value
* @exception LexRepositoryException Description of the Exception
* @since
*/
public static LexRepository getInstance() throws LexRepositoryException
{
@ -78,8 +80,8 @@ public class LexRepository
/**
* Gets the connection attribute of the LexRepository object
*
*@return The connection value
*@since
* @return The connection value
* @since
*/
private Connection getConnection()
{
@ -90,8 +92,8 @@ public class LexRepository
/**
* Gets the queryStatement attribute of the LexRepository object
*
*@return The queryStatement value
*@since
* @return The queryStatement value
* @since
*/
public Statement getQueryStatement()
{
@ -102,8 +104,8 @@ public class LexRepository
/**
* Gets the updateStatement attribute of the LexRepository object
*
*@return The updateStatement value
*@since
* @return The updateStatement value
* @since
*/
public Statement getUpdateStatement()
{
@ -115,11 +117,11 @@ public class LexRepository
/**
* doQuery() performs a SELECT query on the database.
*
*@param sql This is a SQL String passed in from
* @param sql This is a SQL String passed in from
* outside.
*@return ResultSet representing query results
*@exception LexRepositoryException Description of the Exception
*@since
* @return ResultSet representing query results
* @exception LexRepositoryException Description of the Exception
* @since
*/
public ResultSet doQuery( String sql ) throws LexRepositoryException
{
@ -129,7 +131,7 @@ public class LexRepository
}
catch ( SQLException sqle )
{
throw new LexRepositoryException( sqle.getMessage() );
throw new LexRepositoryException( sqle );
}
}
@ -137,10 +139,10 @@ public class LexRepository
/**
* doUpdate() performs an INSERT/UPDATE/DROP action
*
*@param sql Description of the Parameter
*@return Description of the Return Value
*@exception LexRepositoryException Description of the Exception
*@since
* @param sql Description of the Parameter
* @return Description of the Return Value
* @exception LexRepositoryException Description of the Exception
* @since
*/
public int doUpdate( String sql ) throws LexRepositoryException
{
@ -150,7 +152,7 @@ public class LexRepository
}
catch ( SQLException sqle )
{
throw new LexRepositoryException( sqle.getMessage() );
throw new LexRepositoryException( sqle );
}
}
@ -159,10 +161,10 @@ public class LexRepository
* doInsert() is a wrapper for doUpdate() that returns the auto_increment
* primary key value of the newly inserted row
*
*@param sql Description of the Parameter
*@return Description of the Return Value
*@exception LexRepositoryException Description of the Exception
*@since
* @param sql Description of the Parameter
* @return Description of the Return Value
* @exception LexRepositoryException Description of the Exception
* @since
*/
public int doInsert( String sql ) throws LexRepositoryException
{
@ -197,7 +199,7 @@ public class LexRepository
}
catch ( SQLException sqle )
{
throw new LexRepositoryException( sqle.getMessage() );
throw new LexRepositoryException( sqle );
}
}
@ -207,8 +209,8 @@ public class LexRepository
* The main program for the LexRepository class. This method tests all other
* methods in this class
*
*@param args The command line arguments
*@since
* @param args The command line arguments
* @since
*/
public static void main( String[] args )
{
@ -218,7 +220,7 @@ public class LexRepository
{
msg = args[0];
}
//TEST doInsert() method. Insert a message multiple times using the Testing table
//TEST doInsert() method. Insert a message multiple times using the Testing table
System.out.println( "TEST ONE\n--------\n" );
try
{
@ -240,8 +242,8 @@ public class LexRepository
lre.printStackTrace();
}
//TEST doQuery() method. Accept a table parameter from the command line and output
//a tab-delimited representation of the table.
//TEST doQuery() method. Accept a table parameter from the command line and output
//a tab-delimited representation of the table.
System.out.println( "\nTEST TWO\n--------\n" );
try
{
@ -293,30 +295,41 @@ public class LexRepository
/**
* Default Constructor for the LexRepository object
*
*@exception LexRepositoryException Description of the Exception
*@since
* @exception LexRepositoryException Description of the Exception
* @since
*/
private LexRepository() throws LexRepositoryException
{
try
{
Class.forName( LexConstants.DRIVER );
Properties props = new Properties();
props.setProperty( "user", LexConstantsSecure.USER );
props.setProperty( "password", LexConstantsSecure.PASSWORD );
props.setProperty( "useUnicode", "true" );
props.setProperty( "characterEncoding", "UTF-8" );
setConnection( DriverManager.getConnection( LexConstantsSecure.URL, props ) );
/*
Class.forName( LexConstants.DRIVER );
Properties props = new Properties();
props.setProperty( "user", LexConstantsSecure.USER );
props.setProperty( "password", LexConstantsSecure.PASSWORD );
props.setProperty( "useUnicode", "true" );
props.setProperty( "characterEncoding", "UTF-8" );
setConnection( DriverManager.getConnection( LexConstantsSecure.URL, props ) );
*/
Context context = new InitialContext();
DataSource source = (DataSource) context.lookup( LexConstants.DATASOURCE_NAME );
setConnection( source.getConnection() );
setQueryStatement( getConnection().createStatement() );
setUpdateStatement( getConnection().createStatement() );
}
catch ( ClassNotFoundException cnfe )
/*
catch ( ClassNotFoundException cnfe )
{
throw new LexRepositoryException( "No Driver Available for: " + LexConstants.DRIVER );
}
*/
catch ( NamingException ne )
{
throw new LexRepositoryException( "No Driver Available for: " + LexConstants.DRIVER );
throw new LexRepositoryException( ne );
}
catch ( SQLException se )
{
throw new LexRepositoryException( se.getMessage() );
throw new LexRepositoryException( se );
}
}
}