-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[voltdb]: update subtree v2 using
STARTS WITH
(#337)
* [voltdb]: update subtree v2 using `STARTS WITH` * Fix: VoltDB Stored Procedure
- Loading branch information
Showing
7 changed files
with
87 additions
and
48 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import org.voltdb.*; | ||
import java.util.*; | ||
|
||
// https://docs.voltdb.com/tutorial/Part5.php | ||
public class UpdateSubtreeV2 extends VoltProcedure { | ||
public final SQLStmt sql1 = new SQLStmt( | ||
"SELECT id, name, accessTime, modificationTime, permission," | ||
+ "header, parent, parentName from inodes WHERE parentName STARTS WITH ?;"); | ||
|
||
public final SQLStmt sql2 = new SQLStmt("INSERT INTO inodes(" | ||
+ "id, name, accessTime, modificationTime, permission, header, parent, parentName" | ||
+ ") VALUES (?, ?, ?, ?, ?, ?, ?, ?);"); | ||
|
||
public final SQLStmt sql3 = new SQLStmt("DELETE FROM inodes where parentName STARTS WITH ?;"); | ||
|
||
public long run(final long dir_id, final long dest_id, final String old_parent_name, | ||
final String new_parent_name, final long new_parent) throws VoltAbortException { | ||
// 1. find subtree records | ||
voltQueueSQL(sql1, old_parent_name); | ||
VoltTable[] res = voltExecuteSQL(); | ||
|
||
// 2. update subtree records | ||
Long id = null; | ||
String name = null; | ||
Long accessTime = null; | ||
Long modificationTime = null; | ||
Long permission = null; | ||
Long header = null; | ||
Long parent = null; | ||
String parentName = null; | ||
for (int j = 0; j < res.length; ++j) { | ||
for (int i = 0; i < res[j].getRowCount(); ++i) { | ||
VoltTableRow row = res[j].fetchRow(i); | ||
id = row.getLong(0); | ||
name = row.getString(1); | ||
accessTime = row.getLong(2); | ||
modificationTime = row.getLong(3); | ||
permission = row.getLong(4); | ||
header = row.getLong(5); | ||
parent = row.getLong(6); | ||
parentName = row.getString(7); | ||
|
||
if (id == dir_id) { | ||
id += dest_id; | ||
parent = new_parent; | ||
parentName = new_parent_name; | ||
} else { | ||
id += dest_id; | ||
parent += dest_id; | ||
parentName = new_parent_name + parentName.substring(old_parent_name.length()); | ||
} | ||
voltQueueSQL(sql2, | ||
id, | ||
name, | ||
accessTime, | ||
modificationTime, | ||
permission, | ||
header, | ||
parent, | ||
parentName); | ||
} | ||
} | ||
voltExecuteSQL(); | ||
|
||
// 3. delete old subtree records | ||
voltQueueSQL(sql3, old_parent_name); | ||
voltExecuteSQL(); | ||
|
||
return getUniqueId(); | ||
} | ||
} |
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
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