StoreSourceCodeManager.st
author Claus Gittinger <cg@exept.de>
Fri, 25 Aug 2006 19:39:52 +0200
changeset 1735 cecbce9842fa
parent 1734 659de14f0d95
child 1737 b16f73da1716
permissions -rw-r--r--
*** empty log message ***

"
 COPYRIGHT (c) 2006 eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"

"{ Package: 'stx:libbasic3' }"

AbstractSourceCodeManager subclass:#StoreSourceCodeManager
	instanceVariableNames:''
	classVariableNames:'Verbose Connection DefaultDBInfo DBInfoPerModule'
	poolDictionaries:''
	category:'System-SourceCodeManagement'
!

Object subclass:#DBInfo
	instanceVariableNames:'hostName dbName userName password'
	classVariableNames:''
	poolDictionaries:''
	privateIn:StoreSourceCodeManager
!

!StoreSourceCodeManager class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    WARNING:
        this class is incomplete and provided as a sceletton
        if CVS is not to be used as a SourceCodeManager.
        We highly recommend to use CVS.

    SourceCodeManager which accesses sourcecode through a Store Database.
    This class is part of ongoing development and not yet released for public use.
"
! !

!StoreSourceCodeManager class methodsFor:'initialization'!

connectToDatabase
    |session dbInfo|

    dbInfo := self defaultDBInfo.

    SQL::SQLError handle:[:ex |
        self warn:('Failed to connect to Database:\\' withCRs,ex description).
        ^ self.
    ] do:[
        session := self tryToConnectToDatabase:dbInfo.
    ].

    session isNil ifTrue:[
        self warn:'OOPS - Failed to connect to Database'.
        ^ self
    ].
    Connection := session.
    Transcript showCR:('Connected to Store-DB: ',dbInfo hostAndDBName).
!

tryToConnectToDatabase:dbInfo
    |session|

    session := SQL::ODBCSession new.
    session 
        connectWithUsername:(dbInfo userName) 
        password:(dbInfo password) 
        dbname:(dbInfo dbName).

    (session isConnected) ifFalse:[
        ^ nil.
    ].
    ^ session
! !

!StoreSourceCodeManager class methodsFor:'accessing'!

dbName
    ^ self defaultDBInfo dbName
!

dbName:aString
    self defaultDBInfo dbName:aString.
!

defaultDBInfo
    DefaultDBInfo isNil ifTrue:[
        DefaultDBInfo := DBInfo new
    ].
    ^ DefaultDBInfo
!

hostAndDBName
    ^ self defaultDBInfo hostAndDBName
!

hostAndDBName:aString
    self defaultDBInfo hostAndDBName:aString.
!

hostName
    ^ self defaultDBInfo hostName
!

hostName:aString
    self defaultDBInfo hostName:aString.
!

newDBInfo
    ^ DBInfo new
!

password
    ^ self defaultDBInfo password
!

password:aString
    self defaultDBInfo password:aString.
!

repositoryInfoPerModule
    ^ DBInfoPerModule ? #()

    "Created: / 16-08-2006 / 11:06:09 / cg"
!

repositoryInfoPerModule:aCollectionOfDBinfos
    DBInfoPerModule := aCollectionOfDBinfos

    "Created: / 16-08-2006 / 11:06:09 / cg"
!

userName
    ^ self defaultDBInfo userName
!

userName:aString
    self defaultDBInfo userName:aString.
! !

!StoreSourceCodeManager class methodsFor:'queries'!

managerTypeName
    ^ 'Store DB'

    "Created: / 16-08-2006 / 11:06:09 / cg"
! !

!StoreSourceCodeManager class methodsFor:'testing'!

isExperimental
    "/ ^ false.
    ^ true

    "Created: / 16-08-2006 / 11:23:09 / cg"
!

isStore
    ^ true

    "Created: / 16-08-2006 / 10:59:06 / cg"
! !

!StoreSourceCodeManager::DBInfo methodsFor:'accessing'!

dbName
    ^ dbName
!

dbName:something
    dbName := something.
!

hostAndDBName
    hostName isEmptyOrNil ifTrue:[ ^ dbName ].
    ^ dbName,'@',hostName
!

hostAndDBName: aString
    |idx|

    idx := aString indexOf:$@.
    idx == 0 ifTrue:[
        dbName := aString.
        hostName := nil.
    ] ifFalse:[
        dbName := aString copyTo:idx-1.
        hostName := (aString copyFrom:idx+1).
    ]
!

hostAndDBName:hostAndDBNameArg userName:userNameArg password:passwordArg 
    self hostAndDBName:hostAndDBNameArg.
    userName := userNameArg.
    password := passwordArg.
!

hostName
    ^ hostName
!

hostName:something
    hostName := something.
!

hostName:hostNameArg dbName:dbNameArg userName:userNameArg password:passwordArg 
    "set instance variables (automatically generated)"

    hostName := hostNameArg.
    dbName := dbNameArg.
    userName := userNameArg.
    password := passwordArg.
!

password
    ^ password
!

password:something
    password := something.
!

userName
    ^ userName
!

userName:something
    userName := something.
! !

!StoreSourceCodeManager::DBInfo methodsFor:'printing and storing'!

storeOn:aStream
    aStream 
        nextPutAll:'(';
        nextPutAll:self class name;
        nextPutAll:' basicNew';
        nextPutAll:' hostAndDBName:';
        store: self hostAndDBName;
        nextPutAll:' userName:';
        store: self userName;
        nextPutAll:' password:';
        store: self password;
        nextPutAll:')'.

    "
     self readFrom:(self basicNew hostAndDBName:'a' userName:'b' password:'c') storeString
     self readFrom:(self basicNew hostAndDBName:'a@h' userName:'b' password:'c') storeString
    "
! !

!StoreSourceCodeManager class methodsFor:'documentation'!

version
    ^ '$Header: /cvs/stx/stx/libbasic3/StoreSourceCodeManager.st,v 1.5 2006-08-25 17:39:52 cg Exp $'
! !