Conditions | 11 |
Total Lines | 26 |
Code Lines | 23 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Complex classes like adapter.*oracleAdapter.ErrorHandler 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 | package adapter |
||
20 | func (s *oracleAdapter) ErrorHandler(err error) error { |
||
21 | if err == nil { |
||
22 | return nil |
||
23 | } |
||
24 | |||
25 | if oraError, ok := godror.AsOraErr(err); ok { |
||
26 | switch oraError.Code() { |
||
27 | case 1: //ORA-00001" |
||
28 | return sqlcommons.UniqueConstraintViolation |
||
29 | case 2291, 2292: //ORA-02291 (PKNotFound) AND ORA-02292 (ChildFound) |
||
30 | return sqlcommons.IntegrityConstraintViolation |
||
31 | case 12899: //ORA-12899 |
||
32 | return sqlcommons.ValueTooLargeForColumn |
||
33 | case 1438: //ORA-01438 |
||
34 | return sqlcommons.ValueLargerThanPrecision |
||
35 | case 1400, 1407: //ORA-01400 (cannot insert) AND ORA-01407 (cannot change value to) |
||
36 | return sqlcommons.CannotSetNullColumn |
||
37 | case 1722: //ORA-01722 |
||
38 | return sqlcommons.InvalidNumericValue |
||
39 | case 1427: //ORA-01427 |
||
40 | return sqlcommons.SubqueryReturnsMoreThanOneRow |
||
41 | default: |
||
42 | return fmt.Errorf("Unhandled Oracle error. Code:[%d] Desc:[%s]", oraError.Code(), oraError.Message()) |
||
43 | } |
||
44 | } else { |
||
45 | return err |
||
46 | } |
||
48 |