Hello
I have created a multi tabbed JDesktopPane that will load 5 different configurations depending on the profile of the user logged in that has dozens of forms
And dozens of interactive JInternalFrames, JList, JTables, JTrees and a complete unique file system that is created for each new user sorted by profile. The user
Can interact and maintain different file procedures and additionally save Application created serialized multi tabbed JInternalFrames to maintain a note taking system. The application is built using the MV2 framework and it interacts with a Derby embedded Database through properties files, XML properties and a DAO.
I described the App to explain the App already has a strong Model, View Business logic in place and in good working order and the business rules are implemented already and being refined and debugged.
The First order of business that I can assess is that the DB will need to be switched when the Web App is initiated. My Desktop App has a basic undeveloped
Structure in place that implements a DAOFactory (if you will) and a package that contains Interfaces for each DAO. I have no experience at all with Interfaces
What so ever. Totally ignorant of any use it could have but I tried to tag it along as I created the App hoping it could be useful at a later date.
I would like to develop the Desktop Application into a combined Web Application. I would also be interested in hearing from someone that has experience with
the metamorphosis of said Desktop App or a Web Application that resembles the DB and DAO structure described above. My first question of the many thousands I invite concerns if it is possible to duplicate this Desktop App and switch the DB to a MySQL DB for example and then conform the DAO and XML to interact with A Web App that expresses the same Model view Business rules that I have already tested to be affective? Furthermore, Could some insight be offered that could help me start a separate Web App Entity or could the Web App use the DesktopApp as an embedded Application?
Additional vague basic questions that I am exploring:
What ideal way could trigger the Database loading process?
What would be the simplest way to duplicate a Derby Embedded Database to a DB that could Use DAO, JSF structure?
Is it possible to have a Web app or JSF interact using controllers to implement an embedded DB in any form?
Sample classes found in my DesktopApp that could be useful in the metamorphosis to create and use a
public static void buildDB() that could build the new DB.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
/**
*
* @author depot
*/
public abstract class DAOFactory {
public static final int DERBY = 1;
public static DAOFactory getDAOFactory(int whichFactory) {
switch (whichFactory) {
case DERBY:
return new DerbyDAOFactory();
default:
return null;
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.dao;
import model.interfaces.InstrumentDAO;
import model.interfaces.UserGroupMappingMappingDAO;
import model.interfaces.InstructorDAO;
…
……..
………….
public static ConnectAdminDAO adminDAO;
public static ConnectStudentDAO studentDAO;
public static ConnectInstructorDAO instructorDAO;
public static ConnectPayeeDAO payeeDAO;
public static LoginInfo loginInfo;
public static ConnectPayeeStudentMappingDAO payeeStudentMappingDAO;
public static ConnectInstructorStudentMappingDAO instructorStudentMappingDAO;
public static ConnectNormAvailableDAO normAvailableDAO;
private static boolean isConnected;
public static Properties dbProperties;
private static String dbURL;
..
…
…….
public DerbyDAOFactory(){
}
public static void buildDB() throws FileNotFoundException, IOException, SQLException, ProfileException, LoginException, InterruptedException {
ConnectDerbyDAOWorker cdd = new ConnectDerbyDAOWorker();
cdd.connect();
cdd.disconnect();
System.out.println("disconnected the database");
}
public Connection getConnection() throws FileNotFoundException, IOException, SQLException, ProfileException, LoginException, InterruptedException {
ConnectDerbyDAOWorker cdd = new ConnectDerbyDAOWorker();
cdd.connect();
Connection conn = cdd.getConn();
return conn;
}
public static void disconnect() {
if (isConnected) {
//System.out.println("shutdown database ");
dbURL = ConnectDerbyDAOWorker.getDbURL();
dbProperties.put("shutdown", "true");
try {
DriverManager.getConnection(dbURL, dbProperties);
} catch (SQLException ex) {
System.out.println("disconnected the database " + ex);
}
isConnected = false;
}
}
public AdminDAO getAdminUserDAO() throws ClassNotFoundException, InstantiationException, IllegalAccessException, FileNotFoundException, IOException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("adminDAO"));
adminDAO = (ConnectAdminDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectAdminDAO");
return adminDAO;
}
public StudentDAO getStudentUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException, InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("studentDAO"));
studentDAO = (ConnectStudentDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectStudentDAO");
return studentDAO;
}
public InstructorDAO getInstructorUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException, InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("instructorDAO"));
instructorDAO = (ConnectInstructorDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectInstructorDAO");
return instructorDAO;
}
public PayeeDAO getPayeeUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException, InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("payeeDAO"));
payeeDAO = (ConnectPayeeDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectPayeeDAO");
return payeeDAO;
}
public PayrollDAO getPayrollUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException,
InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("payrollDAO"));
payrollDAO = (ConnectPayrollDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectPaymentDAO");
return (PayrollDAO) payrollDAO;
}
public UserMappingDAO getUserMappingUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException,
InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("userMappingDAO"));
userMappingDAO = (ConnectUserMappingDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectUserMappingDAO");
return (UserMappingDAO) userMappingDAO;
}
public UserGroupMappingDAO getUserGroupMappingUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException,
InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("userGroupMappingDAO"));
userGroupMappingDAO = (ConnectUserGroupMappingDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectUseGroupMappingDAO");
return (UserGroupMappingDAO) userGroupMappingDAO;
}
public UserGroupMappingMappingDAO getUserGroupMappingMappingUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException,
InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("userGroupMappingMappingDAO"));
userGroupMappingMappingDAO = (ConnectUserGroupMappingMappingDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectUserGroupMappingMappingDAO");
return (UserGroupMappingMappingDAO) userGroupMappingMappingDAO;
}
public InstructorStudentMappingDAO getInstructorStudentMappingUserDAO() throws ClassNotFoundException, FileNotFoundException, IOException,
InstantiationException, IllegalAccessException {
Class daoClass = Class.forName(ModelUtils.getXMLResource("instructorStudentMappingDAO"));
instructorStudentMappingDAO = (ConnectInstructorStudentMappingDAO) daoClass.newInstance();
//System.out.println("CREATED NEW INSTANCE OF ConnectInstructorStudentMappingDAO");
return (InstructorStudentMappingDAO) instructorStudentMappingDAO;
}
…..
……
……….
}
one of 30 plus Interfaces for each DAO (implicitly each table) that have no purpose that I can see at the moment.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package model.interfaces;
/**
*
* @author depot
*/
public interface AdminDAO {
/*
//useless code I do not understand follows
//……
//………….
//………………
public Admin connect(ConnectAdminDAO connectAdminDAO)
throws LoginException,
//UnknownstudentUserException,
IncorrectPasswordException;
public Admin select(ConnectAdminDAO connectAdminDAO);
public void insertAdmin(Admin adminUser)
throws RegisterException;
public void update(Admin adminUser)
throws ProfileException;
public void delete(Admin adminUser)
throws UnsubscribeException;
public void fillOptionsCB(Admin adminUser)
throws UnsubscribeException;
*/
}
basic DAO structure used for each table that may help someone explain how I could use an interface.
public class ConnectAdminDAO extends LoginInfo implements AdminDAO {
private int numberOfColumns;
private ArrayList columnNameList;
private HashMap<String, String> columnNameAndType;
public ConnectAdminDAO() {
}
public boolean isChkEmailUnique(String thisEmail) throws ProfileException {
tempUser = null;
bUnique = true;
close(conn, ps);
conn = connect();
ps = conn.prepareStatement(ModelUtils.getXMLResource("adminEmail"));
ps.setString(1, thisEmail);
rs = ps.executeQuery();
if (rs.next()) {
tempEmail = rs.getString(1).trim();
}
if (tempEmail != null) {
close(conn, ps);
bUnique = false;
}
close(conn, ps);
return bUnique;
}
//////////////////////////////////////////////////////////////////////
////////////////// login find admin_uid /////////////////////////
////////////////////////////////////////////////////////////////
public Connection connect() throws UnknownUserNameException, {
ddf = new DerbyDAOFactory();
conn = ddf.getConnection();
//conn.setAutoCommit(false);
return conn;
}
public AdminBean select() throws UnknownUserNameException, SQLException, IncorrectPasswordException, LoginException, FileNotFoundException, IOException {
// connectAdmin();
AdminBean adminUser = new AdminBean();
return adminUser;
}
public AdminBean select(String thisUser, String tempProfile, String TEMP) throws SQLException {
AdminBean adminUser = new AdminBean();
return adminUser;
}
public boolean Unique(String user, String PROFILE, char[] password) throws UnknownUserNameException, {
bUnique = false;
ConnectAdminDAO.user = user;
ConnectAdminDAO.password = password;
System.out.println("PROFILE dao: " + PROFILE);
System.out.println("user dao: " + user);
System.out.println("password.to string: " + password);
try {
close(conn, ps);
ddf = new DerbyDAOFactory();
conn = ddf.getConnection();
//testDB();
ps = conn.prepareStatement(ModelUtils.getXMLResource("adminUserName"));
ps.setString(1, getUser());
rs = ps.executeQuery();
if (rs.next()) {
USER = rs.getString(1).trim();
uUser = chkUserLogin();
}
if (!uUser) {
throw new UnknownUserNameException();
}
pUser = chkPassword(password);
if (!pUser) {
throw new IncorrectPasswordException();
}
bUnique = true;
} catch (UnknownUserNameException e) {
String x = e.getMessage();
System.out.println("error message is: " + x);
ViewUtils vu = new ViewUtils();
vu.addLoginExceptionMessage(x);
} catch (IncorrectPasswordException e) {
String x = e.getMessage();
System.out.println("error message is: " + x);
ViewUtils vu = new ViewUtils();
vu.addLoginExceptionMessage(x);
}
close(conn, ps);
return bUnique;
}
public boolean chkUserLogin() throws UnknownUserNameException, {
bUnique = true;
close(conn, ps);
conn = connect();
ps = conn.prepareStatement(ModelUtils.getXMLResource("adminUserName"));
ps.setString(1, getUser());
System.out.println("chkUser: " + getUser());
rs = ps.executeQuery();
if (!user.equals(USER)) {
bUnique = false;
}
close(conn, ps);
System.out.println("user: bUnique: " + bUnique);
return bUnique;
}
public AdminBean selectTemp(String user, String PROFILE, String email) throws UnknownUserNameException, {
ConnectAdminDAO.user = user;
ConnectAdminDAO.email = email;
System.out.println("PROFILE dao: " + PROFILE);
System.out.println("user dao: " + user);
System.out.println("email.to string: " + email);
adminUser = new AdminBean();
System.out.println("started routine to make bean: " + getProfile());
close(conn, ps);
ddf = new DerbyDAOFactory();
conn = ddf.getConnection();
ps = (PreparedStatement) conn.prepareStatement(
ModelUtils.getXMLResource("selectAdmin"));
ps.setString(1, user);
System.out.println("selectAdmin: " + "\n" + ModelUtils.getXMLResource("selectAdmin"));
rs = ps.executeQuery();
while (rs.next()) {
Admin.setUser(rs.getString(1));
adminUser.setEmail(rs.getString(2));
Admin.setProfile(PROFILE);
}
close(conn, ps);
return (AdminBean) adminUser;
}
….
…….
//______________________________________bInsert___________________________________
public boolean insertAdmin() throws FileNotFoundException, IOException, SQLException, ProfileException, LoginException, UnknownUserNameException, IncorrectPasswordException, javax.security.auth.login.LoginException {
AdminSupplementalDAO as = new AdminSupplementalDAO();
bInsert = as.insertAdmin();
return bInsert;
}
//______________________________________populate edit form__________________________________
public void populateAdminProfile(String thisUser) throws FileNotFoundException, IOException, SQLException, ProfileException, LoginException, UnknownUserNameException, IncorrectPasswordException, javax.security.auth.login.LoginException {
AdminSupplementalDAO as = new AdminSupplementalDAO();
as.populateAdminProfile(thisUser);
}
public void populateAdminRemove(String text) throws SQLException, IncorrectPasswordException, UnknownUserNameException, LoginException, FileNotFoundException, IOException, ProfileException, javax.security.auth.login.LoginException {
AdminSupplementalDAO cd = new AdminSupplementalDAO();
cd.populateAdminRemove(text);
}
//______________________________________delete___________________________________
public boolean deleteAdmin(String thisUid) throws UnknownUserNameException, {
System.out.println(C + M + AND + thisUid + " : thisUid : ");
boolean bDelete = true;
bRecord = isRecord(thisUid);
if (!bRecord) {
throw new MappingException();
}
//setTableName(tableName);
try {
close(conn, ps);
conn = connect();
ps = (PreparedStatement) conn.prepareStatement(
ModelUtils.getXMLResource("deleteAdmin"));
ps.setString(1, thisUid);
int rowCount = ps.executeUpdate();
if (rowCount != 1) {
bDelete = false;
close(conn, ps);
throw new NoRecordDeleteException();
}
System.out.println(C + M + AND + bDelete + ": bDelete : ");
close(conn, ps);
} catch (NoRecordDeleteException ex) {
bDelete = false;
String x = ex.getMessage();
System.out.println("error message is: " + x);
ViewUtils vu = new ViewUtils();
vu.addExceptionMessage(x);
}
return bDelete;
}
…..
………..
……………..
Your time is greatly appreciated.
Steve