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

File R54600TranslationDataMigration.java

 

Coverage histogram

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

Code metrics

0
9
5
2
92
56
7
0.78
1.8
2.5
1.4

Classes

Class Line # Actions
R54600TranslationDataMigration 51 5 0% 4 7
0.2222222222.2%
R54600TranslationDataMigration.R54600Work 79 4 0% 3 5
0.00%
 

Contributing tests

No tests hitting this source file were found.

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 java.sql.Connection;
24    import java.sql.SQLException;
25    import java.sql.Statement;
26   
27    import javax.inject.Named;
28    import javax.inject.Singleton;
29   
30    import org.hibernate.HibernateException;
31    import org.hibernate.Session;
32    import org.hibernate.jdbc.Work;
33    import org.xwiki.component.annotation.Component;
34   
35    import com.xpn.xwiki.XWikiException;
36    import com.xpn.xwiki.store.XWikiHibernateBaseStore.HibernateCallback;
37    import com.xpn.xwiki.store.migration.DataMigrationException;
38    import com.xpn.xwiki.store.migration.XWikiDBVersion;
39   
40    /**
41    * Fix any existing mistake with document translation field. It should be synchronized with the language.
42    * <p>
43    * This kind of mistake should not be possible anymore with the fix for XWIKI-11110.
44    *
45    * @version $Id: 9856fda928e49109a1fdd87bdabb357dd0a93442 $
46    * @since 5.4.6
47    */
48    @Component
49    @Named("R54600Translation")
50    @Singleton
 
51    public class R54600TranslationDataMigration extends AbstractHibernateDataMigration
52    {
 
53  0 toggle @Override
54    public String getDescription()
55    {
56  0 return "Fix any existing mistake with document translation field";
57    }
58   
 
59  206 toggle @Override
60    public XWikiDBVersion getVersion()
61    {
62  206 return new XWikiDBVersion(54600);
63    }
64   
 
65  0 toggle @Override
66    public void hibernateMigrate() throws DataMigrationException, XWikiException
67    {
68  0 getStore().executeWrite(getXWikiContext(), new HibernateCallback<Object>()
69    {
 
70  0 toggle @Override
71    public Object doInHibernate(Session session) throws HibernateException, XWikiException
72    {
73  0 session.doWork(new R54600Work());
74  0 return Boolean.TRUE;
75    }
76    });
77    }
78   
 
79    private static class R54600Work implements Work
80    {
 
81  0 toggle @Override
82    public void execute(Connection connection) throws SQLException
83    {
84  0 try (Statement statement = connection.createStatement()) {
85  0 statement.execute("UPDATE xwikidoc set XWD_TRANSLATION = 1"
86    + " where XWD_TRANSLATION = 0 and (XWD_LANGUAGE is not null and XWD_LANGUAGE <> '')");
87  0 statement.execute("UPDATE xwikidoc set XWD_TRANSLATION = 0"
88    + " where XWD_TRANSLATION = 1 and (XWD_LANGUAGE is null or XWD_LANGUAGE = '')");
89    }
90    }
91    }
92    }