bparanj

Greenhorn
+ Follow
since May 27, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by bparanj

Before you begin coding a particular design pattern for your problem, read the intent section of the Design Pattern to decide if it is applicable to your context.

Over-engineering will lead to the same problems as procedural code with no patterns at all. How do you know that you are not using too many patterns that are not required? The answer lies in the elegance of the resulting solution. Does it resolve the forces and fit your constraints well? It is elegant in the sense it helps us to conquer complexity instead of introducing unnecessary complexity.

Originally posted by Vince Hon:


My conern:
1. Is my concept correct regarding the use of DAO ?
2. If I have other biz method that ONLY existed in MySQL instead of Oracle, how to implement it ?
i.e;
//biz method only occur in MySQL
otherShopperMethod();

Do I need to add this in the abstract DAOFactory ? If yes, The OracleDAOFactory has to implement this even this method is always empty (this seems wrong).

3. Actually, I am designing a system with persistance storage, it is probably the data source will not be changed from the same biz logic. i.e. we always use MySQL storing the shopper info. However, we have to get other information from an Oracle database. In this case, there are 2 datasources serving 2 different business logic separately. Is the DAO pattern still apply there ? Could anyone suggest how to do this ?

Thanks



DAO pattern is actually one of the way to implement the Layers Architecture. The main purpose is to isolate the data access
code to a separate tier called the Integration Tier.

#1. Good start. You have grasped the concept explained in the example.
#2. Business logic should be agnostic to the persistance mechanism. If you have to define some business logic that is
not applicable to another database then your design is wrong. Analyze the requirements and find out what varies and
encapsulate it behind a well defined interface.
#3. You have to design your own persitance layer for your requirements.
This layer will have a Mediator that will encapsulate the rules required to dynamically switch between the two different databases during runtime.
There is no better resource to learn how to
design a persistance layer than Scott Ambler. I suggest you start from his website.
[ June 17, 2005: Message edited by: bparanj ]




public ResultSet loadQuestions( String subjectId, String chapterId )

The Business Object that needs the Result set calls this method, gets the result set, converts the result set as XML & sends to GUI.

Is it a better design. I feel it's a bad way to return a ResultSet.
Can anyone guide me.



If you are using JDBC 2.0, I suggest that you take a look at Rowset. I don't think you need to use DTO in that case.

Business objects should not do any data transformation. Remember business objects must be reusable across different UI technologies. It is better to have a mediator that will translate the data from the business tier to the appropriate format for display to the UI. In this case, the Mediator will be specific to the UI and cannot be reused in other types of UI.

Originally posted by Marco K Paul:
Basically, the user selected a calculation type from a dropdown on the screen and in my business object, I have a switch statement that figures out which type of concrete instance to create. since i am using a switch statement, i know which params to pass in. this doesn't sound right to me :roll:



Having a Collection type as one of the parameters is not a good idea. Because your client code will end up with dependency on the method. This implicit dependency, such as - the client code knowing what types of parameter and number of arguments etc can be handled by the implementation.

You have to program to an interface. In your case I suggest you look at the additional parameters and use abstraction to see if you can create a data holder object (assuming they don't have any behavior).

Your current implementation is suffering from programming to the implementation. The business object is tightly coupled to the user interface. It is difficult to give you suggestions without looking at the requirements and the domain. Consider using a Mediator that decouples the user interface from the business objects. You could use just one Mediator class if that is good enough to encapsulate all the interaction between the UI and the business layer or you may need to customize the Mediator pattern to suit your needs.
function isValidIPAddress(ipaddr) {
var re = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/;
if (re.test(ipaddr)) {
var parts = ipaddr.split(".");
if (parseInt(parseFloat(parts[0])) 0) { return false; }
for (var i=0; i<parts.length; i++) {
if (parseInt(parseFloat(parts[i])) > 255) { return false; }
}
return true;
} else {
return false;
}
}
This code is not tested. More info is here :
http://sapassist.com/groups/groups.asp?v=java-l&i=321093
18 years ago
Without knowing your application requirements, its complexity etc, it is very difficult to give you a design suggestion that will fit your scenario.

If the application is simple. Your design is ok. If it is complex with lot of screens and a lot of db access. Things will get messy. Therefore, you should use Mediator Pattern that will encapsulate the interaction between the UI and the Persistance Layer. This Mediator object will be very specific to UI technology, in this case Swing and is also tied to the persistance layer implementation (Hibernate in your case).

Layered architecture must be used for applications that are complex enough to demand its flexibility and other benefits.

Originally posted by shri mon:
I get the following error when i try to use a cache.

org.hibernate.HibernateException: could not instantiate CacheProvider: net.sf.hibernate.cache.OSCacheProvider

The entry which i have in the hibernate.cfg.xml is:

<property name="hibernate.cache.provider_class">net.sf.hibernate.cache.OSCacheProvider</property>

Thanks in advance.
Shrimon



Hibernate is not able to instantiate the class net.sf.hibernate.cache.OSCacheProvider

Since you have not given the version of Hibernate. It is impossible to tell whether you are using the correct class that Hibernate is looks for during instantiation.

I would suggest you attach the jar file to the IDE and use the debugger to see why it is throwing this exception.

Check the documentation for that particular version of Hibernate and make sure the name of the class is correct.

As far as I know the latest version of Hibernate 3.0, the package names have been changed from net..... to org....

Bala
That is because you forgot the new operator before the BigInteger. Here is the code that works:

package test;

import java.math.*;

class BigIntTest
{
private String sBigI = new String("12345");
public BigInteger aBigInt = new BigInteger(sBigI); // line 6

public static void main(String args[]) {
BigIntTest bigIntTest = new BigIntTest();
System.out.println("Test..." + bigIntTest.aBigInt);
}
}
18 years ago
Looks like you are trying to find an equivalent for a function pointer. Since you have not given any background information about your application, it is difficult to say whether you are abusing reflection or not.

For an indepth discussion of this issue, go to : http://www.javaworld.com/javatips/jw-javatip68_p.html
18 years ago
Check out Lucene. It is an open-source, high-performance, full-featured text search engine written in Java. It can used for any application that requires full-text search.
18 years ago
Sounds like some class loader issue. You might find this article helpful :

http://www-128.ibm.com/developerworks/java/library/j-onejar/
18 years ago
Once you parse the CSV, you can convert the Java objects to xml using open source Castor or any other tools that will bind Java objects to XML.
18 years ago
Parsing CSV files in 5 minutes or less!!!

CsvJdbc - an Open Source JDBC driver for CSV files Rocks!

I was looking for an utility which can read and parse the CSV files. The open source utility CsvJdbc was perfect for my requirements. It parses the given CSV file with no problem. Just include the csvjdbc.jar in the classpath and start using the API. The command line argument is C:\\test (Java requires the escape character \ for the \, which is the separator). The filename is anything.csv and is stored in the directory specified above. Version is Version 0.10.
The documentation says :
The driver also now supports scrollable result sets.
This following example code shows how these are used.
...

Connection conn = Drivermanager.getConnection("jdbc:relique:csv:" + args[0],props)

Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, 0);

ResultSet results = stmt.executeQuery("SELECT ID,NAME FROM sample");

resulst.next();
...
results.first();
...
results.previous();
...
results.relative(2);
...
results.absolute(2);
...
But it looks like it is not implemented yet. I got : Oops-> java.lang.UnsupportedOperationException: ResultSet.relative() unsupported error message.

Here is the modified example program that I am using for my purposes:

/*
* Created on Dec 16, 2004
* @author BXParanj
*/
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class RegistrationParser {
private String userName;
private String password;

public RegistrationParser(String fileName) {

}

public static void main(String[] args) {

String index = "fcgp001";
try
{
// load the driver into memory
Class.forName("org.relique.jdbc.csv.CsvDriver");

// create a connection. The first command line parameter is assumed to
// be the directory in which the .csv files are held
Connection conn = DriverManager.getConnection("jdbc:relique:csv:" + args[0] );

// create a Statement object to execute the query with
Statement stmt = conn.createStatement();

// Select the EBK_USERNAME and EBK_PASSWORD columns from lead.csv file

String sqlQuery = "SELECT EBK_USERNAME, EBK_PASSWORD FROM lead WHERE EBK_USERNAME =" + index ;
ResultSet results = stmt.executeQuery(sqlQuery);

// dump out the results
while (results.next())
{
System.out.println("EBK_USERNAME= " + results.getString("EBK_USERNAME") + " EBK_PASSWORD= " + results.getString("EBK_PASSWORD"));
}

// clean up
results.close();
stmt.close();
conn.close();
}
catch(Exception e)
{
System.out.println("Oops-> " + e);
}
}
}
18 years ago
I would check out Rational tools to do the reverse engineering. Rational Rational Rose by Wendy and Micheal Boggs is a good book. There is a recent version : Mastering Rational XDE.

I am not sure if doing reverse engineering is a good way to learn sequence diagrams.

Originally posted by Jim Tovar:
Thanks Stan, do you know if the jakarta validator project has uml documentation online? Just to save me a lot of work by looking directly to the design and not searching through all the code.

I�m giving a look to the sapia - vlad project� Does any one knows anything about it?



I think Filters and Pipes is an overkill for your problem. Commons Validator is good enough. Just look at the example that comes along with the documentation. It's pretty straightforward. I would define an interface for retrieving the error related information for both the web interface and the batch loader.