Fields Summary |
---|
public static final int | OTHER_ENUM |
public static final int | DEFAULT_DB_ENUM |
public static final int | ORACLE_ENUM |
public static final int | POINTBASE_ENUM |
public static final int | MSSQL_ENUM |
public static final int | SYBASE_ENUM |
public static final int | DB2_ENUM |
public static final int | MYSQL_ENUM |
public static final int | INFORMIX_ENUM |
public static final int | INGRES_ENUM |
public static final int | DERBY_ENUM |
public static final int | MAX_KNOWN_DB |
private static final String[] | enumToStringMappingArray that defines mapping from given string name to enum.
Please make sure that array indexes and enum values are kept in sync. |
public static final String | DEFAULT_DB |
public static final String | ORACLE |
public static final String | POINTBASE |
public static final String | MSSQL |
public static final String | SYBASE |
public static final String | DB2 |
public static final String | MYSQL |
public static final String | INFORMIX |
public static final String | INGRES |
public static final String | DERBY |
private static final String | PROPERTY_PATH |
private static final String | VENDOR_NAME_TO_TYPE_PROPERTY |
private static final String | VENDOR_NAME_TO_TYPE_RESOURCE_PROPERTY |
private static final String | VENDOR_NAME_TO_TYPE_RESOURCE_DEFAULT_NAME |
private static final com.sun.jdo.spi.persistence.utility.logging.Logger | loggerThe logger. |
private static Properties | _nameToVendorTypeHolds mapping between possible vendor names to internal types defined above.
vendor names are treated as regular expressions. |
Methods Summary |
---|
public static java.lang.String | getDBType(java.lang.String vendorName)Get Database Vendor Type from vendor name.
boolean debug = logger.isLoggable();
if(debug) {
logger.fine("utility.database.DBVendorTypeHelper.inputVendorName", //NOI18N
vendorName);
}
String detectedDbType = DEFAULT_DB;
if(vendorName != null) {
detectedDbType = matchVendorNameInProperties(vendorName, _nameToVendorType);
//If not able to detect dbType from properties, invent one by
//manipulating input vendorName.
if(detectedDbType == null) {
detectedDbType = vendorName.toUpperCase();
int i = detectedDbType.indexOf('/");
if (i > -1) {
detectedDbType = detectedDbType.substring(0, i);
}
}
}
if(debug)
logger.fine("utility.database.DBVendorTypeHelper.detectedVendorType",detectedDbType); //NOI18N
return detectedDbType;
|
public static int | getEnumDBType(java.sql.DatabaseMetaData metaData)Gets enumerated database type for given metaData
String dbType = getDBType(metaData.getDatabaseProductName());
return getEnumDBType(dbType);
|
public static int | getEnumDBType(java.lang.String dbType)Gets enumerated database type for given dbType
int enumDBType = OTHER_ENUM;
//Search through the array for dbType
for(int i = 0; i < MAX_KNOWN_DB - 1 && enumDBType == OTHER_ENUM; i++) {
if(enumToStringMapping[i].equals(dbType) )
enumDBType = i;
}
return enumDBType;
|
private static java.util.Properties | initializeNameToVendorType()Allocate and initialize nameToVendorType if not already done.
synchronized(DBVendorTypeHelper.class) {
if(_nameToVendorType == null) {
_nameToVendorType = new Properties();
String resourceName = System.getProperty(VENDOR_NAME_TO_TYPE_RESOURCE_PROPERTY,
VENDOR_NAME_TO_TYPE_RESOURCE_DEFAULT_NAME);
try {
PropertyHelper.loadFromResource(_nameToVendorType,resourceName,
DBVendorTypeHelper.class.getClassLoader() );
} catch (IOException e) {
if(logger.isLoggable() ) {
logger.fine("utility.database.DBVendorTypeHelper.couldNotLoadResource", // NOI18N
resourceName,e);
}
}
overrideWithSystemProperties(_nameToVendorType);
}
}
return _nameToVendorType;
|
private static boolean | matchPattern(java.lang.String regExp, java.lang.String target)Matches target to pattern specified regExp. Returns false if there is
any error compiling regExp.
boolean matches = false;
try {
matches = Pattern.matches(regExp,target);
} catch (PatternSyntaxException e){
logger.fine("utility.database.DBVendorTypeHelper.patternSyntaxException",e); // NOI18N
}
return matches;
|
private static java.lang.String | matchVendorNameInProperties(java.lang.String vendorName, java.util.Properties nameToVendorType)Match vendorName in properties specifieid by nameToVendorType.
String dbType = null;
//Iterate over all properties till we find match.
for( Iterator iterator = nameToVendorType.entrySet().iterator();
dbType == null && iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String regExpr = (String) entry.getKey();
String value = (String) entry.getValue();
if(logger.isLoggable(Logger.FINEST) )
logger.finest("utility.database.DBVendorTypeHelper.regExprDbType",regExpr,value); // NOI18N
if( matchPattern(regExpr,vendorName) ) {
dbType = value;
}
}
return dbType;
|
private static void | overrideWithSystemProperties(java.util.Properties nameToVendorType)Overrides nameToVendorType with any system properties defined.
String vendorNameToType = null;
boolean debug = logger.isLoggable();
int counter = 1;
do {
String vendorNameToTypeProperty = VENDOR_NAME_TO_TYPE_PROPERTY + counter++;
vendorNameToType = System.getProperty(vendorNameToTypeProperty);
if(vendorNameToType != null) {
//Split the vendorNameToType into two at char '='
String[] parsedProperty = vendorNameToType.split("=",2); //NOI18N
if( parsedProperty.length >= 2) {
String suggestedDbType = parsedProperty[0];
String regExp = parsedProperty[1];
if(debug) {
logger.fine("utility.database.DBVendorTypeHelper.traceVendorNameToTypeProperty", //NOI18N
vendorNameToTypeProperty,regExp,suggestedDbType);
}
nameToVendorType.put(regExp,suggestedDbType);
}
else {
if(debug)
logger.fine("utility.database.DBVendorTypeHelper.errorParsingVendorNameToTypeProperty", //NOI18N
vendorNameToTypeProperty,vendorNameToType);
}
}
} while (vendorNameToType != null);
|
public static boolean | requireUpperCaseSchema(java.sql.DatabaseMetaData dmd)Determines whether to use uppercase schema name for a give database.
int vendorTypeEnum = getEnumDBType(dmd);
return ORACLE_ENUM == vendorTypeEnum ||
POINTBASE_ENUM == vendorTypeEnum;
|