1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.store.migration.hibernate

File AbstractHibernateDataMigration.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart2.png
81% of files have more coverage

Code metrics

2
16
7
1
128
69
10
0.62
2.29
7
1.43

Classes

Class Line # Actions
AbstractHibernateDataMigration 45 16 0% 10 22
0.1212%
 

Contributing tests

This file is covered by 8 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20   
21    package com.xpn.xwiki.store.migration.hibernate;
22   
23    import javax.inject.Inject;
24    import javax.inject.Named;
25   
26    import org.xwiki.component.manager.ComponentLookupException;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.context.Execution;
29    import org.xwiki.context.ExecutionContext;
30   
31    import com.xpn.xwiki.XWikiContext;
32    import com.xpn.xwiki.XWikiException;
33    import com.xpn.xwiki.store.XWikiHibernateBaseStore;
34    import com.xpn.xwiki.store.XWikiStoreInterface;
35    import com.xpn.xwiki.store.migration.DataMigrationException;
36    import com.xpn.xwiki.store.migration.XWikiDBVersion;
37   
38    /**
39    * Template for data migration of hibernate store.
40    *
41    * @see com.xpn.xwiki.store.migration.DataMigration
42    * @version $Id: 0fcd07917319e93610db111cdc74cffd460a38ab $
43    * @since 3.4M1
44    */
 
45    public abstract class AbstractHibernateDataMigration implements HibernateDataMigration
46    {
47    /**
48    * Component manager used to access stores.
49    */
50    @Inject
51    protected ComponentManager componentManager;
52   
53    /**
54    * Execution context used to access XWikiContext.
55    */
56    @Inject
57    private Execution execution;
58   
59    /**
60    * @return XWikiContext to access the store
61    */
 
62  23 toggle protected XWikiContext getXWikiContext()
63    {
64  23 ExecutionContext context = this.execution.getContext();
65  23 return (XWikiContext) context.getProperty("xwikicontext");
66    }
67   
68    /**
69    * @return store system for execute store-specific actions.
70    * @throws DataMigrationException if the store could not be reached
71    */
 
72  0 toggle protected XWikiHibernateBaseStore getStore() throws DataMigrationException
73    {
74  0 try {
75  0 return (XWikiHibernateBaseStore) this.componentManager.getInstance(XWikiStoreInterface.class, "hibernate");
76    } catch (ComponentLookupException e) {
77  0 throw new DataMigrationException(String.format("Unable to reach the store for database %s",
78    getXWikiContext().getWikiId()), e);
79    }
80    }
81   
 
82  0 toggle @Override
83    public String getName()
84    {
85  0 String hint = null;
86  0 Named named = this.getClass().getAnnotation(Named.class);
87  0 if (named != null) {
88  0 hint = named.value();
89    }
90  0 return hint;
91    }
92   
 
93  0 toggle @Override
94    public boolean shouldExecute(XWikiDBVersion startupVersion)
95    {
96  0 return true;
97    }
98   
99    /**
100    * Execute the migration itself.
101    *
102    * @throws DataMigrationException on migration error.
103    * @throws XWikiException on error from the store.
104    */
105    protected abstract void hibernateMigrate() throws DataMigrationException, XWikiException;
106   
 
107  0 toggle @Override
108    public void migrate() throws DataMigrationException
109    {
110  0 try {
111  0 hibernateMigrate();
112    } catch (Exception e) {
113  0 throw new DataMigrationException(String.format("Data migration %s failed", getName()), e);
114    }
115    }
116   
 
117  0 toggle @Override
118    public String getPreHibernateLiquibaseChangeLog() throws DataMigrationException
119    {
120  0 return null;
121    }
122   
 
123  0 toggle @Override
124    public String getLiquibaseChangeLog() throws DataMigrationException
125    {
126  0 return null;
127    }
128    }