Laurent Leonard

Ranch Hand
+ Follow
since May 15, 2001
Merit badge: grant badges
For More
Belgium, Namur
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Laurent Leonard

Let's say that AspectJ is a tool allowing you to remove all the glue in your code.

Instead of having


you could have

and some instruction in AspectJ telling that for the method sayHello, you must call the method debug from the logger


Your code stays clean.
And you could do that for all the plumbing stuffs like Transaction, logging, measures, security.
15 years ago
Sometimes the words "design patterns" are misused.
When you choose the architecture of the application, you could use Architectural patterns (Active repository, Layering, Pipes and filters, ...)
When you design the application, you could use GRASP Pattern (Creator, my Creator is my saver, Low coupling, ...)
When you implement the application, you could use implementation or design patterns (Gang of four have some patterns, Kent Beck have also some: chain of responsability, proxy, factory method, ...)

Of course there are links between these different patterns.

My favorite books are
- Implementation patterns : Kent Beck (addison-wesley signature series) 160 pages
- Design patterns : Erich Gamm et al (addison-wesley) 400 pages
- Applying UML and patterns : Craig Larman (Prentice Hall) 700 pages
- Patterns of enterprise application architecture : Martin Fowler (addison-wesley signature series) 530 pages


You could use the chain of responsability pattern (gof).
For each block in your if statement, you have a class that check if some conditions are validated, and if it's the case you can execute a statement.
Main -> Handler1 -> Handler2 -> Handler3 -> ... -> HandlerN

The advantages are
- different handlers could be triggered.
- Adding a new Handler is obvious.
- The condition are easier to read because no complex if statement.
- could be implemented in a way that if a statement is executed, the iteration on the chain is stopped

The disadvantage are
- be carefull of overlapping conditions (more than one statement is executed)
- testing could be difficult
Maybe this could help you ?
Documentation on mysql jdbc driver
See the section Un-implemented Functionality.
What did you setup for MS Sql Server 2000 ?
With this procudure, you only installed a library that allow you to connect to MS SQL Server 2000.
After that you have to configure "programmatically" the connection between your application and your MS SQL Server 2000 database.
With an URL liek this one :
jdbc:microsoft:sqlserver://127.0.0.1:1433;SelectMethod=cursor;DatabaseName=myDB
I don't know if it works with mySql but Visio 2000 has a tool to make reverse engineering on db.
It works with Oracle.
I could not respond to this question because I need more info.
Is it on Oracle ?
Is it a inner join = or an outer join =(+)?
You speak of primary key but do you have foreign key ?
Are your indexes created correctly ?
...
Here is a class exemple :
JDBCConnectorFactory.java
package com.lle.dbutils;
import org.apache.log4j.Category;
import org.apache.log4j.Logger;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;

public class JDBCConnectorFactory
{
static Category cat = Logger.getInstance(JDBCConnectorFactory.class.getName());
public static Connection getConnection(String databaseName, boolean autocommit)
{
ResourceBundle properties = null;
Connection connection = null;
String driverName = "";
String url = "";
String username = "";
String password = "";
try
{
properties = PropertyResourceBundle.getBundle("com.lle.databases");
driverName = properties.getString(databaseName + ".drivername");
url = properties.getString(databaseName + ".url");
username = properties.getString(databaseName + ".username");
password = properties.getString(databaseName + ".password");
// Load the JDBC driver
Class.forName(driverName);
// Create a connection to the database
cat.debug("Trying to connect with " + url);
connection = DriverManager.getConnection(url, username, password);
connection.setAutoCommit(autocommit);
cat.debug("Connection done.");
}
catch (ClassNotFoundException e)
{
// Could not find the database driver
cat.error("Class not found : " + driverName);
}
catch (SQLException e)
{
// Could not connect to the database
cat.error("SQL Error during the connection : " + e.getMessage());
}
catch (MissingResourceException mre)
{
// Missing property in the resource file
if (mre.getKey().equals(""))
{
cat.error("Missing resource file : " + mre.getMessage());
}
else
{
cat.error("Missing property (" + mre.getKey() + ") in the resource file : " + mre.getMessage());
}
}
return connection;
}
public static Connection getConnection(String databaseName)
{
return getConnection(databaseName, false);
}
}

Here is the property files

#configuration for Development
oracle.thin.drivername = oracle.jdbc.driver.OracleDriver
oracle.thin.url = jdbc racle:thin:@localhost:1521 ev
oracle.thin.username = scott
oracle.thin.password = tiger
#oracle.oci.drivername = oracle.jdbc.driver.OracleDriver
#oracle.oci.url = jdbc racle ci:scott/tiger@MYSID
#oracle.oci.username = scott
#oracle.oci.password = tiger
sqlserver.thin.drivername = com.microsoft.jdbc.sqlserver.SQLServerDriver
sqlserver.thin.url = jdbc:microsoft:sqlserver://localhost:1433;SelectMethod=cursor;DatabaseName=myDB
sqlserver.thin.username = user
sqlserver.thin.password = password

[ June 17, 2003: Message edited by: Laurent Leonard ]
Try to use MouseListener on components
somewhereInTheInitiationOfTheObject()
{
...
popupListener = new PopupListener(); // defined later
...
}
void addMouseListenerToAllComponents(Component[] comp)
{
if (comp != null)
{
for (int i = 0; i < comp.length; i++)<br /> {<br /> comp[i].addMouseListener(popupListener);<br /> if (comp[i] instanceof Container)<br /> {<br /> Component[] subcomp = ((Container) comp[i]).getComponents();<br /> addMouseListenerToAllComponents(subcomp);<br /> } <br /> } <br /> } <br /> } <br /> void removeMouseListenerFromAllComponents(Component[] comp)<br /> {<br /> if (comp != null)<br /> {<br /> for (int i = 0; i < comp.length; i++)<br /> {<br /> comp[i].removeMouseListener(popupListener);<br /> if (comp[i] instanceof Container)<br /> {<br /> Component[] subcomp = ((Container) comp[i]).getComponents();<br /> removeMouseListenerFromAllComponents(subcomp);<br /> } <br /> } <br /> } <br /> } <br /> // A inner class<br /> class PopupListener extends MouseAdapter<br /> {<br /> public void mousePressed(MouseEvent evt)<br /> {<br /> maybeShowPopup(evt);<br /> } <br /> private void maybeShowPopup(MouseEvent evt)<br /> {<br /> if (evt.getModifiers() == evt.BUTTON3_MASK) // right click<br /> {<br /> // you must test the source of the event <br /> if(evt.getSource() == aLeaf) // a reference to the source<br /> {<br /> popupMenuForLeaf.pack();<br /> int h = (int)popupMenuForLeaf.getPreferredSize().getHeight();<br /> int w = (int)popupMenuForLeaf.getPreferredSize().getWidth();<br /> int x = evt.getX();<br /> int y = evt.getY();<br /> Dimension frameSize = yourFrame.this.getSize(); // or something else<br /> if ((x+w/2) > frameSize.getWidth()/2)<br /> {<br /> x -= w;<br /> }<br /> if ((y+h/2) > frameSize.getHeight()/2)
{
y -= h;
}
popupMenuForLeaf.show(evt.getComponent(), x, y);
}
if(evt.getSource() == aRoot) // for example
{
the other case
}
}
}
}


------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
23 years ago
May I make a remark ?
Extension is not the only way to use an object.
You say I extend the JFrame. Why ?
Does the new class is more specialized than the original ?
If it's the case, ok, let's extend it, but if not, avoid it.
Class A extends JFrame
{
JTable myTable; // to make it accessible in the class A
TableModel myTableModel; // idem
A()
{
super();
// you can use different layouts if you want.
// why not using JTable() instead of an extension of it.
myTable = new JTable();
myTableModel = new MyDataModel(); // extends the TableModel
myTable.setModel(myTableModel);
this.getContentPane().add(myTable);
}
}
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
23 years ago
if you use a JButton try with
- setHorizontalTextPosition
- setVerticalTextPosition
- setHorizontalAlignment (with icon)
- setVerticalAlignment (with icon)
Laurent

------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
23 years ago
Here is an interesting article :
http://developer.java.sun.com/developer/technicalArticles/ALT/RefObj/
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
[This message has been edited by Laurent Leonard (edited September 19, 2001).]
23 years ago
The way you explain your problem makes me quite confused because you come with a solution and not with a problem.
My question is :
WHAT do you want to do and not HOW do you want to do ? Maybe when you'll explain that we can help you.
Do you want to have quick access to data ?
Do you want to sort the data ?
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
[This message has been edited by Laurent Leonard (edited September 19, 2001).]
23 years ago
I've a class with a private member. In this class I create an instance of this class. And I'm quite surpised that I can access the private member through this instance.
Here is the example.
public class MyClass
{
private Object myPrivateMember;
public MyClass()
{
myPrivateMember = new Object();
}
public void createInstance()
{
MyClass instanceOfMyClass;
instanceOfMyClass = new MyClass();
// This is the surprising line because there is no problem
instanceOfMyClass.myPrivateMember = new Object();
}
}
I was thinking that, when a member is private, the only way to access it, is through a so-called set and get method. (These methods access to it via this.thePrivateMember).
Can someone explain me why this is allowed ???
Thanks in advance.

------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
23 years ago
Guess what! You have your answer in your question !!!
try www.dstc.com
When you choose a prefix for a package, it's recommended by sun
to use the address site in the reverse order (without www).
------------------
Laurent Leonard
Laurent.Leonard@advalvas.be
23 years ago