This is for the concept.
So import statements/package statements have been avoided. Also only the necessary methods are given.
Search **** for the comments
Courtesy Effective Java by Joshua Bloch http://www.janeve.me/articles/class-...-getconnection - /* ******Service interface */
-
public interface Connection {
-
... //***** Service-specific methods go here
-
}
-
-
/* ****** Following class implements a connection
-
of a particular DriverImpl */
-
public class ConnectionImpl implements Connection{
-
}
-
-
/* ******Service provider interface */
-
public interface Driver {
-
Connection getConnection() throws SqlException;
-
public boolean acceptsURL(String url);
-
-
}
-
-
/* ****** Following class is a Driver implementation provided by a particular DataBase vendor. The static
-
block is executed whenever class.forName(...) is called.*/
-
public class DriverImpl implements Driver {
-
static {
-
-
try {
-
-
DriverManager.registerDriver(new Driver());
-
-
} catch (SQLException E) {
-
-
throw new RuntimeException("Can't register driver!");
-
-
}
-
-
}
-
-
private Connection getConnection()throws SQLException{
-
......
-
}
-
-
public boolean acceptsURL(String url){
-
......
-
}
-
-
}
-
-
-
-
-
-
/* ******Noninstantiable class for service registration and access */
-
public class DriverManager {
-
private DriverManager() { } // Prevents instantiation
-
// Stores service instances of Drivers
-
private static final Set<Driver> drivers = new ConcurrentHashSet<Driver>();
-
-
-
-
-
/**** This method is called in the static block defined
-
in the Driver class */
-
public static void registerDriver(Driver p){
-
drivers.put(p);
-
}
-
-
-
-
-
-
/*** The getConnection method which is called by our client code. This method calls getDriver() method */
-
public Connection getConnection(String url,....) throws SqlException{
-
Driver d = getDriver(url);
-
return d.getConnection();
-
-
}
-
-
private Driver getDriver(String url) throws SQLException{
-
-
Iterator<Driver> itr = drivers.iterator();
-
Driver d = null;
-
while(itr.hasNext()){
-
d = itr.next();
-
if ( d.acceptsURL(url) )
-
return d;
-
}
-
-
}
-
throw new SQLException("No driver found for " + url);
-
}
-
-
}
6 4621 zmbd 5,501
Recognized Expert Moderator Expert
I have the following issues with this article:
1)
This is for the concept.
What does this mean?
An insight article is, IMHO, not the place to be working on proof of concept.
2)
So import statements/package statements have been avoided.
These "important statements" may very well be what a person seeking help on how to implement a DriverManager Class needs to understand. Insight articles are supposed to be where the details of a concept are explained, or at least, like an expanded help file.
3)
Also only the necessary methods are given.
…and without some explanation of what these are, they are not really helpful to the novice programmer.
4)
Search **** for the comments
…and the comments made in the code are not much to work with.
5)
Courtesy Effective Java by Joshua Bloch http://www.janeve.me/articles/class-...-getconnection
IMNHO: An insight article should not rely on an outside link to provide the "meat and potatos" of the information.
Worse yet, your link isn't even available to me and many like me as it is a blog site which is blocked by my work: Access Denied (policy_denied) Oops! Sorry, access is denied to the requested URL: http://www.janeve.me/articles/class-...-getconnection due to Category: Blogs/Personal Pages (Computers/Internet;Blogs/Personal Pages)
Username: <redacted> / IP Address: 10.<redacted>
The page you attempted to access is unrated or categorized in a manner that requires additional access. If unrated, please <redacted> to submit site for review. For other assistance, contact the IT Support Center at +1 <redacted> or <redacted>.co m. When notifying the Support Center include the category reported for the site you are trying to access.
SO I must "assume" that there is something there worth reading; however, not valuable enough that my IT departement thought it worth letting thru the bloging filter.
sankar2011, you did a much better job here Weak HashMap Summarized
Hi ZMBD,
Thanks for your constructive criticism.
1> I actually concentrated on the design principles followed for implementing this.
2> I emphasized on the the basic flow of DriverManager registration and getting connection.
I omitted the methods to make it simpler. Because one who gets the basic concept he may very well look into the original DriverManager code. This article will help him/her to understand the full implementation.
Regards
zmbd 5,501
Recognized Expert Moderator Expert
sankar2011:
Thank you taking the time to reply.
I read thru your other articles and found them to be fairly well done... and well... I guess expecting the same writing styles as the others so I was somewhat disapointed when I read this one.
I omitted the methods to make it simpler. Because one who gets the basic concept he may very well look into the original DriverManager code. This article will help him/her to understand the full implementation.
Ah, yes, and the article is not available to me (nor do I expect many others) when working from the business/enterprise computers. Companies just simply block most blogs.
Perhaps you could paraphrase what is in the link and add that informtion to the end. IMHO, having that information available within the article would make this article so much better for the novice. Furthermore, should that blog suddenly die, or the author for somereason kills the linked to article, your work would still have a great deal of value.
sankar2011:
I am also disappointed. Please try to improve your work.
Especially comments like this: - /*** The getConnection method which is called by our client code. This method calls getDriver() method */
-
public Connection getConnection(String url,....) throws SqlException{
-
Driver d = getDriver(url);
-
return d.getConnection();
-
}
This comment is redundant and adds no additional information.
It is like writing: - /*** The gnod method which is called by our client code. This method calls x() method */
-
public int gnod(){
-
float x = x();
-
return (int) x * 7;
-
}
But what the comment should really have been is:
"This method returns the number of days that is left for your credit card. It uses method x() to internally evaluate the number of weeks your credit card is valid"
And a better comment, because you don't care about the internals and you know it's a method: "Return number of days left until your credit card becomes invalid."
Ok. :-)
I will definitely remember this. Thank you for taking time to go through my articles. This was written keeping in mind about a novice programmer. But yet. I really take this positively and remember this. Cheers!
zmbd 5,501
Recognized Expert Moderator Expert
sankar2011
I am so glad that you are taking these comments in the spirit intended!
About the novice... I quite often refer the novice to these articles - just because these articles are usually very well written and SOOOOOOOOOOO much better than the almost less than worthless use of bandwidth that most help files have become.
Therefore, what you and others have done by writing these articles is extremely valuable to everyone!
THANK YOU
For taking the time and making the effort to work on these documents.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Choubey |
last post by:
hi everybody,
Iam a java programmer actually i want to know how the Connection
object is created through DriverManager.getConnection when
DriverManager class is not implements Connection interface and no class
in java implementas interface connection so how can we get a object
reference for connection object and call a getconnection method...
|
by: Vince |
last post by:
Hi,
I have a templated class implemented in one file called CDynWnd.h
and declared like this :
CDynWnd.h (declaration and implementation)
------------
template <class BASECLASS> class CDynWnd : public BASECLASS
|
by: Boaz Ben-Porat |
last post by:
I heard somewhere that the DataGrid class is implemented as a XML graph in
memory. Is this true ?
TIA
Boaz Ben-Porat
DataPharm a/s
Denmark
|
by: David A. Osborn |
last post by:
I have a set of classes that each have an enumeration in them, and based on
dynamic input I need to access a different enumeration. For example
Three classes Class_A, Class_B, and Class_C that all have a different
enumeration in them called Properties. I want to basically have a variable
The_Class that I can dynamically point to either...
|
by: Ahmad Jalil Qarshi |
last post by:
Hi!
I have two different applications First one is a Windows Form application
and other is a Windows Service both developed in C#.
Now I have a class named "ClassInWindowsApp" implemented in the namespace of
Windows Form application.
Simililarly another class named "ClassInServiceApp" is implemented in the
namespace of Windows Service...
| |
by: mark.moore |
last post by:
I know this has been asked before, but I just can't find the answer in
the sea of hits...
How do you forward declare a class that is *not* paramaterized, but is
based on a template class?
Here's what I thought should work, but apparently doesn't:
class Foo;
void f1(Foo* p)
|
by: arun |
last post by:
Hello Group,
I have a class A, which has three other members and each member is of a
different class
type.
If I don't create a destructor then the compiler will give me one and
whenever class A is
destroyed (whether on stack or on heap) the destructor of each
different object will be called.
|
by: arun |
last post by:
Hello Group,
The compiler generated destructor will invoke destructor of each member
of the containing
class let us say 'class A'. However, if I write my own destructor for
class A like;
class Object1 {
|
by: Hamilton Woods |
last post by:
Diehards,
I developed a template matrix class back around 1992 using Borland C++ 4.5
(ancestor of C++ Builder) and haven't touched it until a few days ago. I
pulled it from the freezer and thawed it out. I built a console app using
Microsoft Visual C++ 6 (VC++) and it worked great. Only one line in the
header file had to be commented out....
|
by: tonytech08 |
last post by:
How valuable is it that class objects behave like built-in types? I
appears that the whole "constructor doesn't return a value because
they are called by the compiler" thing is to enable built-in-like
behavior for objects of class type. That leads to the "necessity" for
the exception machinery so that errors from constructors can be
handled....
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |