KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > mdr > persistence > jdbcimpl > JdbcStorageFactory


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.mdr.persistence.jdbcimpl;
20
21 import org.netbeans.mdr.persistence.*;
22
23 import java.sql.*;
24 import java.util.*;
25
26 /**
27  * JdbcStorageFactory implements the StorageFactory interface by
28  * creating instances of JdbcStorage.
29  *
30  * @author John V. Sichi
31  * @version $Id: JdbcStorageFactory.java,v 1.6 2006/06/30 20:56:10 jtulach Exp $
32  */

33 public class JdbcStorageFactory implements StorageFactory
34 {
35     // NOTE: Property names are defined here without the MDRStorageProperty
36
// prefix; user code should prepend that prefix, which will be stripped off
37
// by MDR before createStorage is called.
38

39     public static final String JavaDoc PROPERTY_PREFIX =
40     "org.netbeans.mdr.persistence.jdbcimpl.";
41     
42     public static final String JavaDoc STORAGE_URL =
43     PROPERTY_PREFIX + "url";
44     
45     public static final String JavaDoc STORAGE_SCHEMA_NAME =
46     PROPERTY_PREFIX + "schemaName";
47
48     public static final String JavaDoc STORAGE_USER_NAME =
49     PROPERTY_PREFIX + "userName";
50
51     public static final String JavaDoc STORAGE_SCHEMA_AUTH_NAME =
52     PROPERTY_PREFIX + "schemaAuthName";
53
54     public static final String JavaDoc STORAGE_PASSWORD =
55     PROPERTY_PREFIX + "password";
56
57     public static final String JavaDoc STORAGE_DRIVER_CLASS_NAME =
58     PROPERTY_PREFIX + "driverClassName";
59
60     public static final String JavaDoc STORAGE_FIRST_SERIAL_NUMBER =
61     PROPERTY_PREFIX + "firstSerialNumber";
62     
63     public static final String JavaDoc STORAGE_DEBUG_PRINT =
64     PROPERTY_PREFIX + "debugPrint";
65     
66     public static final String JavaDoc STORAGE_QUERY_DUPLICATES =
67     PROPERTY_PREFIX + "queryDuplicates";
68     
69     public static final String JavaDoc STORAGE_DATATYPE_MOFID =
70     PROPERTY_PREFIX + "datatype.mofid";
71
72     public static final String JavaDoc STORAGE_DATATYPE_STREAMABLE =
73     PROPERTY_PREFIX + "datatype.streamable";
74
75     public static final String JavaDoc STORAGE_DATATYPE_STRING =
76     PROPERTY_PREFIX + "datatype.string";
77
78     public static final String JavaDoc STORAGE_DATATYPE_INT =
79     PROPERTY_PREFIX + "datatype.int";
80
81     // adapted from memoryimpl
82
private static final String JavaDoc NULL_STORAGE_ID = "j";
83     private static final MOFID NULL_MOFID = new MOFID(0, NULL_STORAGE_ID);
84     
85     // implement StorageFactory
86
public Storage createStorage(Map map) throws StorageException
87     {
88         Properties properties = new Properties();
89         Iterator iter = map.entrySet().iterator();
90         while (iter.hasNext()) {
91             Map.Entry entry = (Map.Entry) iter.next();
92             if (!(entry.getKey() instanceof String JavaDoc)) {
93                 continue;
94             }
95             if (entry.getValue() == null) {
96                 continue;
97             }
98             if (!(entry.getValue() instanceof String JavaDoc)) {
99                 continue;
100             }
101             properties.put(entry.getKey(),entry.getValue());
102         }
103         String JavaDoc url = properties.getProperty(STORAGE_URL);
104         String JavaDoc schemaName = properties.getProperty(STORAGE_SCHEMA_NAME);
105         String JavaDoc driverClassName =
106             properties.getProperty(STORAGE_DRIVER_CLASS_NAME);
107         if (url == null || schemaName == null) {
108             throw new StorageBadRequestException(
109                 "JdbcStorageFactory requires parameters "
110                 + STORAGE_URL + " and " + STORAGE_SCHEMA_NAME);
111         }
112         if (driverClassName != null) {
113             try {
114                 Class.forName(driverClassName);
115             } catch (ClassNotFoundException JavaDoc ex) {
116                 // let driver manager report "no suitable driver" when
117
// the connection is attempted
118
}
119         }
120         return new JdbcStorage(properties,NULL_STORAGE_ID);
121     }
122     
123     // implement StorageFactory
124
public MOFID createNullMOFID() throws StorageException
125     {
126         return NULL_MOFID;
127     }
128 }
129
130 // End JdbcStorageFactory.java
131
Popular Tags