Created
December 12, 2012 15:26
-
-
Save mtheoryx/4268656 to your computer and use it in GitHub Desktop.
Assignment2Entity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// set the item to be accessible only to the specific groups. | |
// null to make it accessible to the whole site | |
public void setGroups(Collection<String> tgroups) { | |
ArrayList<String> groups = null; | |
if (tgroups != null) | |
groups = new ArrayList<String>(tgroups); | |
List<AssignGroup> assignGroups = getAssignGroups(); | |
Iterator<AssignGroup>i = assignGroups.iterator(); | |
while (i.hasNext()) { | |
AssignGroup a = i.next(); | |
if (groups != null && groups.contains(a.groupid)) { | |
groups.remove(a.groupid); | |
a.update = true; // it's in new set, so update it | |
} | |
} | |
final Collection<String> fgroups = groups; | |
final List<AssignGroup> fassignGroups = assignGroups; | |
// fgroups is now stuff to add | |
// fassignGroups is stuff to update or remove | |
// in a transaction | |
SqlService.transact(new Runnable() | |
{ | |
public void run() | |
{ | |
String updatesql = "update A2_ASSIGN_GROUP_T set version=? where assignment_group_id = ?"; | |
String addsql = "insert into A2_ASSIGN_GROUP_T (version, assignment_id, group_ref) values (0, ?, ?)"; | |
String deletesql = "delete from A2_ASSIGN_GROUP_T where assignment_group_id = ?"; | |
for (AssignGroup a: fassignGroups) { | |
if (a.update) { | |
Object fields[] = new Object[2]; | |
fields[0] = a.version + 1; | |
fields[1] = a.id; | |
SqlService.dbWrite(updatesql, fields); | |
} else { | |
Object fields[] = new Object[1]; | |
fields[0] = a.id; | |
SqlService.dbWrite(deletesql, fields); | |
} | |
} | |
if (fgroups != null) | |
for (String g:fgroups) { | |
Object fields[] = new Object[2]; | |
fields[0] = id; | |
fields[1] = g; | |
SqlService.dbWrite(addsql, fields); | |
} | |
} | |
}, "assignment2setgroups"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment