Created
February 22, 2018 15:59
-
-
Save mczachurski/416144a2aceae5f01f8e42a8bec85063 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public protocol SqlConnectionProtocol { | |
func getDatabaseConfiguration() -> DatabaseConfigurationProtocol | |
func isValidConnection() -> Bool | |
} | |
class SQLiteConnection : SqlConnectionProtocol { | |
private let connectionString: String | |
private var configuration: SQLiteDatabaseConfiguration? | |
private let lock = NSLock() | |
public func getDatabaseConfiguration() -> DatabaseConfigurationProtocol { | |
if self.configuration != nil && isValidConnection() { | |
return self.configuration! | |
} | |
lock.lock() | |
if self.configuration == nil { | |
self.configuration = try! SQLiteDatabaseConfiguration(connectionString) | |
} | |
lock.unlock() | |
return self.configuration! | |
} | |
init(configuration: Configuration) { | |
self.connectionString = configuration.connectionString | |
} | |
public func isValidConnection() -> Bool { | |
// Here we should verify state of connection. | |
return true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment