Package org.h2.engine
Class ConnectionInfo
- java.lang.Object
-
- org.h2.engine.ConnectionInfo
-
- All Implemented Interfaces:
java.lang.Cloneable
public class ConnectionInfo extends java.lang.Object implements java.lang.CloneableEncapsulates the connection settings, including user name and password.
-
-
Field Summary
Fields Modifier and Type Field Description private byte[]fileEncryptionKeyprivate byte[]filePasswordHashprivate static java.util.HashSet<java.lang.String>IGNORED_BY_PARSERprivate static java.util.HashSet<java.lang.String>KNOWN_SETTINGSprivate java.lang.StringnameThe database nameprivate java.lang.StringnameNormalizedprivate NetworkConnectionInfonetworkConnectionInfoprivate java.lang.StringoriginalURLprivate booleanpersistentprivate java.util.Propertiespropprivate booleanremoteprivate booleansslprivate TimeZoneProvidertimeZoneprivate booleanunnamedprivate java.lang.Stringurlprivate java.lang.Stringuserprivate byte[]userPasswordHash
-
Constructor Summary
Constructors Constructor Description ConnectionInfo(java.lang.String name)Create a connection info object.ConnectionInfo(java.lang.String u, java.util.Properties info, java.lang.String user, java.lang.Object password)Create a connection info object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanAuthenticationInfo()Clear authentication properties.ConnectionInfoclone()private voidconvertPasswords()Split the password property into file password and user password if necessary, and convert them to the internal hash format.DbSettingsgetDbSettings()(package private) byte[]getFileEncryptionKey()byte[]getFilePasswordHash()Get the file password hash if it is set.(package private) DbExceptiongetFormatException()Generate a URL format exception.(package private) intgetIntProperty(int setting, int defaultValue)Get the value of the given property.(package private) java.lang.String[]getKeys()Get the property keys.java.lang.StringgetName()Get the unique and normalized database name (excluding settings).NetworkConnectionInfogetNetworkConnectionInfo()Returns the network connection information, ornull.java.lang.StringgetOriginalURL()Get the complete original database URL.(package private) java.lang.StringgetProperty(int setting, java.lang.String defaultValue)Get the value of the given property.(package private) java.lang.StringgetProperty(java.lang.String key)Get the value of the given property.booleangetProperty(java.lang.String key, boolean defaultValue)Get a boolean property if it is set and return the value.(package private) intgetProperty(java.lang.String key, int defaultValue)Get the value of the given property.java.lang.StringgetProperty(java.lang.String key, java.lang.String defaultValue)Get the value of the given property.TimeZoneProvidergetTimeZone()Returns the time zone.java.lang.StringgetURL()Get the database URL.java.lang.StringgetUserName()Get the name of the user.(package private) byte[]getUserPasswordHash()Get the user password hash.private static byte[]hashPassword(boolean passwordHash, java.lang.String userName, char[] password)static booleanisIgnoredByParser(java.lang.String name)Returns whether setting with the specified name should be ignored by parser.private static booleanisKnownSetting(java.lang.String s)booleanisPersistent()Check if the referenced database is persistent.booleanisRemote()Check if this is a remote connection.(package private) booleanisSSL()Check if this is a remote connection with SSL enabled.(package private) booleanisUnnamedInMemory()Check if the referenced database is an unnamed in-memory database.private voidparseName()private voidpreservePasswordForAuthentication(java.lang.Object password)private voidreadProperties(java.util.Properties info)private voidreadSettingsFromURL()private static java.lang.StringremapURL(java.lang.String url)private char[]removePassword()booleanremoveProperty(java.lang.String key, boolean defaultValue)Remove a boolean property if it is set and return the value.(package private) java.lang.StringremoveProperty(java.lang.String key, java.lang.String defaultValue)Remove a String property if it is set and return the value.voidsetBaseDir(java.lang.String dir)Set the base directory of persistent databases, unless the database is in the user home folder (~).voidsetFileEncryptionKey(byte[] key)voidsetFilePasswordHash(byte[] hash)Set the file password hash.voidsetNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)Sets the network connection information.voidsetOriginalURL(java.lang.String url)Set the original database URL.voidsetProperty(java.lang.String key, java.lang.String value)Overwrite a property.voidsetServerKey(java.lang.String serverKey)Switch to server mode, and set the server name and database key.voidsetUserName(java.lang.String name)Overwrite the user name.voidsetUserPasswordHash(byte[] hash)Set the user password hash.
-
-
-
Field Detail
-
KNOWN_SETTINGS
private static final java.util.HashSet<java.lang.String> KNOWN_SETTINGS
-
IGNORED_BY_PARSER
private static final java.util.HashSet<java.lang.String> IGNORED_BY_PARSER
-
prop
private java.util.Properties prop
-
originalURL
private java.lang.String originalURL
-
url
private java.lang.String url
-
user
private java.lang.String user
-
filePasswordHash
private byte[] filePasswordHash
-
fileEncryptionKey
private byte[] fileEncryptionKey
-
userPasswordHash
private byte[] userPasswordHash
-
timeZone
private TimeZoneProvider timeZone
-
name
private java.lang.String name
The database name
-
nameNormalized
private java.lang.String nameNormalized
-
remote
private boolean remote
-
ssl
private boolean ssl
-
persistent
private boolean persistent
-
unnamed
private boolean unnamed
-
networkConnectionInfo
private NetworkConnectionInfo networkConnectionInfo
-
-
Constructor Detail
-
ConnectionInfo
public ConnectionInfo(java.lang.String name)
Create a connection info object.- Parameters:
name- the database name (including tags), but without the "jdbc:h2:" prefix
-
ConnectionInfo
public ConnectionInfo(java.lang.String u, java.util.Properties info, java.lang.String user, java.lang.Object password)Create a connection info object.- Parameters:
u- the database URL (must start with jdbc:h2:)info- the connection properties ornulluser- the user name ornullpassword- the password asStringorchar[], ornull
-
-
Method Detail
-
isKnownSetting
private static boolean isKnownSetting(java.lang.String s)
-
isIgnoredByParser
public static boolean isIgnoredByParser(java.lang.String name)
Returns whether setting with the specified name should be ignored by parser.- Parameters:
name- the name of the setting- Returns:
- whether setting with the specified name should be ignored by parser
-
clone
public ConnectionInfo clone() throws java.lang.CloneNotSupportedException
- Overrides:
clonein classjava.lang.Object- Throws:
java.lang.CloneNotSupportedException
-
parseName
private void parseName()
-
setBaseDir
public void setBaseDir(java.lang.String dir)
Set the base directory of persistent databases, unless the database is in the user home folder (~).- Parameters:
dir- the new base directory
-
isRemote
public boolean isRemote()
Check if this is a remote connection.- Returns:
- true if it is
-
isPersistent
public boolean isPersistent()
Check if the referenced database is persistent.- Returns:
- true if it is
-
isUnnamedInMemory
boolean isUnnamedInMemory()
Check if the referenced database is an unnamed in-memory database.- Returns:
- true if it is
-
readProperties
private void readProperties(java.util.Properties info)
-
readSettingsFromURL
private void readSettingsFromURL()
-
preservePasswordForAuthentication
private void preservePasswordForAuthentication(java.lang.Object password)
-
removePassword
private char[] removePassword()
-
convertPasswords
private void convertPasswords()
Split the password property into file password and user password if necessary, and convert them to the internal hash format.
-
hashPassword
private static byte[] hashPassword(boolean passwordHash, java.lang.String userName, char[] password)
-
getProperty
public boolean getProperty(java.lang.String key, boolean defaultValue)Get a boolean property if it is set and return the value.- Parameters:
key- the property namedefaultValue- the default value- Returns:
- the value
-
removeProperty
public boolean removeProperty(java.lang.String key, boolean defaultValue)Remove a boolean property if it is set and return the value.- Parameters:
key- the property namedefaultValue- the default value- Returns:
- the value
-
removeProperty
java.lang.String removeProperty(java.lang.String key, java.lang.String defaultValue)Remove a String property if it is set and return the value.- Parameters:
key- the property namedefaultValue- the default value- Returns:
- the value
-
getName
public java.lang.String getName()
Get the unique and normalized database name (excluding settings).- Returns:
- the database name
-
getFilePasswordHash
public byte[] getFilePasswordHash()
Get the file password hash if it is set.- Returns:
- the password hash or null
-
getFileEncryptionKey
byte[] getFileEncryptionKey()
-
getUserName
public java.lang.String getUserName()
Get the name of the user.- Returns:
- the user name
-
getUserPasswordHash
byte[] getUserPasswordHash()
Get the user password hash.- Returns:
- the password hash
-
getKeys
java.lang.String[] getKeys()
Get the property keys.- Returns:
- the property keys
-
getProperty
java.lang.String getProperty(java.lang.String key)
Get the value of the given property.- Parameters:
key- the property key- Returns:
- the value as a String
-
getProperty
int getProperty(java.lang.String key, int defaultValue)Get the value of the given property.- Parameters:
key- the property keydefaultValue- the default value- Returns:
- the value as a String
-
getProperty
public java.lang.String getProperty(java.lang.String key, java.lang.String defaultValue)Get the value of the given property.- Parameters:
key- the property keydefaultValue- the default value- Returns:
- the value as a String
-
getProperty
java.lang.String getProperty(int setting, java.lang.String defaultValue)Get the value of the given property.- Parameters:
setting- the setting iddefaultValue- the default value- Returns:
- the value as a String
-
getIntProperty
int getIntProperty(int setting, int defaultValue)Get the value of the given property.- Parameters:
setting- the setting iddefaultValue- the default value- Returns:
- the value as an integer
-
isSSL
boolean isSSL()
Check if this is a remote connection with SSL enabled.- Returns:
- true if it is
-
setUserName
public void setUserName(java.lang.String name)
Overwrite the user name. The user name is case-insensitive and stored in uppercase. English conversion is used.- Parameters:
name- the user name
-
setUserPasswordHash
public void setUserPasswordHash(byte[] hash)
Set the user password hash.- Parameters:
hash- the new hash value
-
setFilePasswordHash
public void setFilePasswordHash(byte[] hash)
Set the file password hash.- Parameters:
hash- the new hash value
-
setFileEncryptionKey
public void setFileEncryptionKey(byte[] key)
-
setProperty
public void setProperty(java.lang.String key, java.lang.String value)Overwrite a property.- Parameters:
key- the property namevalue- the value
-
getURL
public java.lang.String getURL()
Get the database URL.- Returns:
- the URL
-
getOriginalURL
public java.lang.String getOriginalURL()
Get the complete original database URL.- Returns:
- the database URL
-
setOriginalURL
public void setOriginalURL(java.lang.String url)
Set the original database URL.- Parameters:
url- the database url
-
getTimeZone
public TimeZoneProvider getTimeZone()
Returns the time zone.- Returns:
- the time zone
-
getFormatException
DbException getFormatException()
Generate a URL format exception.- Returns:
- the exception
-
setServerKey
public void setServerKey(java.lang.String serverKey)
Switch to server mode, and set the server name and database key.- Parameters:
serverKey- the server name, '/', and the security key
-
getNetworkConnectionInfo
public NetworkConnectionInfo getNetworkConnectionInfo()
Returns the network connection information, ornull.- Returns:
- the network connection information, or
null
-
setNetworkConnectionInfo
public void setNetworkConnectionInfo(NetworkConnectionInfo networkConnectionInfo)
Sets the network connection information.- Parameters:
networkConnectionInfo- the network connection information
-
getDbSettings
public DbSettings getDbSettings()
-
remapURL
private static java.lang.String remapURL(java.lang.String url)
-
cleanAuthenticationInfo
public void cleanAuthenticationInfo()
Clear authentication properties.
-
-