📄 defaultproperties.java
字号:
PREPARE_SYBASE); } /** * Add default properties to the <code>props</code> properties object. * * @param props The properties object. * @return The updated <code>props</code> object, or <code>null</code> * if the <code>serverType</code> property is not set. */ public static Properties addDefaultProperties(final Properties props) { final String serverType = props.getProperty(Messages.get(Driver.SERVERTYPE)); if (serverType == null) { return null; } addDefaultPropertyIfNotSet(props, Driver.TDS, Driver.SERVERTYPE, tdsDefaults); addDefaultPropertyIfNotSet(props, Driver.PORTNUMBER, Driver.SERVERTYPE, portNumberDefaults); addDefaultPropertyIfNotSet(props, Driver.USER, USER); addDefaultPropertyIfNotSet(props, Driver.PASSWORD, PASSWORD); addDefaultPropertyIfNotSet(props, Driver.DATABASENAME, DATABASE_NAME); addDefaultPropertyIfNotSet(props, Driver.INSTANCE, INSTANCE); addDefaultPropertyIfNotSet(props, Driver.DOMAIN, DOMAIN); addDefaultPropertyIfNotSet(props, Driver.APPNAME, APP_NAME); addDefaultPropertyIfNotSet(props, Driver.PROGNAME, PROG_NAME); addDefaultPropertyIfNotSet(props, Driver.WSID, WSID); addDefaultPropertyIfNotSet(props, Driver.BATCHSIZE, Driver.SERVERTYPE, batchSizeDefaults); addDefaultPropertyIfNotSet(props, Driver.LASTUPDATECOUNT, LAST_UPDATE_COUNT); addDefaultPropertyIfNotSet(props, Driver.LOBBUFFER, LOB_BUFFER_SIZE); addDefaultPropertyIfNotSet(props, Driver.LOGINTIMEOUT, LOGIN_TIMEOUT); addDefaultPropertyIfNotSet(props, Driver.MACADDRESS, MAC_ADDRESS); addDefaultPropertyIfNotSet(props, Driver.MAXSTATEMENTS, MAX_STATEMENTS); addDefaultPropertyIfNotSet(props, Driver.NAMEDPIPE, NAMED_PIPE); addDefaultPropertyIfNotSet(props, Driver.PACKETSIZE, Driver.TDS, packetSizeDefaults); addDefaultPropertyIfNotSet(props, Driver.CACHEMETA, CACHEMETA); addDefaultPropertyIfNotSet(props, Driver.CHARSET, CHARSET); addDefaultPropertyIfNotSet(props, Driver.LANGUAGE, LANGUAGE); addDefaultPropertyIfNotSet(props, Driver.PREPARESQL, Driver.SERVERTYPE, prepareSQLDefaults); addDefaultPropertyIfNotSet(props, Driver.SENDSTRINGPARAMETERSASUNICODE, USE_UNICODE); addDefaultPropertyIfNotSet(props, Driver.TCPNODELAY, TCP_NODELAY); addDefaultPropertyIfNotSet(props, Driver.XAEMULATION, XAEMULATION); addDefaultPropertyIfNotSet(props, Driver.LOGFILE, LOGFILE); addDefaultPropertyIfNotSet(props, Driver.SSL, SSL); addDefaultPropertyIfNotSet(props, Driver.USECURSORS, USECURSORS); addDefaultPropertyIfNotSet(props, Driver.BUFFERMAXMEMORY, BUFFER_MAX_MEMORY); addDefaultPropertyIfNotSet(props, Driver.BUFFERMINPACKETS, BUFFER_MIN_PACKETS); addDefaultPropertyIfNotSet(props, Driver.USELOBS, USELOBS); return props; } /** * Sets a default property if the property is not already set. * * @param props The properties object. * @param key The message key to set. * @param defaultValue The default value to set. */ private static void addDefaultPropertyIfNotSet( final Properties props, final String key, final String defaultValue) { final String messageKey = Messages.get(key); if (props.getProperty(messageKey) == null) { props.setProperty(messageKey, defaultValue); } } /** * Sets a default property if the property is not already set, using * the <code>defaultKey</code> and the <code>defaults</code> map to * determine the correct value. * * @param props The properties object. * @param key The message key to set. * @param defaultKey The key whose value determines which default * value to set from <code>defaults</code>. * @param defaults The mapping of <code>defaultKey</code> values to * the correct <code>key</code> value to set. */ private static void addDefaultPropertyIfNotSet( final Properties props, final String key, final String defaultKey, final Map defaults) { final String defaultKeyValue = props.getProperty(Messages.get(defaultKey)); if (defaultKeyValue == null) { return; } final String messageKey = Messages.get(key); if (props.getProperty(messageKey) == null) { final Object defaultValue = defaults.get(defaultKeyValue); if (defaultValue != null) { props.setProperty(messageKey, String.valueOf(defaultValue)); } } } /** * Converts an integer server type to its string representation. * * @param serverType the server type as an <code>int</code> * @return the server type as a string if known, or <code>null</code> if unknown */ public static String getServerType(int serverType) { if (serverType == Driver.SQLSERVER) { return SERVER_TYPE_SQLSERVER; } else if (serverType == Driver.SYBASE) { return SERVER_TYPE_SYBASE; } return null; } /** * Converts a string server type to its integer representation. * * @param serverType the server type as a string * @return the server type as an integer if known or <code>null</code> if * unknown */ public static Integer getServerType(String serverType) { if (DefaultProperties.SERVER_TYPE_SQLSERVER.equals(serverType)) { return new Integer(Driver.SQLSERVER); } else if (DefaultProperties.SERVER_TYPE_SYBASE.equals(serverType)) { return new Integer(Driver.SYBASE); } return null; } /** * Same as {@link #getServerType(int)}, only it returns the default server * type (<code>"sqlserver"</code>) if <code>serverType</code> is 0. * * @param serverType integer server type or 0 for default * @return the server type as a string if known or <code>"sqlserver"</code> * if unknown */ public static String getServerTypeWithDefault(int serverType) { if (serverType == 0) { return DefaultProperties.SERVER_TYPE_SQLSERVER; } else if (serverType == Driver.SQLSERVER || serverType == Driver.SYBASE) { return getServerType(serverType); } else { throw new IllegalArgumentException( "Only 0, 1 and 2 accepted for serverType"); } } /** * Converts a string TDS version to its integer representation. * * @param tdsVersion The TDS version as a string. * @return The TDS version as an integer if known, or <code>null</code> if unknown. */ public static Integer getTdsVersion(String tdsVersion) { if (DefaultProperties.TDS_VERSION_42.equals(tdsVersion)) { return new Integer(Driver.TDS42); } else if (DefaultProperties.TDS_VERSION_50.equals(tdsVersion)) { return new Integer(Driver.TDS50); } else if (DefaultProperties.TDS_VERSION_70.equals(tdsVersion)) { return new Integer(Driver.TDS70); } else if (DefaultProperties.TDS_VERSION_80.equals(tdsVersion)) { return new Integer(Driver.TDS80); } return null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -