Documentation
¶
Overview ¶
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016-2017 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package dao provides a data access object library.
Copyright 2016 Pedro Salgado ¶
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func NewUnknownDAO(nm string) error
- func NewUnknownFactory(nm string) error
- func Process(m Manager, f TransactionFunc) (err error)
- type BaseFactory
- type BaseManager
- func (m *BaseManager) CommitTransaction(ctx *Context) error
- func (m *BaseManager) CreateDAO(ctx *Context, nm string) (interface{}, error)
- func (m *BaseManager) EndTransaction(ctx *Context)
- func (m *BaseManager) RegisterDataSource(ds *DataSource)
- func (m *BaseManager) RegisterFactory(f Factory)
- func (m *BaseManager) RollbackTransaction(ctx *Context) error
- func (m *BaseManager) Source(nm string) *DataSource
- func (m *BaseManager) StartTransaction() (*Context, error)
- type Context
- type DataAccessObject
- type DataSource
- type Factory
- type FactoryFunc
- type Manager
- type TransactionFunc
- type UnknownDAO
- type UnknownFactory
Constants ¶
const ( // UnknownDAOMessage error message format for the UnknownDAOError. UnknownDAOMessage = "There is no implementation registered for the %s data access object" // UnknownFactoryMessage error message format for the UnknownFactoryError. UnknownFactoryMessage = "There is no factory registered for the %s data access object" )
Variables ¶
This section is empty.
Functions ¶
func NewUnknownFactory ¶
NewUnknownFactory returns a UnknownFactoryError error.
func Process ¶
func Process(m Manager, f TransactionFunc) (err error)
Process wrap database transaction handling around given TransactionFunc.
Types ¶
type BaseFactory ¶
type BaseFactory struct {
// Source target data source against which to generate data access objects.
Source *DataSource
// FactoryFuncs maps data access object names to the factory functions.
FactoryFuncs map[string]FactoryFunc
}
BaseFactory base type to build data access object factories.
func (*BaseFactory) DataAccessObjects ¶
func (f *BaseFactory) DataAccessObjects() []string
DataAccessObjects returns the list of data access object names the factory can generate.
func (*BaseFactory) NewDataAccessObject ¶
func (f *BaseFactory) NewDataAccessObject(ctx *Context, nm string) (interface{}, error)
NewDataAccessObject returns a data access object.
type BaseManager ¶
type BaseManager struct {
Sources map[string]*DataSource
Factories map[string]Factory
}
BaseManager base implementation of the Manager interface.
func NewBaseManager ¶
func NewBaseManager() *BaseManager
NewBaseManager returns a generic Manager implementation.
func (*BaseManager) CommitTransaction ¶
func (m *BaseManager) CommitTransaction(ctx *Context) error
CommitTransaction commits the context database transaction.
func (*BaseManager) CreateDAO ¶
func (m *BaseManager) CreateDAO(ctx *Context, nm string) (interface{}, error)
CreateDAO returns a new data access object.
func (*BaseManager) EndTransaction ¶
func (m *BaseManager) EndTransaction(ctx *Context)
EndTransaction ends the context database transaction.
func (*BaseManager) RegisterDataSource ¶
func (m *BaseManager) RegisterDataSource(ds *DataSource)
RegisterDataSource registers a new mapping between a name and a data source.
func (*BaseManager) RegisterFactory ¶
func (m *BaseManager) RegisterFactory(f Factory)
RegisterFactory registers the given factory with the data access object names it can generate.
func (*BaseManager) RollbackTransaction ¶
func (m *BaseManager) RollbackTransaction(ctx *Context) error
RollbackTransaction rollback the context database transaction.
func (*BaseManager) Source ¶
func (m *BaseManager) Source(nm string) *DataSource
Source returns the data source associated with the given name.
func (*BaseManager) StartTransaction ¶
func (m *BaseManager) StartTransaction() (*Context, error)
StartTransaction start the context database transaction.
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context struct to hold database transaction contexts.
func NewContext ¶
NewContext returns a new database transaction context.
func (*Context) NewDataAccessObject ¶
func (ctx *Context) NewDataAccessObject(nm string) (*DataAccessObject, error)
NewDataAccessObject returns a data access object with an active database transaction.
type DataAccessObject ¶
DataAccessObject base struct for data access objects.
func (*DataAccessObject) SetTransaction ¶
func (dao *DataAccessObject) SetTransaction(tx *sql.Tx)
SetTransaction sets this data access object's database transaction.
func (*DataAccessObject) Transaction ¶
func (dao *DataAccessObject) Transaction() *sql.Tx
Transaction returns this data access object's database transaction.
type DataSource ¶
type DataSource struct {
// DB the database.
DB *sql.DB
// Name the name of the data source.
Name string
}
DataSource struct to represent data sources whose target are databases.
type Factory ¶
type Factory interface {
// DataAccessObjects returns the list of data access object names the factory can generate.
DataAccessObjects() []string
// NewDataAccessObject returns a data access object.
NewDataAccessObject(ctx *Context, nm string) (interface{}, error)
}
Factory interface for data access object factories.
type FactoryFunc ¶
FactoryFunc function to generate data access object implementations.
type Manager ¶
type Manager interface {
// CommitTransaction commits the context database transaction.
CommitTransaction(ctx *Context) error
// CreateDAO returns a new data access object.
CreateDAO(ctx *Context, nm string) (interface{}, error)
// EndTransaction ends the context database transaction.
EndTransaction(ctx *Context)
// RegisterDataSource registers a new mapping between a name and a data source.
RegisterDataSource(ds *DataSource)
// RegisterFactory registers the given factory with the data access object names it can generate.
RegisterFactory(f Factory)
// RollbackTransaction rollback the context database transaction.
RollbackTransaction(ctx *Context) error
// Source returns the data source associated with the given name.
Source(nm string) *DataSource
// StartTransaction start the context database transaction.
StartTransaction() (*Context, error)
}
Manager interface for data access object managers.
type TransactionFunc ¶
TransactionFunc definition of a function wrapped in a database transaction context.
type UnknownDAO ¶
type UnknownDAO struct {
// contains filtered or unexported fields
}
UnknownDAO no data access object implementation registered with the given name.
type UnknownFactory ¶
type UnknownFactory struct {
// contains filtered or unexported fields
}
UnknownFactory no data access object implementation registered with the given name.
func (*UnknownFactory) Error ¶
func (e *UnknownFactory) Error() string
Error returns the error message.