Package uk.co.sculptor.kflibjava
Class Database
java.lang.Object
uk.co.sculptor.kflibjava.Database
- All Implemented Interfaces:
AutoCloseable
Represents the Database object and is the basic object needed to create KeyedFiles.
Note: This class implements theAutoCloseable
interface, meaning that an object may hold resources
(such as file or socket handles) until it is closed. The close() method of an AutoCloseable object is called automatically
when exiting a try-with-resources
block for which the object has been declared in the resource specification header.
This construction ensures prompt release, avoiding resource exhaustion exceptions and errors that may otherwise occur.- Author:
- Marcos Gutierrez Batz
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Database flag enumerationstatic enum
Database mirror flag enumerationstatic enum
Database type enumeration -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close all KeyedFiles hanging from the database and then close the database.Return the Database databaseNamegetFlags()
Return the Database flagsReturn the Database mirrorDatabaseReturn the Database servergetType()
Return the Database typeboolean
Return the Database mirrorOnServervoid
Stop a mirror operation on the current Databasevoid
Start a mirror operationvoid
mirrorTo
(Database targetDatabase, EnumSet<Database.MirrorFlag> mirrorFlags, String logFile) Start a mirror operationopenTable
(String fileName, KeyedFile.Mode mode) Creates aKeyedFile
object.openTable
(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options) Creates aKeyedFile
object.openTable
(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options, String dotdFile) Creates aKeyedFile
object.openTable
(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options, KeyedFile sourceKeyedFile) Creates aKeyedFile
object.
-
Method Details
-
close
Close all KeyedFiles hanging from the database and then close the database.- Specified by:
close
in interfaceAutoCloseable
- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol or any operation.
-
getDatabaseName
Return the Database databaseName- Returns:
- the databaseName
-
getFlags
Return the Database flags- Returns:
- the flags
-
getMirrorDatabase
Return the Database mirrorDatabase- Returns:
- the mirrorDatabase
-
getServer
Return the Database server- Returns:
- the server
-
getType
Return the Database type- Returns:
- the type
-
isMirrorOnServer
public boolean isMirrorOnServer()Return the Database mirrorOnServer- Returns:
- the mirrorOnServer
-
mirrorStop
Stop a mirror operation on the current Database- Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol or mirror operation.
-
mirrorTo
Start a mirror operation- Parameters:
targetDatabase
- The mirror database- Throws:
IOException
- If an I/O error occurs when using the socketKfException
- Any error on the KfServer protocol.
-
mirrorTo
public void mirrorTo(Database targetDatabase, EnumSet<Database.MirrorFlag> mirrorFlags, String logFile) throws IOException, KfException Start a mirror operation- Parameters:
targetDatabase
- The mirror databasemirrorFlags
-Database.MirrorFlag
for special settings on mirror.logFile
- The log file to create (empty string if none)- Throws:
IOException
- If an I/O error occurs when using the socketKfException
- Any error on the KfServer protocol.
-
openTable
Creates aKeyedFile
object. It uses the **RECREATE**KeyedFile.Option
, meaning the Keyed file will be recreated- Parameters:
fileName
- The Keyed File filenamemode
- Keyed File open mode (seeKeyedFile.Mode
)- Returns:
- The requested table represented by a
KeyedFile
object - Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
openTable
public KeyedFile openTable(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options) throws IOException, KfException Creates aKeyedFile
object.- Parameters:
fileName
- The KeyedFile filenamemode
- KeyedFile open mode (seeKeyedFile.Mode
)options
- KeyedFile options (seeKeyedFile.Option
)- Returns:
- The requested table represented by a
KeyedFile
object - Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
openTable
public KeyedFile openTable(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options, KeyedFile sourceKeyedFile) throws IOException, KfException Creates aKeyedFile
object. Using as a source structure the sourceKeyedFile, used when we want to create a KeyedFile as the mirror of sourceKeyedFile.- Parameters:
fileName
- The KeyedFile filenamemode
- KeyedFile open mode (seeKeyedFile.Mode
)options
- KeyedFile options (seeKeyedFile.Option
)sourceKeyedFile
- the KeyedFile to use to extract the structure (in place of the dotd file).- Returns:
- The requested table represented by a
KeyedFile
object - Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-
openTable
public KeyedFile openTable(String fileName, KeyedFile.Mode mode, EnumSet<KeyedFile.Option> options, String dotdFile) throws IOException, KfException Creates aKeyedFile
object.- Parameters:
fileName
- The KeyedFile filenamemode
- KeyedFile open mode (seeKeyedFile.Mode
)options
- KeyedFile options (seeKeyedFile.Option
)dotdFile
- The ".d" file on the server or local (USE_LOCAL_DOT_DKeyedFile.Option
case) to use- Returns:
- The requested table represented by a
KeyedFile
object - Throws:
IOException
- Any error received by writing/reading the socket.KfException
- Any error on the KfServer protocol.
-