Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit 7257377

Browse files
authored
Merge pull request #28 from gondzo/feature/load-project-groups
FYI - @ajefts @gondzo - Merging To Dev - load project groups to DW
2 parents b72f259 + 1678f4f commit 7257377

File tree

1 file changed

+91
-2
lines changed

1 file changed

+91
-2
lines changed

src/main/com/topcoder/utilities/dwload/TCLoadTCS.java

Lines changed: 91 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,8 @@ public void performLoad() throws Exception {
364364

365365
doLoadProjectTechnologies();
366366

367+
doLoadProjectGroups();
368+
367369
doLoadSpecReviews();
368370

369371
// load scorecard template before submission review because submission_review will use this table
@@ -2143,6 +2145,7 @@ public void doLoadProjects() throws Exception {
21432145
insert.setDouble(62, rs.getDouble("copilot_cost"));
21442146

21452147
insert.executeUpdate();
2148+
21462149
}
21472150
} else {
21482151
// we need to delete this project and all related objects in the database.
@@ -2171,7 +2174,6 @@ public void doLoadProjects() throws Exception {
21712174
}
21722175
}
21732176

2174-
21752177
/**
21762178
* <p/>
21772179
* Load Marathon Matches to the DW.
@@ -2717,7 +2719,7 @@ public void doLoadProjectTechnologies() throws Exception {
27172719
String name = rs.getString("technology_name");
27182720

27192721
if(!firstRun && !deletedProjects.contains(projectID)) {
2720-
// the load is not run for the first time && it's not processed in this load, clear the old technologies for the project
2722+
// the load is not run for the first time && it's not processed in this load, clear the old groups for the project
27212723
deleteTechnologies.clearParameters();
27222724
deleteTechnologies.setLong(1, projectID);
27232725
deleteTechnologies.executeUpdate();
@@ -2750,6 +2752,93 @@ public void doLoadProjectTechnologies() throws Exception {
27502752
}
27512753
}
27522754

2755+
/**
2756+
* Loads the project groups.
2757+
*
2758+
* @throws Exception if any error.
2759+
* @since 1.2.3
2760+
*/
2761+
public void doLoadProjectGroups() throws Exception {
2762+
log.info("load project groups");
2763+
2764+
PreparedStatement firstTimeSelect = null;
2765+
PreparedStatement deleteGroups = null;
2766+
PreparedStatement selectGroups = null;
2767+
PreparedStatement insertGroups = null;
2768+
ResultSet rs = null;
2769+
Set<Long> deletedProjects = new HashSet<Long>();
2770+
2771+
try {
2772+
long start = System.currentTimeMillis();
2773+
2774+
firstTimeSelect = prepareStatement("SELECT count(*) from project_groups", TARGET_DB);
2775+
rs = firstTimeSelect.executeQuery();
2776+
rs.next();
2777+
2778+
// no records, it's the first run of loading groups
2779+
boolean firstRun = rs.getInt(1) == 0;
2780+
2781+
if(firstRun) log.info("Loading project group table for the first time. A complete load will be performed");
2782+
2783+
final String SELECT = "select p.project_id, group_id from project p INNER JOIN common_oltp:contest_eligibility ce ON ce.contest_id = p.project_id INNER JOIN common_oltp:group_contest_eligibility gce ON gce.contest_eligibility_id=ce.contest_eligibility_id \n" +
2784+
(firstRun ? "" : " AND (p.create_date > ? OR p.modify_date > ?)") +
2785+
"group by p.project_id, group_id";
2786+
2787+
selectGroups = prepareStatement(SELECT, SOURCE_DB);
2788+
2789+
if(!firstRun) {
2790+
// no the first time, set last loading time
2791+
selectGroups.setTimestamp(1, fLastLogTime);
2792+
selectGroups.setTimestamp(2, fLastLogTime);
2793+
}
2794+
2795+
2796+
final String DELETE = "delete from project_groups where project_id = ?";
2797+
deleteGroups = prepareStatement(DELETE, TARGET_DB);
2798+
2799+
final String INSERT = "insert into project_groups (project_id, group_id) VALUES (?,?)";
2800+
insertGroups = prepareStatement(INSERT, TARGET_DB);
2801+
2802+
rs = selectGroups.executeQuery();
2803+
2804+
int countRecords = 0;
2805+
2806+
while (rs.next()) {
2807+
long projectID = rs.getLong("project_id");
2808+
long groupId = rs.getLong("group_id");
2809+
2810+
if(!firstRun && !deletedProjects.contains(projectID)) {
2811+
// the load is not run for the first time && it's not processed in this load, clear the old technologies for the project
2812+
deleteGroups.clearParameters();
2813+
deleteGroups.setLong(1, projectID);
2814+
deleteGroups.executeUpdate();
2815+
deletedProjects.add(projectID);
2816+
}
2817+
2818+
insertGroups.clearParameters();
2819+
insertGroups.setLong(1, projectID);
2820+
insertGroups.setLong(2, groupId);
2821+
2822+
insertGroups.executeUpdate();
2823+
countRecords ++;
2824+
}
2825+
2826+
log.info("Loaded " + countRecords + " records in " + (System.currentTimeMillis() - start) / 1000 + " seconds");
2827+
2828+
} catch(SQLException sqle) {
2829+
DBMS.printSqlException(true, sqle);
2830+
throw new Exception("Load Project groups failed.\n" +
2831+
sqle.getMessage());
2832+
} finally {
2833+
close(rs);
2834+
close(firstTimeSelect);
2835+
close(selectGroups);
2836+
close(deleteGroups);
2837+
close(insertGroups);
2838+
deletedProjects.clear();
2839+
}
2840+
}
2841+
27532842
/**
27542843
* Helper method that deletes all project related objects in the dw.
27552844
*

0 commit comments

Comments
 (0)