pystratum_mssql.wrapper.create_routine_wrapper()   C
last analyzed

Complexity

Conditions 11

Size

Total Lines 33
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 23
dl 0
loc 33
rs 5.4
c 0
b 0
f 0
cc 11
nop 2

How to fix   Complexity   

Complexity

Complex classes like pystratum_mssql.wrapper.create_routine_wrapper() often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
from pystratum_mssql.wrapper.MsSqlFunctionsWrapper import MsSqlFunctionsWrapper
2
from pystratum_mssql.wrapper.MsSqlLogWrapper import MsSqlLogWrapper
3
from pystratum_mssql.wrapper.MsSqlNoneWrapper import MsSqlNoneWrapper
4
from pystratum_mssql.wrapper.MsSqlRow0Wrapper import MsSqlRow0Wrapper
5
from pystratum_mssql.wrapper.MsSqlRow1Wrapper import MsSqlRow1Wrapper
6
from pystratum_mssql.wrapper.MsSqlRowsWithIndexWrapper import MsSqlRowsWithIndexWrapper
7
from pystratum_mssql.wrapper.MsSqlRowsWithKeyWrapper import MsSqlRowsWithKeyWrapper
8
from pystratum_mssql.wrapper.MsSqlRowsWrapper import MsSqlRowsWrapper
9
from pystratum_mssql.wrapper.MsSqlSingleton0Wrapper import MsSqlSingleton0Wrapper
10
from pystratum_mssql.wrapper.MsSqlSingleton1Wrapper import MsSqlSingleton1Wrapper
11
12
13
def create_routine_wrapper(routine, lob_as_string_flag):
14
    """
15
    A factory for creating the appropriate object for generating a wrapper method for a stored routine.
16
    
17
    :param dict[str,str] routine: The metadata of the sored routine. 
18
    :param bool lob_as_string_flag: If True BLOBs and CLOBs must be treated as strings.
19
20
    :rtype: pystratum.mssql.wrapper.MsSqlWrapper.MsSqlWrapper
21
    """
22
    if routine['designation'] == 'none':
23
        wrapper = MsSqlNoneWrapper(routine, lob_as_string_flag)
24
    elif routine['designation'] == 'row0':
25
        wrapper = MsSqlRow0Wrapper(routine, lob_as_string_flag)
26
    elif routine['designation'] == 'row1':
27
        wrapper = MsSqlRow1Wrapper(routine, lob_as_string_flag)
28
    elif routine['designation'] == 'rows':
29
        wrapper = MsSqlRowsWrapper(routine, lob_as_string_flag)
30
    elif routine['designation'] == 'rows_with_index':
31
        wrapper = MsSqlRowsWithIndexWrapper(routine, lob_as_string_flag)
32
    elif routine['designation'] == 'rows_with_key':
33
        wrapper = MsSqlRowsWithKeyWrapper(routine, lob_as_string_flag)
34
    elif routine['designation'] == 'singleton0':
35
        wrapper = MsSqlSingleton0Wrapper(routine, lob_as_string_flag)
36
    elif routine['designation'] == 'singleton1':
37
        wrapper = MsSqlSingleton1Wrapper(routine, lob_as_string_flag)
38
    elif routine['designation'] == 'function':
39
        wrapper = MsSqlFunctionsWrapper(routine, lob_as_string_flag)
40
    elif routine['designation'] == 'log':
41
        wrapper = MsSqlLogWrapper(routine, lob_as_string_flag)
42
    else:
43
        raise Exception("Unknown routine type '{0!s}'.".format(routine['designation']))
44
45
    return wrapper
46
47
    # ----------------------------------------------------------------------------------------------------------------------
48