1 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 33 public class JdbcStorageFactory implements StorageFactory 34 { 35 39 public static final String PROPERTY_PREFIX = 40 "org.netbeans.mdr.persistence.jdbcimpl."; 41 42 public static final String STORAGE_URL = 43 PROPERTY_PREFIX + "url"; 44 45 public static final String STORAGE_SCHEMA_NAME = 46 PROPERTY_PREFIX + "schemaName"; 47 48 public static final String STORAGE_USER_NAME = 49 PROPERTY_PREFIX + "userName"; 50 51 public static final String STORAGE_SCHEMA_AUTH_NAME = 52 PROPERTY_PREFIX + "schemaAuthName"; 53 54 public static final String STORAGE_PASSWORD = 55 PROPERTY_PREFIX + "password"; 56 57 public static final String STORAGE_DRIVER_CLASS_NAME = 58 PROPERTY_PREFIX + "driverClassName"; 59 60 public static final String STORAGE_FIRST_SERIAL_NUMBER = 61 PROPERTY_PREFIX + "firstSerialNumber"; 62 63 public static final String STORAGE_DEBUG_PRINT = 64 PROPERTY_PREFIX + "debugPrint"; 65 66 public static final String STORAGE_QUERY_DUPLICATES = 67 PROPERTY_PREFIX + "queryDuplicates"; 68 69 public static final String STORAGE_DATATYPE_MOFID = 70 PROPERTY_PREFIX + "datatype.mofid"; 71 72 public static final String STORAGE_DATATYPE_STREAMABLE = 73 PROPERTY_PREFIX + "datatype.streamable"; 74 75 public static final String STORAGE_DATATYPE_STRING = 76 PROPERTY_PREFIX + "datatype.string"; 77 78 public static final String STORAGE_DATATYPE_INT = 79 PROPERTY_PREFIX + "datatype.int"; 80 81 private static final String NULL_STORAGE_ID = "j"; 83 private static final MOFID NULL_MOFID = new MOFID(0, NULL_STORAGE_ID); 84 85 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 )) { 93 continue; 94 } 95 if (entry.getValue() == null) { 96 continue; 97 } 98 if (!(entry.getValue() instanceof String )) { 99 continue; 100 } 101 properties.put(entry.getKey(),entry.getValue()); 102 } 103 String url = properties.getProperty(STORAGE_URL); 104 String schemaName = properties.getProperty(STORAGE_SCHEMA_NAME); 105 String 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 ex) { 116 } 119 } 120 return new JdbcStorage(properties,NULL_STORAGE_ID); 121 } 122 123 public MOFID createNullMOFID() throws StorageException 125 { 126 return NULL_MOFID; 127 } 128 } 129 130 | Popular Tags |