|
From: Frank V. C. <fr...@us...> - 2001-04-15 16:36:11
|
Update of /cvsroot/corelinux/clfw/src/libs/Persist
In directory usw-pr-cvs1:/tmp/cvs-serv27968/src/libs/Persist
Modified Files:
Makefile.am SchemaCatalog.cpp SchemaSponsor.cpp Store.cpp
Added Files:
SchemaAbstractStore.cpp SchemaCatStore.cpp
Log Message:
115287 Schema persist incremental
--- NEW FILE ---
/*
CoreLinux++
Copyright (C) 1999,2000,2001 CoreLinux Consortium
The CoreLinux++ Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The CoreLinux++ Library Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#define PERSIST_FRAMEWORK
#if !defined(__CLFWCOMMON_HPP)
#include <ClfwCommon.hpp>
#endif
#if !defined(__SCHEMAABSTRACTSTORE_HPP)
#include INCL_SchemaAbstractStore
#endif
#include <gdbm.h>
namespace corelinux
{
SchemaAbstractStore::SchemaAbstractStore( void )
:
Store(),
theHandle( NULLPTR )
{
;
}
SchemaAbstractStore::SchemaAbstractStore( SchemaAbstractStoreCref aRef )
:
Store(aRef),
theHandle( NULLPTR )
{
;
}
SchemaAbstractStore::~SchemaAbstractStore( void )
{
this->closeStore();
}
//
// Equality operator
//
bool SchemaAbstractStore::operator==( SchemaAbstractStoreCref aSchemaStore ) const
{
return ( this == &aSchemaStore );
}
//
// Assignment operator
//
SchemaAbstractStoreRef SchemaAbstractStore::operator=( SchemaAbstractStoreCref )
{
return ( *this );
}
void SchemaAbstractStore::closeStore( void )
{
if( theHandle != NULLPTR )
{
gdbm_close((GDBM_FILE)theHandle);
theHandle = NULLPTR;
}
else
{
; // do nothing
}
}
Handle SchemaAbstractStore::openRead( CharPtr aName )
{
REQUIRE( aName != NULLPTR );
return (Handle) gdbm_open
(
aName,0, GDBM_READER,0666,NULLPTR
);
}
Handle SchemaAbstractStore::openWrite( CharPtr aName )
{
REQUIRE( aName != NULLPTR );
return (Handle) gdbm_open
(
aName,0, GDBM_WRCREAT,0666,NULLPTR
);
}
//
// Check for any key in system
//
bool SchemaAbstractStore::hasKey( CharPtr aKey )
{
datum key ={aKey, strlen(aKey)};
return gdbm_exists( (GDBM_FILE)theHandle, key );
}
//
// Update the toc record
//
void SchemaAbstractStore::updateDesc( CharPtr aKey, SchemaDataDescriptorCref aDesc )
{
datum key = {aKey, strlen(aKey)};
datum keyd = {aDesc.data,aDesc.dataSize};
gdbm_store((GDBM_FILE)theHandle,key,keyd,GDBM_REPLACE);
}
//
// Fetch the toc record
//
SchemaDataDescriptor SchemaAbstractStore::fetchDesc( CharPtr aKey )
{
datum key = { aKey, strlen(aKey) };
datum res = gdbm_fetch((GDBM_FILE)theHandle,key);
SchemaDataDescriptor ad = { res.dptr,res.dsize };
return ad;
}
//
// MetaType information block
//
// version SchemaCatStore for the MetaType
const DwordCref version(1);
// meta indentifier for the SchemaCatStore
const UniversalIdentifier metaIdentifier
(
"4fa40184-31ba-11d5-95f8-00500489272c"
);
// Define parents
OPEN_METATYPE_PARENTS( SchemaAbstractStore )
DEFINE_METATYPE_PARENT( Store )
CLOSE_METATYPE_PARENT;
// We construct the null values reference
OPEN_INSTANCEDATA( SchemaAbstractStore )
CLOSE_INSTANCEDATA;
// We construct the null dispatch table
DEFINE_DUMMY_DISPATCHTABLE( SchemaAbstractStore );
// we use the abstract macro for MetaTypeStore autonaming
DEFINE_ABSTRACT_METATYPE
(
SchemaAbstractStore,
metaIdentifier,
version,
NULLPTR ,
"SchemaAbstractStore is base abstraction for derived Schema store types"
);
}
***** Error reading new file: [Errno 2] No such file or directory: 'SchemaCatStore.cpp'
Index: Makefile.am
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/libs/Persist/Makefile.am,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** Makefile.am 2001/04/12 11:56:53 1.4
--- Makefile.am 2001/04/15 16:36:08 1.5
***************
*** 14,22 ****
noinst_LTLIBRARIES = libclfwp.la
! libclfwp_la_SOURCES = StoreSponsor.cpp \
! SchemaSponsor.cpp \
! StoreCatalog.cpp \
! SchemaCatalog.cpp \
! Store.cpp
--- 14,26 ----
noinst_LTLIBRARIES = libclfwp.la
! libclfwp_la_SOURCES = \
! StoreSponsor.cpp \
! StoreCatalog.cpp \
! Store.cpp \
! SchemaSponsor.cpp \
! SchemaCatalog.cpp \
! SchemaAbstractStore.cpp \
! SchemaCatStore.cpp
!
Index: SchemaCatalog.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/libs/Persist/SchemaCatalog.cpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -r1.5 -r1.6
*** SchemaCatalog.cpp 2001/04/12 11:56:53 1.5
--- SchemaCatalog.cpp 2001/04/15 16:36:08 1.6
***************
*** 33,36 ****
--- 33,40 ----
#endif
+ #if !defined(__SCHEMACATSTORE_HPP)
+ #include INCL_SchemaCatStore
+ #endif
+
#if !defined(__SCHEMA_HPP)
#include <clfw/Schema.hpp>
***************
*** 56,71 ****
#include <unistd.h>
#include <errno.h>
- #include <gdbm.h>
}
namespace corelinux
{
- // Property constants
-
- static FrameworkString nameKey("Name");
- static FrameworkString locationKey("Location");
- static FrameworkString collectionType("Collection");
- static FrameworkString guidKey("GUID");
-
// Environmental constants
--- 60,67 ----
***************
*** 76,79 ****
--- 72,76 ----
const FrameworkString catName("schemcat");
const FrameworkString defCollection("SetCollection");
+ const FrameworkString catMode("Write");
//
***************
*** 83,92 ****
SchemaCatalog::SchemaCatalog( void )
:
! StoreCatalog()
{
//
// Initialize the catalog
//
resolveLocations();
}
--- 80,92 ----
SchemaCatalog::SchemaCatalog( void )
:
! StoreCatalog(),
! theCatalog( NULLPTR )
{
//
// Initialize the catalog
//
+
resolveLocations();
+ createCatalogStore();
}
***************
*** 97,101 ****
SchemaCatalog::SchemaCatalog( SchemaCatalogCref aType )
:
! StoreCatalog( aType )
{
//
--- 97,102 ----
SchemaCatalog::SchemaCatalog( SchemaCatalogCref aType )
:
! StoreCatalog( aType ),
! theCatalog( NULLPTR )
{
//
***************
*** 103,106 ****
--- 104,108 ----
//
resolveLocations();
+ createCatalogStore();
}
***************
*** 111,115 ****
SchemaCatalog::~SchemaCatalog( void )
{
! ; // do nothing
}
--- 113,125 ----
SchemaCatalog::~SchemaCatalog( void )
{
! if( theCatalog != NULLPTR )
! {
! delete theCatalog;
! theCatalog = NULLPTR;
! }
! else
! {
! ; // do nothing
! }
}
***************
*** 159,163 ****
FrameworkStringPtr aName
(
! this->resolveValueAssignment(aCollection,&nameKey)
);
--- 169,173 ----
FrameworkStringPtr aName
(
! Store::resolveValueAssignment(aCollection,&Store::getNameKey())
);
***************
*** 194,197 ****
--- 204,244 ----
// Make the catalog entry and persist
+ FrameworkStringPtr aLocation
+ (
+ Store::resolveValueAssignment(aCollection,& Store::getLocationKey())
+ );
+
+ if( aLocation == NULLPTR )
+ {
+ aLocation = &theStoresRoot;
+ }
+ else
+ {
+ ; // do nothing
+ }
+
+ //
+ // What we do here to make the entry is:
+ // Collection where:
+ // UuidAssignment -> uuid
+ // EntryInfo -> array
+ // Name -> name
+ // Location -> location
+ //
+
+ Array outer;
+ Array inner;
+ Attribute uid;
+
+ uid.setKey( FrameworkEntityPtr(&Store::getUniqueIdKey()) );
+ uid.setValue( FrameworkEntityPtr(&aUid) );
+ outer.put( &uid );
+
+ Attribute colInfo;
+ colInfo.setKey( FrameworkEntityPtr(&Store::getCollectionKey()) );
+ colInfo.setValue( &inner );
+
+ outer.put( &colInfo );
+
// Serialize the first part to the location
***************
*** 234,238 ****
FrameworkStringPtr aName
(
! this->resolveValueAssignment(aCollection,&nameKey)
);
--- 281,285 ----
FrameworkStringPtr aName
(
! Store::resolveValueAssignment(aCollection,&Store::getNameKey())
);
***************
*** 297,301 ****
UniversalIdentifier aSchmId( aKey.getValue() );
! anAttribute->setKey( new FrameworkString(nameKey) );
anAttribute->setValue( new FrameworkString(aName) );
--- 344,348 ----
UniversalIdentifier aSchmId( aKey.getValue() );
! anAttribute->setKey( new FrameworkString( Store::getNameKey() ) );
anAttribute->setValue( new FrameworkString(aName) );
***************
*** 320,324 ****
FrameworkStringPtr aResult
(
! this->resolveValueAssignment(aCollection,&guidKey)
);
--- 367,375 ----
FrameworkStringPtr aResult
(
! Store::resolveValueAssignment
! (
! aCollection,
! &Store::getUniqueIdKey()
! )
);
***************
*** 352,356 ****
FrameworkStringPtr aResult
(
! this->resolveValueAssignment(aCollection,&collectionType)
);
--- 403,411 ----
FrameworkStringPtr aResult
(
! Store::resolveValueAssignment
! (
! aCollection,
! &Store::getCollectionKey()
! )
);
***************
*** 385,417 ****
}
- //
- // Little workhorse
- //
-
- FrameworkStringPtr SchemaCatalog::resolveValueAssignment
- (
- CollectionPtr aCollection,
- FrameworkStringPtr aValue
- ) const
- {
- FrameworkStringPtr aResult(NULLPTR);
- Attribute aQueryAttr;
- ElementIndex anIndex(-1);
-
- aQueryAttr.setKey( aValue );
- AttributePtr aAttr( NULLPTR );
-
- if( ( anIndex = aCollection->indexOf( &aQueryAttr ) ) >= 0 )
- {
- aAttr = Attribute::castDown(aCollection->getElementAt( anIndex ));
- aResult = FrameworkString::castDown( aAttr->getValue() );
- }
- else
- {
- ; // do nothing
- }
-
- return aResult;
- }
//
--- 440,443 ----
***************
*** 488,491 ****
--- 514,582 ----
; // do nothing
}
+ }
+
+ //
+ // Fetch or create, if first time, the
+ // schema catalog
+ //
+
+ void SchemaCatalog::createCatalogStore( void )
+ {
+ Array anArray;
+
+ //
+ // Establish the location
+ //
+
+ Attribute aLoc;
+ aLoc.setKey( (FrameworkEntityPtr)&(Store::getLocationKey()) );
+ aLoc.setValue( (FrameworkEntityPtr)&theCatalogRoot );
+ anArray.put( &aLoc );
+
+ //
+ // Establish the name
+ //
+
+ Attribute aName;
+ aName.setKey( (FrameworkEntityPtr)&(Store::getNameKey()) );
+ aName.setValue( (FrameworkEntityPtr)&catName );
+ anArray.put( &aName );
+
+ //
+ // Establish mode
+ //
+
+ Attribute aMode;
+ aMode.setKey( (FrameworkEntityPtr)&(Store::getModeKey() ) );
+ aMode.setValue( (FrameworkEntityPtr)&catMode );
+ anArray.put( &aMode );
+
+ theCatalog = SchemaCatStore::create();
+ if( theCatalog != NULLPTR )
+ {
+ CollectionPtr aResult( NULLPTR );
+ theCatalog->open( &anArray );
+
+ aResult = theCatalog->read( NULLPTR );
+
+ if( aResult != NULLPTR )
+ {
+ Counter maxLoop( aResult->getSize() );
+ for( Counter x = 0; x < maxLoop; ++x )
+ {
+
+ }
+ theCatalog->returnReadCollection( aResult );
+ }
+ else
+ {
+ throw NullPointerException(LOCATION);
+ }
+ }
+ else
+ {
+ throw Exception("Can't open Schema Catalog",LOCATION);
+ }
+
}
Index: SchemaSponsor.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/libs/Persist/SchemaSponsor.cpp,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -r1.2 -r1.3
*** SchemaSponsor.cpp 2001/04/10 21:17:50 1.2
--- SchemaSponsor.cpp 2001/04/15 16:36:08 1.3
***************
*** 89,93 ****
if( theStoreCatalog == NULLPTR )
{
! theStoreCatalog = new SchemaCatalog;
}
else
--- 89,93 ----
if( theStoreCatalog == NULLPTR )
{
! theStoreCatalog = SchemaCatalog::create();
}
else
Index: Store.cpp
===================================================================
RCS file: /cvsroot/corelinux/clfw/src/libs/Persist/Store.cpp,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** Store.cpp 2001/04/12 11:56:53 1.1
--- Store.cpp 2001/04/15 16:36:08 1.2
***************
*** 25,34 ****
--- 25,57 ----
#endif
+ #if !defined(__FRAMEWORKSTRING_HPP)
+ #include <clfw/FrameworkString.hpp>
+ #endif
+
+ #if !defined(__COLLECTION_HPP)
+ #include <clfw/Collection.hpp>
+ #endif
+
+ #if !defined(__ATTRIBUTE_HPP)
+ #include <clfw/Attribute.hpp>
+ #endif
+
#if !defined(__STORE_HPP)
#include INCL_Store
#endif
+
namespace corelinux
{
+ FrameworkString Store::theNameKey("Name");
+
+ FrameworkString Store::theModeKey("Mode");
+
+ FrameworkString Store::theLocationKey("Location");
+
+ FrameworkString Store::theUniqueIdKey("GUID");
+
+ FrameworkString Store::theCollectionKey("Collection");
+
//
// Constructor
***************
*** 77,80 ****
--- 100,158 ----
{
return ( *this );
+ }
+
+ //
+ // Little workhorse
+ //
+
+ FrameworkStringPtr Store::resolveValueAssignment
+ (
+ CollectionPtr aCollection,
+ FrameworkStringCptr aValue
+ )
+ {
+ FrameworkStringPtr aResult(NULLPTR);
+ Attribute aQueryAttr;
+ ElementIndex anIndex(-1);
+
+ aQueryAttr.setKey( FrameworkStringPtr(aValue) );
+ AttributePtr aAttr( NULLPTR );
+
+ if( ( anIndex = aCollection->indexOf( &aQueryAttr ) ) >= 0 )
+ {
+ aAttr = Attribute::castDown(aCollection->getElementAt( anIndex ));
+ aResult = FrameworkString::castDown( aAttr->getValue() );
+ }
+ else
+ {
+ ; // do nothing
+ }
+
+ return aResult;
+ }
+
+ FrameworkStringCref Store::getNameKey( void )
+ {
+ return theNameKey;
+ }
+
+ FrameworkStringCref Store::getModeKey( void )
+ {
+ return theModeKey;
+ }
+
+ FrameworkStringCref Store::getLocationKey( void )
+ {
+ return theLocationKey;
+ }
+
+ FrameworkStringCref Store::getUniqueIdKey( void )
+ {
+ return theUniqueIdKey;
+ }
+
+ FrameworkStringCref Store::getCollectionKey( void )
+ {
+ return theCollectionKey;
}
|