View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.service.data.impl;
20  
21  import javax.sql.DataSource;
22  
23  import org.springframework.beans.factory.annotation.Autowired;
24  import org.springframework.jdbc.core.JdbcTemplate;
25  import org.springframework.stereotype.Service;
26  import org.springframework.transaction.annotation.Transactional;
27  
28  import com.hack23.cia.service.data.api.ViewDataManager;
29  
30  /**
31   * The Class ViewDataManagerImpl.
32   */
33  @Service
34  @Transactional(timeout=900)
35  final class ViewDataManagerImpl implements ViewDataManager {
36  
37  	/** The data source. */
38  	@Autowired
39  	private DataSource dataSource;
40  
41  	/**
42  	 * Instantiates a new view data manager impl.
43  	 */
44  	public ViewDataManagerImpl() {
45  		super();
46  	}
47  
48  	@Override
49  	public void refreshViews() {
50  		final JdbcTemplate jdbcTemplate = new JdbcTemplate(dataSource);
51  
52  
53  		//Handle FP changed to L for folkpartiet name changed to liberalerna.
54  
55  		jdbcTemplate.execute("update vote_data set gender='MAN' where gender='M'");
56  		jdbcTemplate.execute("update vote_data set gender='KVINNA' where gender='K'");
57  		
58  		jdbcTemplate.execute("update vote_data set gender='MAN' where gender='man'");
59  		jdbcTemplate.execute("update vote_data set gender='KVINNA' where gender='kvinna'");
60  		
61  
62  		jdbcTemplate.execute("update vote_data set party='L' where party='FP'");
63  
64  		jdbcTemplate.execute("update person_data set party='L' where party='FP'");
65  		jdbcTemplate.execute("update document_element set org='L' where org='FP' or org='fp'");
66  		jdbcTemplate.execute("update document_data set org='L' where org='FP' or org='fp'");
67  		jdbcTemplate.execute("update committee_document_data set org='L' where org='FP' or org='fp'");
68  		jdbcTemplate.execute("update document_person_reference_da_0 set party_short_code='L' where party_short_code='FP' or party_short_code='fp'");
69  
70  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_worldbank_indicator_data_country_summary");
71  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_summary");
72  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_party_summary");
73  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_politician_summary");
74  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_party_summary_daily");
75  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_party_summary_annual");
76  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_party_summary_monthly");
77  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_party_summary_weekly");
78  
79  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_summary_daily");
80  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_summary_annual");
81  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_summary_monthly");
82  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_summary_weekly");
83  
84  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_politician_summary_daily");
85  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_politician_summary_annual");
86  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_politician_summary_monthly");
87  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_vote_data_ballot_politician_summary_weekly");
88  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_decisions");
89  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_ballot_decision_politician_summary");
90  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_ballot_decision_party_summary");
91  
92  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_ballot_decision_summary");
93  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_decision_type_org_summary");
94  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_committee_decision_type_summary");
95  
96  
97  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_politician_document");
98  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_org_document_daily_summary");
99  		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_party_document_daily_summary");
100 		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_politician_document_daily_summary");
101 		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_riksdagen_document_type_daily_summary");
102 
103 		jdbcTemplate.execute("REFRESH MATERIALIZED VIEW view_worldbank_indicator_data_country_summary");
104 
105 	}
106 
107 }