--- a/DataBaseSourceCodeManager.st Mon Dec 26 00:51:15 2011 +0100
+++ b/DataBaseSourceCodeManager.st Mon Dec 26 02:50:26 2011 +0100
@@ -12,10 +12,10 @@
"{ Package: 'stx:libbasic3' }"
AbstractSourceCodeManager subclass:#DataBaseSourceCodeManager
- instanceVariableNames:''
- classVariableNames:'Verbose RepositoryPath ModulePathes'
- poolDictionaries:''
- category:'System-SourceCodeManagement'
+ instanceVariableNames:''
+ classVariableNames:'Verbose RepositoryName ModuleDBs CachedDBHandles'
+ poolDictionaries:''
+ category:'System-SourceCodeManagement'
!
!DataBaseSourceCodeManager class methodsFor:'documentation'!
@@ -36,11 +36,9 @@
documentation
"
- A simple file based sourceCodeManager, which saves versions in a local directory.
- Versions will be stored as filename.st.vNr (i.e. Foo.st.1, Foo.st.2, etc.)
+ A simple database sourceCodeManager, which saves versions in a relational db
- This is more an example of the protocol which needs to be implemented,
- than a real manager (although it may be useful for tiny private projects or classroom examples)
+ unfinished
[author:]
Claus Gittinger
@@ -49,43 +47,120 @@
!DataBaseSourceCodeManager class methodsFor:'accessing'!
-getRepositoryPathForModule:aModuleName
+getRepositoryDBForModule:aModuleName
"internal: used when accessing a source repository.
- Return the path to the top directory for a particular module.
- If no specific path was defined for that module, return the value of
- the global (fallBack) repositoryPath.
+ Return the db-name for a particular module.
+ If no specific db was defined for that module, return the value of
+ the global (fallBack) repositoryDB.
Nil is returned if no repository is available."
- ModulePathes isNil ifTrue:[^ RepositoryPath].
- aModuleName isNil ifTrue:[^ RepositoryPath].
- ^ ModulePathes at:aModuleName ifAbsent:RepositoryPath.
+ ModuleDBs isNil ifTrue:[^ RepositoryName].
+ aModuleName isNil ifTrue:[^ RepositoryName].
+ ^ ModuleDBs at:aModuleName ifAbsent:RepositoryName.
"Modified: / 20-05-1998 / 16:30:12 / cg"
- "Created: / 21-12-2011 / 23:05:51 / cg"
+ "Created: / 26-12-2011 / 00:30:17 / cg"
!
knownModules
"return the modules, we currently know"
- ^ ModulePathes keys
+ ModuleDBs isEmptyOrNil ifTrue:[^ #() ].
+ ^ ModuleDBs keys
+
+ "Modified: / 26-12-2011 / 00:48:51 / cg"
+!
- "Modified: / 21-12-2011 / 14:54:53 / cg"
+repositoryName
+ "return the default repository"
+
+ ^ RepositoryName
+
+ "Created: / 26-12-2011 / 00:34:14 / cg"
!
-repositoryPath
- "return the path of the default repository"
+repositoryName:aDBSpec
+ "set the default repository"
+
+ RepositoryName := aDBSpec.
+
+ "Created: / 26-12-2011 / 01:13:59 / cg"
+! !
+
+!DataBaseSourceCodeManager class methodsFor:'private'!
+
+dbHandleForModule:aModuleName
+ |dbName handle|
+
+ CachedDBHandles isNil ifTrue:[
+ CachedDBHandles := WeakIdentityDictionary new.
+ ].
- ^ RepositoryPath
+ handle := CachedDBHandles at:aModuleName ifAbsent:nil.
+ handle notNil ifTrue:[^ handle ].
+
+ dbName := self getRepositoryDBForModule:aModuleName.
+ dbName isNil ifTrue:[
+ self error:'no database'.
+ ^ nil
+ ].
- "Created: / 21-12-2011 / 14:55:12 / cg"
+ handle := self openDB:dbName.
+ handle isNil ifTrue:[
+ self error:'no database'.
+ ^ nil
+ ].
+ CachedDBHandles at:aModuleName put:handle.
+ ^ handle.
+
+ "Created: / 26-12-2011 / 00:59:49 / cg"
!
-repositoryPath:aPath
- "set the path of the default repository"
+openDB:aDBName
+ |idx dbType dbSpec|
+
+ idx := aDBName indexOf:$:.
+ dbType := aDBName copyTo:idx-1.
+ dbSpec := aDBName copyFrom:idx+1.
+
+ dbType = 'sqlite' ifTrue:[
+ ^ self openSQLite:dbSpec
+ ].
+ dbType = 'odbc' ifTrue:[
+ ^ self openODBC:dbSpec
+ ].
+ self error:'unsupported dbtype'
+
+ "Created: / 26-12-2011 / 01:05:57 / cg"
+!
+
+openODBC:dbSpec
+self halt.
- RepositoryPath := aPath
+ "Created: / 26-12-2011 / 01:06:41 / cg"
+!
+
+openSQLite:dbSpec
+ |file con rslt crsr|
+
+ file := dbSpec.
+ con := SQLiteConnection fileNamed:file.
+ con open.
- "Created: / 22-12-2011 / 00:30:19 / cg"
+ SqliteError handle:[:ex |
+ ] do:[
+ crsr := con executeQuery:'SELECT * FROM sqlite_master WHERE type=''table'';'.
+ ].
+Transcript showCR:rslt.
+ crsr isNil ifTrue:[
+ rslt := con executeQuery:'CREATE table packages (id, name);'.
+ ] ifFalse:[
+ ].
+
+ con close.
+ ^ con
+
+ "Created: / 26-12-2011 / 01:06:37 / cg"
! !
!DataBaseSourceCodeManager class methodsFor:'queries'!
@@ -183,7 +258,7 @@
checkForExistingModule:moduleDir
"check for a package directory to be present"
- self halt.
+ ^ true.
"/
"/ dir := self moduleDirectoryFor:moduleDir.
"/ ^ dir exists
@@ -192,15 +267,21 @@
!
checkForExistingModule:moduleDir directory:packageDir
- "check for a package directory to be present"
+ "check for a package directory to be present; return true, if it does"
+
+ |handle packagePresent name|
+
+ handle := self dbHandleForModule:moduleDir.
+ name := moduleDir,':',packageDir.
- self halt.
-"/ |dir|
-"/
-"/ dir := self packageDirectoryForModule:moduleDir package:packageDir.
-"/ ^ dir exists
-"/
-"/
+ packagePresent := false.
+ handle
+ withResultForQuery: ('select * from packages where name = "%1"' bindWith:name)
+ do:[:result |
+ packagePresent := result numRows > 0.
+ ].
+
+ ^ packagePresent
"Created: / 21-12-2011 / 18:03:33 / cg"
!
@@ -208,6 +289,9 @@
checkinClass:aClass fileName:classFileName directory:packageDir module:moduleDir source:sourceFile logMessage:logMessage force:force
"Return true if ok, false if not."
+ aClass definition.
+
+
self halt.
"/ |targetDir newestRevision newRevision newFile packageMode filter outStream|
"/
@@ -289,6 +373,17 @@
createModule:moduleDir directory:packageDir
"create a package directory"
+ |handle id name|
+
+ id := UUID new.
+ name := (moduleDir,':',packageDir).
+
+ handle := self dbHandleForModule:moduleDir.
+ handle
+ withResultForQuery: ('insert into packages values (''%1'', ''%2'')' bindWith:id with:name)
+ do:[:result |
+ ].
+
self halt.
"/ |dir|
"/
@@ -312,34 +407,6 @@
"Created: / 21-12-2011 / 18:14:03 / cg"
!
-moduleDirectoryFor:moduleDir
- "a modules directory as filename"
-
- self halt.
-"/ |root|
-"/
-"/ root := self getRepositoryPathForModule:moduleDir.
-"/ root isNil ifTrue:[
-"/ RepositoryPath := root := self defaultRepositoryPath.
-"/ ].
-"/
-"/ ^ (root asFilename construct:moduleDir)
-
- "Created: / 21-12-2011 / 18:38:38 / cg"
-!
-
-packageDirectoryForModule:moduleDir package:package
- "a packages directory as filename"
-
- self halt.
-"/ |dir|
-"/
-"/ dir := self moduleDirectoryFor:moduleDir.
-"/ ^ dir construct:package
-
- "Created: / 21-12-2011 / 18:43:27 / cg"
-!
-
revisionInfoFromString:aString
"{ Pragma: +optSpace }"
@@ -499,9 +566,9 @@
!DataBaseSourceCodeManager class methodsFor:'documentation'!
version
- ^ '$Header: /cvs/stx/stx/libbasic3/DataBaseSourceCodeManager.st,v 1.2 2011-12-25 22:27:00 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic3/DataBaseSourceCodeManager.st,v 1.3 2011-12-26 01:50:26 cg Exp $'
!
version_CVS
- ^ '$Header: /cvs/stx/stx/libbasic3/DataBaseSourceCodeManager.st,v 1.2 2011-12-25 22:27:00 vrany Exp $'
+ ^ '$Header: /cvs/stx/stx/libbasic3/DataBaseSourceCodeManager.st,v 1.3 2011-12-26 01:50:26 cg Exp $'
! !