Skip to content

Commit 94f07c7

Browse files
committed
#948 Add getters to BackupManager and allow "use default" to be set
1 parent 867d394 commit 94f07c7

7 files changed

Lines changed: 146 additions & 78 deletions

File tree

src/docs/asciidoc/release_notes.adoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,7 @@ See also https://github.com/FirebirdSQL/jaybird/blob/master/devdoc/jdp/jdp-2026-
688688
* Improvement: Clear warnings on connection close (https://github.com/FirebirdSQL/jaybird/pull/943[#943])
689689
+
690690
This change was contributed by https://github.com/FuriousFourier[FuriousFourier^]
691+
* Improvement: Add getters to BackupManager and allow "`use default`" to be set (https://github.com/FirebirdSQL/jaybird/issues/948[#948])
691692
* ...
692693
693694
[#compatibility-changes]

src/main/org/firebirdsql/management/BackupManager.java

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
*
1818
* @author Roman Rokytskyy
1919
* @author Steven Jardine
20+
* @author Mark Rotteveel
2021
*/
22+
@SuppressWarnings("unused")
2123
public interface BackupManager extends ServiceManager {
2224

2325
/**
@@ -86,7 +88,6 @@ public interface BackupManager extends ServiceManager {
8688
*/
8789
int RESTORE_USE_ALL_SPACE = ISCConstants.isc_spb_res_use_all_space;
8890

89-
9091
/**
9192
* Sets the location of the backup file. This method is used to set the
9293
* path to the backup consisting of a single file. It is not possible to
@@ -200,49 +201,88 @@ public interface BackupManager extends ServiceManager {
200201
* Set whether the operations of this {@code BackupManager} will result in verbose logging to the configured logger.
201202
*
202203
* @param verbose
203-
* If {@code true}, operations will be logged verbosely, otherwise they will not be logged verbosely
204+
* {@code true}, operations will be logged verbosely, otherwise they will not be logged verbosely
205+
* @see #isVerbose()
204206
*/
205207
void setVerbose(boolean verbose);
206208

207209
/**
208-
* Set the default number of pages to be buffered (cached) by default in a
209-
* restored database.
210+
* @return {@code true}, operations will be logged verbosely, otherwise they will not be logged verbosely
211+
* @see #setVerbose(boolean)
212+
* @since 7
213+
*/
214+
boolean isVerbose();
215+
216+
/**
217+
* Set the default number of pages to be buffered (cached) by default in a restored database.
210218
*
211219
* @param bufferCount
212-
* The page-buffer size to be used, a positive value
220+
* page-buffer size to be used, a positive value, or {@code -1} for the value recorded in the backup
221+
* @see #getRestorePageBufferCount()
213222
*/
214223
void setRestorePageBufferCount(int bufferCount);
215224

216225
/**
217-
* Set the page size that will be used for a restored database. The value for {@code pageSize} must be one
218-
* of: 1024, 2048, 4096, 8192 or 16384. The default value depends on the Firebird version.
226+
* @return page-buffer size to be used, or {@code -1} for the value recorded in the backup
227+
* @see #setRestorePageBufferCount(int)
228+
* @since 7
229+
*/
230+
int getRestorePageBufferCount();
231+
232+
/**
233+
* Set the page size that will be used for a restored database. The value for {@code pageSize} must be
234+
* one of {@link PageSizeConstants}. Use {@link PageSizeConstants#USE_DEFAULT} ({@code -1}) for the value recorded
235+
* in the backup.
236+
* <p>
237+
* Be aware that not all page sizes are supported by all Firebird versions.
238+
* </p>
219239
*
220240
* @param pageSize
221-
* The page size to be used in a restored database, one of 1024, 2048, 4196, 8192 or 16384
241+
* page size to be used in a restored database, see {@link PageSizeConstants}
242+
* @see #getRestorePageSize()
222243
* @see PageSizeConstants
223244
*/
224245
void setRestorePageSize(int pageSize);
225246

226247
/**
227-
* Set the restore operation to create a new database, as opposed to
228-
* overwriting an existing database.
248+
* @return page size to be used, or {@code -1} for the value recorded in the backup
249+
* @see #setRestorePageSize(int)
250+
* @since 7
251+
*/
252+
int getRestorePageSize();
253+
254+
/**
255+
* Set the restore operation to create a new database, as opposed to overwriting an existing database.
229256
*
230257
* @param replace
231-
* If {@code true}, the restore operation will attempt to create a new database if it does not exit or
232-
* overwrite an existing one when it exists, {@code false} when restore should fail if database already
233-
* exist (if it doesn't, a database will be successfully created).
258+
* {@code true} drop existing database and overwrite, {@code false} fail if database exists
259+
* @see #isRestoreReplace()
234260
*/
235261
void setRestoreReplace(boolean replace);
236262

263+
/**
264+
* @return {@code true} drop existing database and overwrite, {@code false} fail if database exists
265+
* @see #setRestoreReplace(boolean)
266+
* @since 7
267+
*/
268+
boolean isRestoreReplace();
269+
237270
/**
238271
* Set the read-only attribute on a restored database.
239272
*
240273
* @param readOnly
241-
* If {@code true}, a restored database will be
242-
* read-only, otherwise it will be read-write.
274+
* {@code true} restored database is marked read-only, otherwise it will be read-write
275+
* @see #isRestoreReadOnly()
243276
*/
244277
void setRestoreReadOnly(boolean readOnly);
245278

279+
/**
280+
* @return {@code true} restored database is marked read-only, otherwise it will be read-write
281+
* @see #setRestoreReadOnly(boolean)
282+
* @since 7
283+
*/
284+
boolean isRestoreReadOnly();
285+
246286
/**
247287
* SQL regular expression for the tables to exclude from the backup or restore.
248288
* <p>

src/main/org/firebirdsql/management/FBBackupManagerBase.java

Lines changed: 39 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import static org.firebirdsql.util.FirebirdSupportInfo.supportInfoFor;
2525

2626
/**
27-
* Implements the common functionality between regular and streaming backup/restore
27+
* Implements the common functionality between regular and streaming backup/restore.
2828
*
2929
* @author Roman Rokytskyy
3030
* @author Mark Rotteveel
@@ -79,8 +79,8 @@ public String toString() {
7979

8080
protected boolean verbose;
8181

82-
private int restoreBufferCount = -1;
83-
private int restorePageSize = -1;
82+
private int restorePageBufferCount = -1;
83+
private int restorePageSize = PageSizeConstants.USE_DEFAULT;
8484
private boolean restoreReadOnly;
8585
private boolean restoreReplace;
8686
private @Nullable String skipData;
@@ -92,13 +92,13 @@ public String toString() {
9292
private static final int RESTORE_CREATE = isc_spb_res_create;
9393

9494
/**
95-
* Create a new instance of <code>FBBackupManagerBase</code> based on the default GDSType.
95+
* Create a new instance of {@code FBBackupManagerBase} based on the default GDSType.
9696
*/
9797
protected FBBackupManagerBase() {
9898
}
9999

100100
/**
101-
* Create a new instance of <code>FBBackupManagerBase</code> based on a given GDSType.
101+
* Create a new instance of {@code FBBackupManagerBase} based on a given GDSType.
102102
*
103103
* @param gdsType
104104
* type must be PURE_JAVA, EMBEDDED, or NATIVE
@@ -108,7 +108,7 @@ protected FBBackupManagerBase(String gdsType) {
108108
}
109109

110110
/**
111-
* Create a new instance of <code>FBBackupManagerBase</code> based on a given GDSType.
111+
* Create a new instance of {@code FBBackupManagerBase} based on a given GDSType.
112112
*
113113
* @param gdsType
114114
* type must be PURE_JAVA, EMBEDDED, or NATIVE
@@ -208,71 +208,61 @@ public void restoreDatabase() throws SQLException {
208208
restoreDatabase(0);
209209
}
210210

211-
/**
212-
* Set whether the operations of this {@code BackupManager} will result in verbose logging to the configured logger.
213-
*
214-
* @param verbose
215-
* If <code>true</code>, operations will be logged verbosely, otherwise they will not be logged verbosely
216-
*/
217211
@Override
218212
public void setVerbose(boolean verbose) {
219213
this.verbose = verbose;
220214
}
221215

222-
/**
223-
* Set the default number of pages to be buffered (cached) by default in a restored database.
224-
*
225-
* @param bufferCount
226-
* The page-buffer size to be used, a positive value
227-
*/
216+
@Override
217+
public boolean isVerbose() {
218+
return verbose;
219+
}
220+
228221
@Override
229222
public void setRestorePageBufferCount(int bufferCount) {
230-
if (bufferCount < 0) {
231-
throw new IllegalArgumentException("Buffer count must be positive");
223+
if (bufferCount < -1) {
224+
throw new IllegalArgumentException("Buffer count must be positive or -1");
232225
}
233-
this.restoreBufferCount = bufferCount;
226+
this.restorePageBufferCount = bufferCount;
227+
}
228+
229+
@Override
230+
public int getRestorePageBufferCount() {
231+
return restorePageBufferCount;
234232
}
235233

236-
/**
237-
* Set the page size that will be used for a restored database. The value for {@code pageSize} must be
238-
* one of {@link PageSizeConstants}. The default value depends on the Firebird version.
239-
* <p>
240-
* Be aware that not all page sizes are supported by all Firebird versions.
241-
* </p>
242-
*
243-
* @param pageSize
244-
* The page size to be used in a restored database, see {@link PageSizeConstants}
245-
* @see PageSizeConstants
246-
*/
247234
@Override
248235
public void setRestorePageSize(int pageSize) {
249-
this.restorePageSize = PageSizeConstants.requireValidPageSize(pageSize);
236+
this.restorePageSize = pageSize != PageSizeConstants.USE_DEFAULT
237+
? PageSizeConstants.requireValidPageSize(pageSize)
238+
: PageSizeConstants.USE_DEFAULT;
239+
}
240+
241+
@Override
242+
public int getRestorePageSize() {
243+
return restorePageSize;
250244
}
251245

252-
/**
253-
* Set the restore operation to create a new database, as opposed to overwriting an existing database. This is true
254-
* by default.
255-
*
256-
* @param replace
257-
* If <code>true</code>, the restore operation will attempt to create a new database, otherwise the restore
258-
* operation will overwrite an existing database
259-
*/
260246
@Override
261247
public void setRestoreReplace(boolean replace) {
262248
this.restoreReplace = replace;
263249
}
264250

265-
/**
266-
* Set the read-only attribute on a restored database.
267-
*
268-
* @param readOnly
269-
* If <code>true</code>, a restored database will be read-only, otherwise it will be read-write.
270-
*/
251+
@Override
252+
public boolean isRestoreReplace() {
253+
return restoreReplace;
254+
}
255+
271256
@Override
272257
public void setRestoreReadOnly(boolean readOnly) {
273258
this.restoreReadOnly = readOnly;
274259
}
275260

261+
@Override
262+
public boolean isRestoreReadOnly() {
263+
return restoreReadOnly;
264+
}
265+
276266
@Override
277267
public void setSkipData(@Nullable String skipData) {
278268
this.skipData = skipData;
@@ -342,8 +332,8 @@ protected ServiceRequestBuffer getRestoreSRB(FbService service, int options) thr
342332

343333
addBackupsToRestoreRequestBuffer(service, restoreSPB);
344334

345-
if (restoreBufferCount != -1) {
346-
restoreSPB.addArgument(isc_spb_res_buffers, restoreBufferCount);
335+
if (restorePageBufferCount != -1) {
336+
restoreSPB.addArgument(isc_spb_res_buffers, restorePageBufferCount);
347337
}
348338

349339
if (restorePageSize != -1) {

src/main/org/firebirdsql/management/FBStreamingBackupManager.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public class FBStreamingBackupManager extends FBBackupManagerBase implements Bac
4646
* </p>
4747
*
4848
* @param bufferSize
49-
* The buffer size to be used, a positive value
49+
* buffer size to be used, a positive value
50+
* @see #getBackupBufferSize()
5051
*/
5152
public void setBackupBufferSize(int bufferSize) {
5253
if (bufferSize <= 0) {
@@ -55,6 +56,15 @@ public void setBackupBufferSize(int bufferSize) {
5556
this.backupBufferSize = bufferSize;
5657
}
5758

59+
/**
60+
* @return buffer size to be used for backup
61+
* @see #setBackupBufferSize(int)
62+
* @since 7
63+
*/
64+
public int getBackupBufferSize() {
65+
return backupBufferSize;
66+
}
67+
5868
/**
5969
* Create a new instance of <code>FBStreamingBackupManager</code> based on
6070
* the default GDSType.
@@ -154,7 +164,7 @@ protected boolean verboseBackup() {
154164
*/
155165
@Override
156166
public void setRestorePageSize(int pageSize) {
157-
if (pageSize < PageSizeConstants.SIZE_4K) {
167+
if (pageSize != PageSizeConstants.USE_DEFAULT && pageSize < PageSizeConstants.SIZE_4K) {
158168
throw new IllegalArgumentException(
159169
"FirebirdSQL versions with streaming restore support don't support pages below 4096");
160170
}

src/main/org/firebirdsql/management/PageSizeConstants.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,22 @@
1313
* @author Mark Rotteveel
1414
* @since 3.0
1515
*/
16-
@SuppressWarnings("unused")
16+
@SuppressWarnings({ "unused", "DeprecatedIsStillUsed" })
1717
public final class PageSizeConstants {
1818

19+
/**
20+
* Value to signal use of a (server determined) default value.
21+
*/
22+
public static final int USE_DEFAULT = -1;
23+
/**
24+
* @deprecated deprecated in Firebird 2.1, and not supported in Firebird 2.5 and higher
25+
*/
26+
@Deprecated
1927
public static final int SIZE_1K = 1024;
28+
/**
29+
* @deprecated deprecated in Firebird 2.1, and not supported in Firebird 2.5 and higher
30+
*/
31+
@Deprecated
2032
public static final int SIZE_2K = 2 * SIZE_1K;
2133
public static final int SIZE_4K = 4 * SIZE_1K;
2234
public static final int SIZE_8K = 8 * SIZE_1K;
@@ -38,6 +50,9 @@ private PageSizeConstants() {
3850
* Actual support of a page size depends on the Firebird version, even if a page size is valid according to this
3951
* method, it can still be invalid for the actual Firebird version used.
4052
* </p>
53+
* <p>
54+
* This method does not consider {@link #USE_DEFAULT} ({@code -1}) a valid page size.
55+
* </p>
4156
*
4257
* @param pageSize
4358
* Page size to check

0 commit comments

Comments
 (0)