|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ChangeFactory | Line # 19 | 27 | 0% | 15 | 10 | 75.6% |
0.75609756
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
| (18) | |||
| Result | |||
|
0.46341464
|
liquibase.change.core.ChangeFactoryTest.reset
liquibase.change.core.ChangeFactoryTest.reset
|
1 PASS | |
|
0.36585367
|
liquibase.change.core.ChangeFactoryTest.unregister_doesNotExist
liquibase.change.core.ChangeFactoryTest.unregister_doesNotExist
|
1 PASS | |
|
0.36585367
|
liquibase.change.core.ChangeFactoryTest.unregister_instance
liquibase.change.core.ChangeFactoryTest.unregister_instance
|
1 PASS | |
|
0.31707317
|
liquibase.change.core.ChangeFactoryTest.register
liquibase.change.core.ChangeFactoryTest.register
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.otherNamespaceAttributesChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.otherNamespaceAttributesChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.simpleChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.simpleChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.nestedRelativeChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.nestedRelativeChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.multiChangeSetChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.multiChangeSetChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedRelativeChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedRelativeChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.preconditionsChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.preconditionsChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.doubleNestedChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.logicalPathChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.logicalPathChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.testNestedChangeLog
liquibase.parser.core.xml.XMLChangeLogSAXParserTest.testNestedChangeLog
|
1 PASS | |
|
0.24390244
|
liquibase.change.core.ChangeFactoryTest.create_exists
liquibase.change.core.ChangeFactoryTest.create_exists
|
1 PASS | |
|
0.2195122
|
liquibase.change.core.ChangeFactoryTest.create_notExists
liquibase.change.core.ChangeFactoryTest.create_notExists
|
1 PASS | |
|
0.14634146
|
liquibase.change.core.ChangeFactoryTest.builtInGeneratorsAreFound
liquibase.change.core.ChangeFactoryTest.builtInGeneratorsAreFound
|
1 PASS | |
|
0.14634146
|
liquibase.serializer.core.string.StringChangeLogSerializerTest.tryAllChanges
liquibase.serializer.core.string.StringChangeLogSerializerTest.tryAllChanges
|
1 PASS | |
|
0.09756097
|
liquibase.change.core.ChangeFactoryTest.getInstance
liquibase.change.core.ChangeFactoryTest.getInstance
|
1 PASS | |
| 1 | package liquibase.change; | |
| 2 | ||
| 3 | import java.util.Comparator; | |
| 4 | import java.util.Map; | |
| 5 | import java.util.SortedSet; | |
| 6 | import java.util.TreeSet; | |
| 7 | import java.util.concurrent.ConcurrentHashMap; | |
| 8 | ||
| 9 | import liquibase.exception.UnexpectedLiquibaseException; | |
| 10 | import liquibase.servicelocator.ServiceLocator; | |
| 11 | ||
| 12 | /** | |
| 13 | * Factory class for constructing the correct liquibase.change.Change implementation based on the tag name. It is | |
| 14 | * currently implemented by a static array of Change implementations, although that may change in later revisions. The | |
| 15 | * best way to get an instance of ChangeFactory is off the Liquibase.getChangeFactory() method. | |
| 16 | * | |
| 17 | * @see liquibase.change.Change | |
| 18 | */ | |
| 19 | public class ChangeFactory { | |
| 20 | ||
| 21 | private static ChangeFactory instance; | |
| 22 | ||
| 23 | private Map<String, SortedSet<Class<? extends Change>>> registry = new ConcurrentHashMap<String, SortedSet<Class<? extends Change>>>(); | |
| 24 | ||
| 25 | 9 |
private ChangeFactory() { |
| 26 | 9 | Class<? extends Change>[] classes; |
| 27 | 9 | try { |
| 28 | 9 | classes = ServiceLocator.getInstance().findClasses(Change.class); |
| 29 | ||
| 30 | 9 | for (Class<? extends Change> clazz : classes) { |
| 31 | // noinspection unchecked | |
| 32 | 387 | register(clazz); |
| 33 | } | |
| 34 | ||
| 35 | } catch (Exception e) { | |
| 36 | 0 | throw new UnexpectedLiquibaseException(e); |
| 37 | } | |
| 38 | ||
| 39 | } | |
| 40 | ||
| 41 | /** | |
| 42 | * Return singleton SqlGeneratorFactory | |
| 43 | */ | |
| 44 | 38 |
public static synchronized ChangeFactory getInstance() { |
| 45 | 38 | if (instance == null) { |
| 46 | 0 | instance = new ChangeFactory(); |
| 47 | } | |
| 48 | 38 | return instance; |
| 49 | } | |
| 50 | ||
| 51 | 9 |
public static void reset() { |
| 52 | 9 | instance = new ChangeFactory(); |
| 53 | } | |
| 54 | ||
| 55 | 394 |
public void register(Class<? extends Change> changeClass) { |
| 56 | 394 | try { |
| 57 | 394 | String name = changeClass.newInstance().getChangeMetaData().getName(); |
| 58 | 394 | if (registry.get(name) == null) { |
| 59 | 394 | registry.put(name, new TreeSet<Class<? extends Change>>(new Comparator<Class<? extends Change>>() { |
| 60 | 0 |
public int compare(Class<? extends Change> o1, Class<? extends Change> o2) { |
| 61 | 0 | try { |
| 62 | 0 | return -1 |
| 63 | * new Integer(o1.newInstance().getChangeMetaData().getPriority()).compareTo(o2 | |
| 64 | .newInstance().getChangeMetaData().getPriority()); | |
| 65 | } catch (Exception e) { | |
| 66 | 0 | throw new UnexpectedLiquibaseException(e); |
| 67 | } | |
| 68 | } | |
| 69 | })); | |
| 70 | } | |
| 71 | 394 | registry.get(name).add(changeClass); |
| 72 | } catch (Exception e) { | |
| 73 | 0 | throw new UnexpectedLiquibaseException(e); |
| 74 | } | |
| 75 | } | |
| 76 | ||
| 77 | 2 |
public void unregister(String name) { |
| 78 | 2 | registry.remove(name); |
| 79 | } | |
| 80 | ||
| 81 | 13 |
public Map<String, SortedSet<Class<? extends Change>>> getRegistry() { |
| 82 | 13 | return registry; |
| 83 | } | |
| 84 | ||
| 85 | 25 |
public Change create(String name) { |
| 86 | 25 | SortedSet<Class<? extends Change>> classes = registry.get(name); |
| 87 | ||
| 88 | 25 | if (classes == null) { |
| 89 | 1 | return null; |
| 90 | } | |
| 91 | ||
| 92 | 24 | try { |
| 93 | 24 | return classes.iterator().next().newInstance(); |
| 94 | } catch (Exception e) { | |
| 95 | 0 | throw new UnexpectedLiquibaseException(e); |
| 96 | } | |
| 97 | } | |
| 98 | ||
| 99 | } | |
|
||||||||||||