import (
"context"
cconf "github.com/pip-services4/pip-services4-go/pip-services4-components-go/config"
cref "github.com/pip-services4/pip-services4-go/pip-services4-components-go/refer"
)
type MyCustomPersistence struct {
// Custom implementation using any persistence framework
}
func NewMyCustomPersistence() *MyCustomPersistence {
return &MyCustomPersistence{}
}
type MyCustomPersistenceWrapper struct {
config *cconf.ConfigParams
persistence *MyCustomPersistence
}
func NewMyCustomPersistenceWrapper() *MyCustomPersistenceWrapper {
return &MyCustomPersistenceWrapper{
config: cconf.NewConfigParams(map[string]string{}),
}
}
func (c *MyCustomPersistenceWrapper) Configure(ctx context.Context, config *cconf.ConfigParams) {
// Store config parameters
if config != nil {
c.config = config
}
}
func (c *MyCustomPersistenceWrapper) SetReferences(ctx context.Context, references cref.IReferences) {
// Retrieve whatever references you may need
}
func (c *MyCustomPersistenceWrapper) IsOpen() bool {
return c.persistence != nil
}
func (c *MyCustomPersistenceWrapper) Open(ctx context.Context, correlationId string) (err error) {
if c.persistence != nil {
return nil
}
// Create custom persistence
c.persistence = NewMyCustomPersistence()
// Configure custom persistence
// ...
// Open and connect to the database
c.persistence.Connect()
}
func (c *MyCustomPersistenceWrapper) Close(ctx context.Context, correlationId string) (err error) {
if c.persistence == nil {
return
}
// Disconnect from the database and close
c.persistence.Disconnect()
c.persistence = nil
}