bpmn-lib 4.0.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bpmn_lib-4.0.5/LICENSE +21 -0
- bpmn_lib-4.0.5/PKG-INFO +129 -0
- bpmn_lib-4.0.5/README.md +77 -0
- bpmn_lib-4.0.5/pyproject.toml +29 -0
- bpmn_lib-4.0.5/setup.cfg +4 -0
- bpmn_lib-4.0.5/src/bpmn_lib/__init__.py +38 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/__init__.py +25 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/instance/__init__.py +13 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/instance/database_builder.py +151 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/instance/database_bulk_validator.py +350 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/instance/database_index_builder.py +112 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/instance/database_instance.py +413 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/__init__.py +15 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/column_definition.py +223 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/database_schema.py +167 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/database_schema_parser.py +374 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/foreign_key_relationship.py +139 -0
- bpmn_lib-4.0.5/src/bpmn_lib/database/schema/table_definition.py +245 -0
- bpmn_lib-4.0.5/src/bpmn_lib/navigator/__init__.py +80 -0
- bpmn_lib-4.0.5/src/bpmn_lib/navigator/bpmn_constants.py +52 -0
- bpmn_lib-4.0.5/src/bpmn_lib/navigator/bpmn_hierarchy_navigator.py +1423 -0
- bpmn_lib-4.0.5/src/bpmn_lib/navigator/navigator_factory.py +175 -0
- bpmn_lib-4.0.5/src/bpmn_lib/py.typed +1 -0
- bpmn_lib-4.0.5/src/bpmn_lib/utils/__init__.py +11 -0
- bpmn_lib-4.0.5/src/bpmn_lib/utils/validation_result.py +131 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/__init__.py +11 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/exceptions.py +5 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/expression_ast.py +78 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/expression_parser.py +232 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/rule_engine.py +267 -0
- bpmn_lib-4.0.5/src/bpmn_lib/validation/rule_store.py +191 -0
- bpmn_lib-4.0.5/src/bpmn_lib.egg-info/PKG-INFO +129 -0
- bpmn_lib-4.0.5/src/bpmn_lib.egg-info/SOURCES.txt +34 -0
- bpmn_lib-4.0.5/src/bpmn_lib.egg-info/dependency_links.txt +1 -0
- bpmn_lib-4.0.5/src/bpmn_lib.egg-info/requires.txt +7 -0
- bpmn_lib-4.0.5/src/bpmn_lib.egg-info/top_level.txt +1 -0
bpmn_lib-4.0.5/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hennig IT Consulting GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
bpmn_lib-4.0.5/PKG-INFO
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bpmn-lib
|
|
3
|
+
Version: 4.0.5
|
|
4
|
+
Summary: BPMN Process Navigation Library
|
|
5
|
+
Author-email: Hennig IT Consulting GmbH <contact@hennig-it-consulting.de>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2026 Hennig IT Consulting GmbH
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/hennig-ai/bpmn-lib
|
|
29
|
+
Project-URL: Repository, https://github.com/hennig-ai/bpmn-lib
|
|
30
|
+
Project-URL: Issues, https://github.com/hennig-ai/bpmn-lib
|
|
31
|
+
Classifier: Development Status :: 4 - Beta
|
|
32
|
+
Classifier: Intended Audience :: Developers
|
|
33
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
34
|
+
Classifier: Programming Language :: Python :: 3
|
|
35
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
36
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
37
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
38
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
39
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
40
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
41
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
42
|
+
Requires-Python: >=3.8
|
|
43
|
+
Description-Content-Type: text/markdown
|
|
44
|
+
License-File: LICENSE
|
|
45
|
+
Requires-Dist: basic-framework<4.0.0,>=3.0.0
|
|
46
|
+
Provides-Extra: dev
|
|
47
|
+
Requires-Dist: pytest>=8.0.0; extra == "dev"
|
|
48
|
+
Requires-Dist: pytest-cov>=5.0.0; extra == "dev"
|
|
49
|
+
Requires-Dist: pytest-xdist>=3.5.0; extra == "dev"
|
|
50
|
+
Requires-Dist: pyright>=1.1.0; extra == "dev"
|
|
51
|
+
Dynamic: license-file
|
|
52
|
+
|
|
53
|
+
# bpmn-lib
|
|
54
|
+
|
|
55
|
+
A Python library for navigating BPMN (Business Process Model and Notation) element hierarchies and managing in-memory process data. Designed for use in Python-based process automation and tooling pipelines.
|
|
56
|
+
|
|
57
|
+
## What it does
|
|
58
|
+
|
|
59
|
+
bpmn-lib lets you load a BPMN process model from markdown-defined schemas and data files, then navigate it programmatically:
|
|
60
|
+
|
|
61
|
+
- Traverse parent-child element hierarchies (e.g. `bpmn_element → activity → task → user_task`)
|
|
62
|
+
- Navigate sequence flows forward and backward
|
|
63
|
+
- Query element attributes across inheritance chains
|
|
64
|
+
- Resolve data associations (inputs/outputs)
|
|
65
|
+
- Validate element type specificity and FK constraints
|
|
66
|
+
|
|
67
|
+
## Installation
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
pip install bpmn-lib
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Install with dev dependencies (for development):
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
pip install -e ".[dev]"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Quick Start
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from bpmn_lib.navigator.navigator_factory import create_navigator
|
|
83
|
+
|
|
84
|
+
navigator = create_navigator(
|
|
85
|
+
schema_file="path/to/schema.md",
|
|
86
|
+
data_file="path/to/data.md",
|
|
87
|
+
hierarchy_file="path/to/hierarchy.md",
|
|
88
|
+
log_dir="path/to/logs",
|
|
89
|
+
schema_name="My BPMN Schema"
|
|
90
|
+
)
|
|
91
|
+
|
|
92
|
+
# Navigate sequence flows
|
|
93
|
+
next_elements = navigator.next_elements_in_flow(element_id)
|
|
94
|
+
|
|
95
|
+
# Get all elements in a process
|
|
96
|
+
elements = navigator.get_process_elements(process_id)
|
|
97
|
+
|
|
98
|
+
# Read an attribute (traverses inheritance chain)
|
|
99
|
+
value = navigator.get_element_attribute(element_id, "attribute_name")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Architecture
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
┌─────────────────────────────────────┐
|
|
106
|
+
│ Navigation Layer │ ← BPMNHierarchyNavigator
|
|
107
|
+
├─────────────────────────────────────┤
|
|
108
|
+
│ Database Instance Layer │ ← DatabaseInstance, DatabaseBuilder
|
|
109
|
+
├─────────────────────────────────────┤
|
|
110
|
+
│ Database Schema Layer │ ← DatabaseSchema, TableDefinition
|
|
111
|
+
├─────────────────────────────────────┤
|
|
112
|
+
│ Parsing Layer │ ← DatabaseSchemaParser, MarkdownDocument
|
|
113
|
+
└─────────────────────────────────────┘
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
Schema definitions and instance data are loaded from markdown files. The factory function orchestrates the full pipeline: parse schema → load data → validate constraints → build indexes → create navigator.
|
|
117
|
+
|
|
118
|
+
## Testing
|
|
119
|
+
|
|
120
|
+
```bash
|
|
121
|
+
pytest tests/ -v
|
|
122
|
+
pytest tests/unit/ -v
|
|
123
|
+
pytest tests/integration/ -v
|
|
124
|
+
pytest tests/ --cov=bpmn_lib --cov-report=term-missing
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## License
|
|
128
|
+
|
|
129
|
+
MIT — see [LICENSE](LICENSE)
|
bpmn_lib-4.0.5/README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
# bpmn-lib
|
|
2
|
+
|
|
3
|
+
A Python library for navigating BPMN (Business Process Model and Notation) element hierarchies and managing in-memory process data. Designed for use in Python-based process automation and tooling pipelines.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
bpmn-lib lets you load a BPMN process model from markdown-defined schemas and data files, then navigate it programmatically:
|
|
8
|
+
|
|
9
|
+
- Traverse parent-child element hierarchies (e.g. `bpmn_element → activity → task → user_task`)
|
|
10
|
+
- Navigate sequence flows forward and backward
|
|
11
|
+
- Query element attributes across inheritance chains
|
|
12
|
+
- Resolve data associations (inputs/outputs)
|
|
13
|
+
- Validate element type specificity and FK constraints
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install bpmn-lib
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
Install with dev dependencies (for development):
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
pip install -e ".[dev]"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
```python
|
|
30
|
+
from bpmn_lib.navigator.navigator_factory import create_navigator
|
|
31
|
+
|
|
32
|
+
navigator = create_navigator(
|
|
33
|
+
schema_file="path/to/schema.md",
|
|
34
|
+
data_file="path/to/data.md",
|
|
35
|
+
hierarchy_file="path/to/hierarchy.md",
|
|
36
|
+
log_dir="path/to/logs",
|
|
37
|
+
schema_name="My BPMN Schema"
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Navigate sequence flows
|
|
41
|
+
next_elements = navigator.next_elements_in_flow(element_id)
|
|
42
|
+
|
|
43
|
+
# Get all elements in a process
|
|
44
|
+
elements = navigator.get_process_elements(process_id)
|
|
45
|
+
|
|
46
|
+
# Read an attribute (traverses inheritance chain)
|
|
47
|
+
value = navigator.get_element_attribute(element_id, "attribute_name")
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Architecture
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
┌─────────────────────────────────────┐
|
|
54
|
+
│ Navigation Layer │ ← BPMNHierarchyNavigator
|
|
55
|
+
├─────────────────────────────────────┤
|
|
56
|
+
│ Database Instance Layer │ ← DatabaseInstance, DatabaseBuilder
|
|
57
|
+
├─────────────────────────────────────┤
|
|
58
|
+
│ Database Schema Layer │ ← DatabaseSchema, TableDefinition
|
|
59
|
+
├─────────────────────────────────────┤
|
|
60
|
+
│ Parsing Layer │ ← DatabaseSchemaParser, MarkdownDocument
|
|
61
|
+
└─────────────────────────────────────┘
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Schema definitions and instance data are loaded from markdown files. The factory function orchestrates the full pipeline: parse schema → load data → validate constraints → build indexes → create navigator.
|
|
65
|
+
|
|
66
|
+
## Testing
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
pytest tests/ -v
|
|
70
|
+
pytest tests/unit/ -v
|
|
71
|
+
pytest tests/integration/ -v
|
|
72
|
+
pytest tests/ --cov=bpmn_lib --cov-report=term-missing
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
## License
|
|
76
|
+
|
|
77
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = [ "setuptools>=45", "wheel",]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bpmn-lib"
|
|
7
|
+
version = "4.0.5"
|
|
8
|
+
description = "BPMN Process Navigation Library"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.8"
|
|
11
|
+
classifiers = [ "Development Status :: 4 - Beta", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Topic :: Software Development :: Libraries",]
|
|
12
|
+
dependencies = [ "basic-framework>=3.0.0,<4.0.0",]
|
|
13
|
+
[[project.authors]]
|
|
14
|
+
name = "Hennig IT Consulting GmbH"
|
|
15
|
+
email = "contact@hennig-it-consulting.de"
|
|
16
|
+
|
|
17
|
+
[project.license]
|
|
18
|
+
file = "LICENSE"
|
|
19
|
+
|
|
20
|
+
[project.urls]
|
|
21
|
+
Homepage = "https://github.com/hennig-ai/bpmn-lib"
|
|
22
|
+
Repository = "https://github.com/hennig-ai/bpmn-lib"
|
|
23
|
+
Issues = "https://github.com/hennig-ai/bpmn-lib"
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
dev = [ "pytest>=8.0.0", "pytest-cov>=5.0.0", "pytest-xdist>=3.5.0", "pyright>=1.1.0",]
|
|
27
|
+
|
|
28
|
+
[tool.setuptools.packages.find]
|
|
29
|
+
where = [ "src",]
|
bpmn_lib-4.0.5/setup.cfg
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"""
|
|
2
|
+
BPMN Process Navigation Library.
|
|
3
|
+
|
|
4
|
+
This library provides classes for navigating and managing BPMN element hierarchies,
|
|
5
|
+
database schema definitions, and validation utilities.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from bpmn_lib.navigator.bpmn_hierarchy_navigator import BPMNHierarchyNavigator
|
|
9
|
+
from bpmn_lib.database.instance.database_instance import DatabaseInstance
|
|
10
|
+
from bpmn_lib.database.instance.database_builder import DatabaseBuilder
|
|
11
|
+
from bpmn_lib.database.schema.database_schema import DatabaseSchema
|
|
12
|
+
from bpmn_lib.database.schema.database_schema_parser import DatabaseSchemaParser
|
|
13
|
+
from bpmn_lib.database.schema.table_definition import TableDefinition
|
|
14
|
+
from bpmn_lib.database.schema.column_definition import ColumnDefinition
|
|
15
|
+
from bpmn_lib.database.schema.foreign_key_relationship import ForeignKeyRelationship
|
|
16
|
+
from bpmn_lib.utils.validation_result import ValidationResult
|
|
17
|
+
from basic_framework import MarkdownDocument
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
# Navigator
|
|
21
|
+
"BPMNHierarchyNavigator",
|
|
22
|
+
# Database Instance
|
|
23
|
+
"DatabaseInstance",
|
|
24
|
+
"DatabaseBuilder",
|
|
25
|
+
# Database Schema
|
|
26
|
+
"DatabaseSchema",
|
|
27
|
+
"DatabaseSchemaParser",
|
|
28
|
+
"TableDefinition",
|
|
29
|
+
"ColumnDefinition",
|
|
30
|
+
"ForeignKeyRelationship",
|
|
31
|
+
# Utils
|
|
32
|
+
"ValidationResult",
|
|
33
|
+
"MarkdownDocument",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
from importlib.metadata import version
|
|
37
|
+
|
|
38
|
+
__version__: str = version("bpmn-lib")
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Database module for schema and instance management."""
|
|
2
|
+
|
|
3
|
+
from bpmn_lib.database.schema.database_schema import DatabaseSchema
|
|
4
|
+
from bpmn_lib.database.schema.database_schema_parser import DatabaseSchemaParser
|
|
5
|
+
from bpmn_lib.database.schema.table_definition import TableDefinition
|
|
6
|
+
from bpmn_lib.database.schema.column_definition import ColumnDefinition
|
|
7
|
+
from bpmn_lib.database.schema.foreign_key_relationship import ForeignKeyRelationship
|
|
8
|
+
from bpmn_lib.database.instance.database_instance import DatabaseInstance
|
|
9
|
+
from bpmn_lib.database.instance.database_builder import DatabaseBuilder
|
|
10
|
+
from bpmn_lib.database.instance.database_bulk_validator import DatabaseBulkValidator
|
|
11
|
+
from bpmn_lib.database.instance.database_index_builder import DatabaseIndexBuilder
|
|
12
|
+
|
|
13
|
+
__all__ = [
|
|
14
|
+
# Schema
|
|
15
|
+
"DatabaseSchema",
|
|
16
|
+
"DatabaseSchemaParser",
|
|
17
|
+
"TableDefinition",
|
|
18
|
+
"ColumnDefinition",
|
|
19
|
+
"ForeignKeyRelationship",
|
|
20
|
+
# Instance
|
|
21
|
+
"DatabaseInstance",
|
|
22
|
+
"DatabaseBuilder",
|
|
23
|
+
"DatabaseBulkValidator",
|
|
24
|
+
"DatabaseIndexBuilder",
|
|
25
|
+
]
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Database instance module."""
|
|
2
|
+
|
|
3
|
+
from bpmn_lib.database.instance.database_instance import DatabaseInstance
|
|
4
|
+
from bpmn_lib.database.instance.database_builder import DatabaseBuilder
|
|
5
|
+
from bpmn_lib.database.instance.database_bulk_validator import DatabaseBulkValidator
|
|
6
|
+
from bpmn_lib.database.instance.database_index_builder import DatabaseIndexBuilder
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
"DatabaseInstance",
|
|
10
|
+
"DatabaseBuilder",
|
|
11
|
+
"DatabaseBulkValidator",
|
|
12
|
+
"DatabaseIndexBuilder",
|
|
13
|
+
]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""
|
|
2
|
+
DatabaseBuilder - Koordiniert den Aufbau der Datenbank in Phasen.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Dict
|
|
6
|
+
from basic_framework.proc_frame import log_msg, log_and_raise
|
|
7
|
+
from basic_framework.container_utils.container_in_memory import ContainerInMemory
|
|
8
|
+
from basic_framework.container_utils.abstract_container import AbstractContainer
|
|
9
|
+
from bpmn_lib.database.schema.database_schema import DatabaseSchema
|
|
10
|
+
from bpmn_lib.database.instance.database_instance import DatabaseInstance
|
|
11
|
+
from bpmn_lib.utils.validation_result import ValidationResult
|
|
12
|
+
from bpmn_lib.database.instance.database_bulk_validator import DatabaseBulkValidator
|
|
13
|
+
from bpmn_lib.database.instance.database_index_builder import DatabaseIndexBuilder
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DatabaseBuilder:
|
|
17
|
+
"""Koordiniert den Aufbau der Datenbank in Phasen."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, schema: DatabaseSchema, result: ValidationResult) -> None:
|
|
20
|
+
"""
|
|
21
|
+
Initialisiert den DatabaseBuilder.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
schema: DatabaseSchema mit Tabellendefinitionen
|
|
25
|
+
result: ValidationResult für Fehlerberichte
|
|
26
|
+
|
|
27
|
+
Raises:
|
|
28
|
+
TypeError: Wenn schema oder result None ist (Python's Typsystem)
|
|
29
|
+
"""
|
|
30
|
+
self._schema: DatabaseSchema = schema
|
|
31
|
+
|
|
32
|
+
# DatabaseInstance erstellen mit neuem Konstruktor
|
|
33
|
+
self._instance: DatabaseInstance = DatabaseInstance(self._schema)
|
|
34
|
+
|
|
35
|
+
# Validator und IndexBuilder erstellen mit neuen Konstruktoren
|
|
36
|
+
self._bulk_validator: DatabaseBulkValidator = DatabaseBulkValidator(self._instance, result)
|
|
37
|
+
self._index_builder: DatabaseIndexBuilder = DatabaseIndexBuilder(self._instance)
|
|
38
|
+
|
|
39
|
+
log_msg(f"DatabaseBuilder fuer Schema '{self._schema.get_schema_name()}' initialisiert.")
|
|
40
|
+
|
|
41
|
+
def load_all_data(self, o_data_source: Dict[str, ContainerInMemory]) -> None:
|
|
42
|
+
"""Laedt alle Daten ohne Constraint-Pruefung."""
|
|
43
|
+
log_msg("Starte Bulk-Load der Daten...")
|
|
44
|
+
self._load_from_container_dictionary(o_data_source)
|
|
45
|
+
|
|
46
|
+
def _load_from_container_dictionary(self, o_container_dict: Dict[str, ContainerInMemory]) -> None:
|
|
47
|
+
"""Laedt Daten aus einem Dictionary von ContainerInMemory-Objekten."""
|
|
48
|
+
n_total_rows = 0
|
|
49
|
+
|
|
50
|
+
# Fuer jede Tabelle im Dictionary
|
|
51
|
+
for v_table_name in o_container_dict.keys():
|
|
52
|
+
s_table_name = str(v_table_name)
|
|
53
|
+
|
|
54
|
+
# Pruefen ob Tabelle im Schema existiert
|
|
55
|
+
if not self._table_exists_in_schema(s_table_name):
|
|
56
|
+
log_msg(f"WARNUNG: Tabelle '{s_table_name}' existiert nicht im Schema und wird uebersprungen.")
|
|
57
|
+
continue
|
|
58
|
+
|
|
59
|
+
# Source Container holen
|
|
60
|
+
o_source_container = o_container_dict[s_table_name]
|
|
61
|
+
|
|
62
|
+
# Iterator fuer Source erstellen
|
|
63
|
+
o_source_iterator = o_source_container.create_iterator()
|
|
64
|
+
|
|
65
|
+
# Zeilen kopieren
|
|
66
|
+
n_row_count = 0
|
|
67
|
+
|
|
68
|
+
while not o_source_iterator.is_empty():
|
|
69
|
+
# Zeile in Ziel-Tabelle einfuegen
|
|
70
|
+
if self._instance.insert_row_from_iterator(s_table_name, o_source_iterator):
|
|
71
|
+
n_row_count += 1
|
|
72
|
+
|
|
73
|
+
o_source_iterator.pp()
|
|
74
|
+
|
|
75
|
+
# Log-Nachricht alle 1000 Zeilen
|
|
76
|
+
if n_row_count % 1000 == 0:
|
|
77
|
+
pass # log_msg(f"Tabelle '{s_table_name}': {n_row_count} Zeilen geladen")
|
|
78
|
+
|
|
79
|
+
# log_msg(f"Tabelle '{s_table_name}': {n_row_count} Zeilen geladen.")
|
|
80
|
+
n_total_rows += n_row_count
|
|
81
|
+
|
|
82
|
+
# log_msg(f"Bulk-Load abgeschlossen. Insgesamt {n_total_rows} Zeilen geladen.")
|
|
83
|
+
|
|
84
|
+
def load_table_data(self, s_table_name: str, o_source_container: AbstractContainer) -> None:
|
|
85
|
+
"""Laedt Daten fuer eine einzelne Tabelle."""
|
|
86
|
+
# Pruefen ob Tabelle im Schema existiert
|
|
87
|
+
if not self._table_exists_in_schema(s_table_name):
|
|
88
|
+
log_and_raise(f"Tabelle '{s_table_name}' existiert nicht im Schema.")
|
|
89
|
+
|
|
90
|
+
# log_msg(f"Lade Daten fuer Tabelle '{s_table_name}'...")
|
|
91
|
+
|
|
92
|
+
# Iterator fuer Source erstellen
|
|
93
|
+
o_source_iterator = o_source_container.create_iterator()
|
|
94
|
+
|
|
95
|
+
# Zeilen kopieren
|
|
96
|
+
n_row_count = 0
|
|
97
|
+
|
|
98
|
+
while not o_source_iterator.is_empty():
|
|
99
|
+
# Zeile in Ziel-Tabelle einfuegen
|
|
100
|
+
if self._instance.insert_row_from_iterator(s_table_name, o_source_iterator):
|
|
101
|
+
n_row_count += 1
|
|
102
|
+
|
|
103
|
+
o_source_iterator.pp()
|
|
104
|
+
|
|
105
|
+
# Log-Nachricht alle 1000 Zeilen
|
|
106
|
+
if n_row_count % 1000 == 0:
|
|
107
|
+
pass # log_msg(f"Tabelle '{s_table_name}': {n_row_count} Zeilen geladen")
|
|
108
|
+
|
|
109
|
+
# log_msg(f"Tabelle '{s_table_name}': {n_row_count} Zeilen geladen.")
|
|
110
|
+
|
|
111
|
+
def validate_all_constraints(self) -> None:
|
|
112
|
+
"""Prueft nachtraeglich alle Constraints."""
|
|
113
|
+
log_msg("Starte Validierung aller Constraints...")
|
|
114
|
+
|
|
115
|
+
# BulkValidator ausfuehren
|
|
116
|
+
self._bulk_validator.validate_all()
|
|
117
|
+
|
|
118
|
+
def build_indexes_if_valid(self) -> None:
|
|
119
|
+
"""Erstellt Indizes nur bei erfolgreicher Validierung."""
|
|
120
|
+
# log_msg("Erstelle Indizes...")
|
|
121
|
+
|
|
122
|
+
# IndexBuilder ausfuehren
|
|
123
|
+
self._index_builder.build_all_indexes()
|
|
124
|
+
|
|
125
|
+
# log_msg("Indizes erfolgreich erstellt.")
|
|
126
|
+
|
|
127
|
+
def create_read_only_database(self) -> DatabaseInstance:
|
|
128
|
+
"""Gibt fertige DatabaseInstance zurueck."""
|
|
129
|
+
# Pruefen ob alle Schritte durchgefuehrt wurden
|
|
130
|
+
if not self._instance.is_finalized():
|
|
131
|
+
log_and_raise("create_read_only_database: Indizes wurden nicht erstellt.")
|
|
132
|
+
|
|
133
|
+
# Instanz auf Read-Only setzen
|
|
134
|
+
self._instance.set_read_only()
|
|
135
|
+
|
|
136
|
+
log_msg("Read-Only Datenbank erfolgreich erstellt.")
|
|
137
|
+
return self._instance
|
|
138
|
+
|
|
139
|
+
def _table_exists_in_schema(self, s_table_name: str) -> bool:
|
|
140
|
+
"""Hilfsmethode - Prueft ob Tabelle im Schema existiert."""
|
|
141
|
+
o_table_names = self._schema.get_table_names()
|
|
142
|
+
|
|
143
|
+
for v_name in o_table_names:
|
|
144
|
+
if str(v_name) == s_table_name:
|
|
145
|
+
return True
|
|
146
|
+
|
|
147
|
+
return False
|
|
148
|
+
|
|
149
|
+
def get_instance(self) -> DatabaseInstance:
|
|
150
|
+
"""Gibt die DatabaseInstance zurueck (auch vor Finalisierung)."""
|
|
151
|
+
return self._instance
|