473,545 Members | 2,451 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How a DriverManager class is implemented

18 New Member
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


Expand|Select|Wrap|Line Numbers
  1. /* ******Service interface  */
  2. public interface Connection {
  3. ... //***** Service-specific methods go here
  4. }
  5.  
  6. /* ******  Following class implements a connection
  7. of a particular DriverImpl */
  8. public class ConnectionImpl implements Connection{
  9. }
  10.  
  11. /* ******Service provider interface */
  12. public interface Driver {
  13.     Connection getConnection() throws SqlException; 
  14.         public boolean acceptsURL(String url);
  15.  
  16. }
  17.  
  18. /* ****** Following class is a Driver implementation provided by a particular DataBase vendor. The static
  19. block is executed whenever class.forName(...) is called.*/
  20. public class DriverImpl implements Driver {
  21.     static {
  22.  
  23.             try {
  24.  
  25.                 DriverManager.registerDriver(new Driver());
  26.  
  27.             } catch (SQLException E) {
  28.  
  29.                 throw new RuntimeException("Can't register driver!");
  30.  
  31.             }
  32.  
  33.     }
  34.  
  35. private Connection getConnection()throws SQLException{
  36. ......
  37. }
  38.  
  39. public boolean acceptsURL(String url){
  40. ......
  41. }
  42.  
  43. }
  44.  
  45.  
  46.  
  47.  
  48.  
  49. /* ******Noninstantiable class for service registration and access */
  50. public class DriverManager {
  51. private DriverManager() { } // Prevents instantiation 
  52. // Stores service instances of Drivers
  53. private static final Set<Driver> drivers = new ConcurrentHashSet<Driver>();
  54.  
  55.  
  56.  
  57.  
  58. /****  This method is called in the static block defined 
  59. in the Driver class  */
  60. public static void registerDriver(Driver p){
  61.     drivers.put(p);
  62. }
  63.  
  64.  
  65.  
  66.  
  67.  
  68. /*** The getConnection method which is called by our client code. This method calls getDriver() method */
  69. public Connection getConnection(String url,....) throws SqlException{
  70.     Driver d = getDriver(url);
  71.     return d.getConnection();    
  72.  
  73. }
  74.  
  75. private Driver getDriver(String url) throws SQLException{
  76.  
  77.     Iterator<Driver> itr = drivers.iterator();
  78.     Driver d = null;    
  79.     while(itr.hasNext()){
  80.         d = itr.next();
  81.         if ( d.acceptsURL(url) ) 
  82.             return d;
  83.     }
  84.  
  85.   }
  86.   throw new SQLException("No driver found for " + url);
  87. }
  88.  
  89. }
Sep 9 '13 #1
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
Sep 12 '13 #2
sankar2011
18 New Member
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
Sep 12 '13 #3
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.
Sep 13 '13 #4
chaarmann
785 Recognized Expert Contributor
sankar2011:
I am also disappointed. Please try to improve your work.

Especially comments like this:
Expand|Select|Wrap|Line Numbers
  1.  /*** The getConnection method which is called by our client code. This method calls getDriver() method */
  2. public Connection getConnection(String url,....) throws SqlException{
  3.     Driver d = getDriver(url);
  4.     return d.getConnection();    
  5. }
This comment is redundant and adds no additional information.
It is like writing:
Expand|Select|Wrap|Line Numbers
  1.  /*** The gnod method which is called by our client code. This method calls x() method */
  2. public int gnod(){
  3.     float x = x();
  4.     return (int) x * 7;    
  5. }
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."
Sep 13 '13 #5
sankar2011
18 New Member
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!
Sep 13 '13 #6
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.
Sep 13 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4654
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...
1
2067
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
6
2660
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
9
2211
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...
0
1222
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...
23
3820
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)
2
3939
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.
2
2052
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 {
3
3743
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....
55
3926
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....
0
7487
marktang
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...
0
7934
jinu1996
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...
0
7778
tracyyun
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...
0
6003
agi2029
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...
1
5349
isladogs
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...
0
4966
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...
0
3459
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1908
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
0
731
bsmnconsultancy
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.