synchronize singleton constructor static getInstance method. dangerous otherwise
[mir.git] / source / mircoders / storage / DatabaseBreaking.java
1 package mircoders.storage;
2
3 import java.lang.*;
4 import java.sql.*;
5 import java.io.*;
6 import java.util.*;
7
8 import freemarker.template.*;
9
10 import mir.storage.*;
11 import mir.entity.*;
12 import mir.misc.*;
13
14 /**
15  * <b>Diese Klasse implementiert die Datenbankverbindung zur MetaObjekt-Tabelle
16  *
17  *
18  */
19
20 public class DatabaseBreaking extends Database implements StorageObject{
21
22   private static DatabaseBreaking instance;
23
24   // the following *has* to be sychronized cause this static method
25   // could get preemted and we could end up with 2 instances of DatabaseFoo..
26   // see the "Singletons with needles and thread" article at JavaWorld -mh
27   public synchronized static DatabaseBreaking getInstance() 
28     throws StorageObjectException {
29     if (instance == null) {
30       instance = new DatabaseBreaking();
31       instance.myselfDatabase = instance;
32     }
33     return instance;
34   }
35
36   private DatabaseBreaking() throws StorageObjectException
37   {
38     super();
39     //this.cache = new DatabaseCache(4);
40     this.theTable="breaking";
41     try {
42       this.theEntityClass = Class.forName("mircoders.entity.EntityBreaking");
43     }
44     catch (Exception e) { throw new StorageObjectException(e.toString()); }
45   }
46
47
48 }