Added DbSystem.dbRename. Also added unit test for it.
git-svn-id: https://svn.code.sf.net/p/flaim/code/trunk@875 0109f412-320b-0410-ab79-c3e0c5ffbbe6
This commit is contained in:
@@ -33,6 +33,7 @@ namespace cstest
|
||||
{
|
||||
private const string CREATE_DB_NAME = "create.db";
|
||||
private const string COPY_DB_NAME = "copy.db";
|
||||
private const string COPY2_DB_NAME = "copy2.db";
|
||||
private const string RENAME_DB_NAME = "rename.db";
|
||||
private const string RESTORE_DB_NAME = "restore.db";
|
||||
private const string BACKUP_PATH = "backup";
|
||||
@@ -183,6 +184,8 @@ namespace cstest
|
||||
// Copy database test.
|
||||
//--------------------------------------------------------------------------
|
||||
static bool copyDbTest(
|
||||
string sSrcDbName,
|
||||
string sDestDbName,
|
||||
DbSystem dbSystem)
|
||||
{
|
||||
|
||||
@@ -190,10 +193,10 @@ namespace cstest
|
||||
|
||||
MyDbCopyStatus copyStatus = new MyDbCopyStatus();
|
||||
|
||||
beginTest( "Copy Database Test (" + CREATE_DB_NAME + " --> " + COPY_DB_NAME + ")");
|
||||
beginTest( "Copy Database Test (" + sSrcDbName + " --> " + sDestDbName + ")");
|
||||
try
|
||||
{
|
||||
dbSystem.dbCopy( CREATE_DB_NAME, null, null, COPY_DB_NAME, null, null, copyStatus);
|
||||
dbSystem.dbCopy( sSrcDbName, null, null, sDestDbName, null, null, copyStatus);
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
@@ -377,6 +380,33 @@ namespace cstest
|
||||
return( true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Rename database test.
|
||||
//--------------------------------------------------------------------------
|
||||
static bool renameDbTest(
|
||||
string sSrcDbName,
|
||||
string sDestDbName,
|
||||
DbSystem dbSystem)
|
||||
{
|
||||
|
||||
// Try renaming the database
|
||||
|
||||
MyDbRenameStatus renameStatus = new MyDbRenameStatus();
|
||||
|
||||
beginTest( "Rename Database Test (" + sSrcDbName + " --> " + sDestDbName + ")");
|
||||
try
|
||||
{
|
||||
dbSystem.dbRename( sSrcDbName, null, null, sDestDbName, true, renameStatus);
|
||||
}
|
||||
catch (XFlaimException ex)
|
||||
{
|
||||
endTest( renameStatus.outputLines(), ex, "renaming database");
|
||||
return( false);
|
||||
}
|
||||
endTest( renameStatus.outputLines(), true);
|
||||
return( true);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Main for tester program
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -400,7 +430,18 @@ namespace cstest
|
||||
|
||||
// Database copy test
|
||||
|
||||
if (!copyDbTest( dbSystem))
|
||||
if (!copyDbTest( CREATE_DB_NAME, COPY_DB_NAME, dbSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!copyDbTest( CREATE_DB_NAME, COPY2_DB_NAME, dbSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Database rename test
|
||||
|
||||
if (!renameDbTest( COPY2_DB_NAME, RENAME_DB_NAME, dbSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -433,6 +474,10 @@ namespace cstest
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!checkDbTest( RENAME_DB_NAME, dbSystem))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Database remove test
|
||||
|
||||
@@ -448,6 +493,10 @@ namespace cstest
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (!removeDbTest( dbSystem, RENAME_DB_NAME))
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -882,4 +931,29 @@ namespace cstest
|
||||
|
||||
private bool m_bOutputLines;
|
||||
}
|
||||
|
||||
public class MyDbRenameStatus : DbRenameStatus
|
||||
{
|
||||
public MyDbRenameStatus()
|
||||
{
|
||||
m_bOutputLines = false;
|
||||
System.Console.Write( "\n");
|
||||
}
|
||||
|
||||
public RCODE dbRenameStatus(
|
||||
string sSrcFileName,
|
||||
string sDestFileName)
|
||||
{
|
||||
System.Console.WriteLine( "Renaming {0} to {1}", sSrcFileName, sDestFileName);
|
||||
m_bOutputLines = true;
|
||||
return( RCODE.NE_XFLM_OK);
|
||||
}
|
||||
|
||||
public bool outputLines()
|
||||
{
|
||||
return( m_bOutputLines);
|
||||
}
|
||||
|
||||
private bool m_bOutputLines;
|
||||
}
|
||||
}
|
||||
|
||||
60
xflaim/csharp/xflaim/DbRenameStatus.cs
Normal file
60
xflaim/csharp/xflaim/DbRenameStatus.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Desc: Db Rename Status
|
||||
//
|
||||
// Tabs: 3
|
||||
//
|
||||
// Copyright (c) 2006 Novell, Inc. All Rights Reserved.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of version 2 of the GNU General Public
|
||||
// License as published by the Free Software Foundation.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, contact Novell, Inc.
|
||||
//
|
||||
// To contact Novell about this file by physical or electronic mail,
|
||||
// you may find current contact information at www.novell.com
|
||||
//
|
||||
// $Id$
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace xflaim
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// This interface allows XFlaim to periodically pass information back to the
|
||||
/// client about the status of an ongoing database copy operation. The
|
||||
/// implementor may do anything it wants with the information, such as write
|
||||
/// it to a log file or display it on the screen.
|
||||
/// </summary>
|
||||
public interface DbRenameStatus
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="DbSystem.dbRename"/> operation calls this method periodically to
|
||||
/// inform the implementation object about the status of the rename operation.
|
||||
/// </summary>
|
||||
/// <param name="sSrcFileName">
|
||||
/// The name of the file that is currently being renamed.
|
||||
/// </param>
|
||||
/// <param name="sDestFileName">
|
||||
/// The name the source file is being renamed to.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// If the implementation object returns anything but RCODE.NE_XFLM_OK
|
||||
/// the <see cref="DbSystem.dbRename"/> operation will abort and throw an
|
||||
/// <see cref="XFlaimException"/>
|
||||
/// </returns>
|
||||
RCODE dbRenameStatus(
|
||||
string sSrcFileName,
|
||||
string sDestFileName);
|
||||
}
|
||||
}
|
||||
@@ -806,3 +806,78 @@ Exit:
|
||||
|
||||
return( rc);
|
||||
}
|
||||
|
||||
typedef RCODE (FLMAPI * DB_RENAME_STATUS)(
|
||||
const char * pszSrcFileName,
|
||||
const char * pszDestFileName);
|
||||
|
||||
/****************************************************************************
|
||||
Desc:
|
||||
****************************************************************************/
|
||||
class CS_DbRenameStatus : public IF_DbRenameStatus
|
||||
{
|
||||
public:
|
||||
|
||||
CS_DbRenameStatus(
|
||||
DB_RENAME_STATUS fnRenameStatus)
|
||||
{
|
||||
m_fnRenameStatus = fnRenameStatus;
|
||||
}
|
||||
|
||||
virtual ~CS_DbRenameStatus()
|
||||
{
|
||||
}
|
||||
|
||||
RCODE FLMAPI dbRenameStatus(
|
||||
const char * pszSrcFileName,
|
||||
const char * pszDestFileName)
|
||||
{
|
||||
return( m_fnRenameStatus( pszSrcFileName, pszDestFileName));
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
DB_RENAME_STATUS m_fnRenameStatus;
|
||||
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
Desc:
|
||||
****************************************************************************/
|
||||
FLMEXTC FLMEXP RCODE FLMAPI xflaim_DbSystem_dbRename(
|
||||
FLMUINT64 ui64This,
|
||||
const char * pszSrcDbName,
|
||||
const char * pszSrcDataDir,
|
||||
const char * pszSrcRflDir,
|
||||
const char * pszDestDbName,
|
||||
FLMBOOL bOverwriteDestOk,
|
||||
DB_RENAME_STATUS fnRenameStatus)
|
||||
{
|
||||
RCODE rc = NE_XFLM_OK;
|
||||
IF_DbSystem * pDbSystem = ((IF_DbSystem *)(FLMUINT)ui64This);
|
||||
IF_DbRenameStatus * pDbRenameStatus = NULL;
|
||||
|
||||
if (fnRenameStatus)
|
||||
{
|
||||
if ((pDbRenameStatus = f_new CS_DbRenameStatus( fnRenameStatus)) == NULL)
|
||||
{
|
||||
rc = RC_SET( NE_XFLM_MEM);
|
||||
goto Exit;
|
||||
}
|
||||
}
|
||||
|
||||
if (RC_BAD( rc = pDbSystem->dbRename( pszSrcDbName, pszSrcDataDir, pszSrcRflDir, pszDestDbName,
|
||||
bOverwriteDestOk, pDbRenameStatus)))
|
||||
{
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
Exit:
|
||||
|
||||
if (pDbRenameStatus)
|
||||
{
|
||||
pDbRenameStatus->Release();
|
||||
}
|
||||
|
||||
return( rc);
|
||||
}
|
||||
|
||||
@@ -916,6 +916,81 @@ namespace xflaim
|
||||
private DbCopyStatus m_dbCopyStatus;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rename a database.
|
||||
/// </summary>
|
||||
/// <param name="sDbName">
|
||||
/// The name of the control file of the database to be renamed.
|
||||
/// </param>
|
||||
/// <param name="sDataDir">
|
||||
/// The data file directory. See <see cref="dbCreate"/> for more information.
|
||||
/// </param>
|
||||
/// <param name="sRflDir">
|
||||
/// The roll-forward log file directory. See <see cref="dbCreate"/> for more information.
|
||||
/// </param>
|
||||
/// <param name="sNewDbName">
|
||||
/// The new control file name for the database.
|
||||
/// </param>
|
||||
/// <param name="bOverwriteDestOk">
|
||||
/// If true, then if the data specified in sNewDbName already exists, it will be overwritten.
|
||||
/// </param>
|
||||
/// <param name="renameStatus">
|
||||
/// If non-null this is an object that implements the <see cref="DbRenameStatus"/>
|
||||
/// interface. It is a callback object that is used to report rename progress.
|
||||
/// </param>
|
||||
public void dbRename(
|
||||
string sDbName,
|
||||
string sDataDir,
|
||||
string sRflDir,
|
||||
string sNewDbName,
|
||||
bool bOverwriteDestOk,
|
||||
DbRenameStatus renameStatus)
|
||||
{
|
||||
int rc;
|
||||
DbRenameStatusDelegate dbRenameStatus = null;
|
||||
DbRenameStatusCallback fnDbRenameStatus = null;
|
||||
|
||||
if (renameStatus != null)
|
||||
{
|
||||
dbRenameStatus = new DbRenameStatusDelegate( renameStatus);
|
||||
fnDbRenameStatus = new DbRenameStatusCallback( dbRenameStatus.funcDbRenameStatus);
|
||||
}
|
||||
|
||||
if ((rc = xflaim_DbSystem_dbRename( m_pDbSystem, sDbName, sDataDir, sRflDir, sNewDbName,
|
||||
(int)(bOverwriteDestOk ? 1 : 0), fnDbRenameStatus)) != 0)
|
||||
{
|
||||
throw new XFlaimException( rc);
|
||||
}
|
||||
}
|
||||
|
||||
private delegate RCODE DbRenameStatusCallback(
|
||||
IntPtr pszSrcFileName,
|
||||
IntPtr pszDestFileName);
|
||||
|
||||
private class DbRenameStatusDelegate
|
||||
{
|
||||
public DbRenameStatusDelegate(
|
||||
DbRenameStatus dbRenameStatus)
|
||||
{
|
||||
m_dbRenameStatus = dbRenameStatus;
|
||||
}
|
||||
|
||||
~DbRenameStatusDelegate()
|
||||
{
|
||||
}
|
||||
|
||||
public RCODE funcDbRenameStatus(
|
||||
IntPtr pszSrcFileName,
|
||||
IntPtr pszDestFileName)
|
||||
{
|
||||
return( m_dbRenameStatus.dbRenameStatus(
|
||||
Marshal.PtrToStringAnsi( pszSrcFileName),
|
||||
Marshal.PtrToStringAnsi( pszDestFileName)));
|
||||
}
|
||||
|
||||
private DbRenameStatus m_dbRenameStatus;
|
||||
}
|
||||
|
||||
// PRIVATE METHODS THAT ARE IMPLEMENTED IN C AND C++
|
||||
|
||||
[DllImport("xflaim")]
|
||||
@@ -988,6 +1063,16 @@ namespace xflaim
|
||||
[MarshalAs(UnmanagedType.LPStr)] string pszDestRflDir,
|
||||
DbCopyStatusCallback fnDbCopyStatus);
|
||||
|
||||
[DllImport("xflaim",CharSet=CharSet.Ansi)]
|
||||
private static extern int xflaim_DbSystem_dbRename(
|
||||
ulong pDbSystem,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string pszSrcDbName,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string pszSrcDataDir,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string pszSrcRflDir,
|
||||
[MarshalAs(UnmanagedType.LPStr)] string pszDestDbName,
|
||||
int bOverwriteDestOk,
|
||||
DbRenameStatusCallback fnDbRenameStatus);
|
||||
|
||||
private ulong m_pDbSystem;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user