|
|||||||||||||||||||
| 30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover | |||||||||||||||||||
| Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
| PlsqlCommandProcessor.java | 0% | 0% | 0% | 0% |
|
||||||||||||||
| 1 |
/*
|
|
| 2 |
* Replica is published under the terms
|
|
| 3 |
* of the Apache Software License.
|
|
| 4 |
*/
|
|
| 5 |
package replica.server.commands.plsql;
|
|
| 6 |
|
|
| 7 |
import java.util.StringTokenizer;
|
|
| 8 |
|
|
| 9 |
import replica.command.CommandProcessor;
|
|
| 10 |
import replica.core.ApplicationCommandProcessor;
|
|
| 11 |
import replica.core.ApplicationMessage;
|
|
| 12 |
import replica.group.GroupManager;
|
|
| 13 |
import replica.server.ServerProcess;
|
|
| 14 |
import replica.session.SessionManager;
|
|
| 15 |
|
|
| 16 |
/**
|
|
| 17 |
*
|
|
| 18 |
* @author Pedro Costa
|
|
| 19 |
* @author Helder Silva
|
|
| 20 |
* @since 29/Jan/2004
|
|
| 21 |
*/
|
|
| 22 |
public class PlsqlCommandProcessor extends ApplicationCommandProcessor { |
|
| 23 |
|
|
| 24 |
StringBuffer plsqlCommand = new StringBuffer();
|
|
| 25 |
SessionManager sessionManager; |
|
| 26 |
CommandProcessor oldCommandProcessor; |
|
| 27 |
ServerProcess serverProcess; |
|
| 28 |
GroupManager groupManager; |
|
| 29 |
|
|
| 30 |
/**
|
|
| 31 |
*
|
|
| 32 |
*/
|
|
| 33 | 0 |
public PlsqlCommandProcessor(String plsqlCommandStart, ServerProcess serverProcess, GroupManager groupManager) {
|
| 34 | 0 |
super();
|
| 35 |
|
|
| 36 | 0 |
plsqlCommand.append(plsqlCommandStart); |
| 37 | 0 |
setServerProcess( serverProcess ); |
| 38 | 0 |
setGroupManager(groupManager); |
| 39 |
} |
|
| 40 |
|
|
| 41 |
/**
|
|
| 42 |
* Process one received appMsg that is part of a plsql program.
|
|
| 43 |
*
|
|
| 44 |
* Adds the received command to the internal program body.
|
|
| 45 |
* Checks if the end of a plsql program. If yes, process program end,
|
|
| 46 |
* else return and wait for more.
|
|
| 47 |
*
|
|
| 48 |
* @see replica.core.ApplicationCommandProcessor#process(replica.core.ApplicationMessage)
|
|
| 49 |
*/
|
|
| 50 | 0 |
protected Object process(ApplicationMessage appMsg) {
|
| 51 |
|
|
| 52 | 0 |
String command = appMsg.getBody().toString(); |
| 53 | 0 |
plsqlCommand.append(command); |
| 54 |
|
|
| 55 | 0 |
if( isPlsqlEnd(command) ){
|
| 56 | 0 |
processPlsqlCommandEnd(appMsg); |
| 57 |
} |
|
| 58 |
|
|
| 59 | 0 |
return ""; |
| 60 |
} |
|
| 61 |
|
|
| 62 |
/**
|
|
| 63 |
* Called when a end of the plsql program is received.
|
|
| 64 |
*
|
|
| 65 |
* Reset the command processor on the receiving thread and sends the full plsql program
|
|
| 66 |
* to the group.
|
|
| 67 |
*
|
|
| 68 |
* @param appMsg the last message received.
|
|
| 69 |
*/
|
|
| 70 | 0 |
void processPlsqlCommandEnd(ApplicationMessage appMsg){
|
| 71 |
|
|
| 72 | 0 |
getServerProcess().setCommandProcessor(getOldCommandProcessor()); |
| 73 |
|
|
| 74 | 0 |
appMsg.setBody(plsqlCommand.toString()); |
| 75 |
|
|
| 76 | 0 |
getGroupManager().sendMessage(appMsg); |
| 77 |
} |
|
| 78 |
|
|
| 79 |
/**
|
|
| 80 |
* Return true if the given command is the end of a plsql program.
|
|
| 81 |
*
|
|
| 82 |
* A plsql ends with <i>end;</i> or <i>end<anyseparator>;</i>
|
|
| 83 |
*
|
|
| 84 |
* For a list of what is considered <anyseparator> see {@link java.util.StringTokenizer(String)}.
|
|
| 85 |
*
|
|
| 86 |
* @param command
|
|
| 87 |
* @return
|
|
| 88 |
*/
|
|
| 89 | 0 |
boolean isPlsqlEnd(String command){
|
| 90 |
|
|
| 91 | 0 |
StringTokenizer tok = new StringTokenizer(command.trim(), " "); |
| 92 |
|
|
| 93 | 0 |
String token = tok.nextToken(); |
| 94 | 0 |
return ( token.equals("end") && tok.hasMoreTokens() && tok.nextToken().equals(";") ) || |
| 95 |
token.equals("end;");
|
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/**
|
|
| 99 |
* @return
|
|
| 100 |
*/
|
|
| 101 | 0 |
public SessionManager getSessionManager() {
|
| 102 | 0 |
return sessionManager;
|
| 103 |
} |
|
| 104 |
|
|
| 105 |
/**
|
|
| 106 |
* @param manager
|
|
| 107 |
*/
|
|
| 108 | 0 |
public void setSessionManager(SessionManager manager) { |
| 109 | 0 |
sessionManager = manager; |
| 110 |
} |
|
| 111 |
|
|
| 112 |
/**
|
|
| 113 |
* @return
|
|
| 114 |
*/
|
|
| 115 | 0 |
public CommandProcessor getOldCommandProcessor() {
|
| 116 | 0 |
return oldCommandProcessor;
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
/**
|
|
| 120 |
* @param processor
|
|
| 121 |
*/
|
|
| 122 | 0 |
public void setOldCommandProcessor(CommandProcessor processor) { |
| 123 | 0 |
oldCommandProcessor = processor; |
| 124 |
} |
|
| 125 |
|
|
| 126 |
/**
|
|
| 127 |
* @return
|
|
| 128 |
*/
|
|
| 129 | 0 |
public ServerProcess getServerProcess() {
|
| 130 | 0 |
return serverProcess;
|
| 131 |
} |
|
| 132 |
|
|
| 133 |
/**
|
|
| 134 |
* @param process
|
|
| 135 |
*/
|
|
| 136 | 0 |
public void setServerProcess(ServerProcess process) { |
| 137 | 0 |
serverProcess = process; |
| 138 | 0 |
setOldCommandProcessor( serverProcess.getCommandProcessor() ); |
| 139 | 0 |
serverProcess.setCommandProcessor( this );
|
| 140 |
} |
|
| 141 |
|
|
| 142 |
/**
|
|
| 143 |
* @return
|
|
| 144 |
*/
|
|
| 145 | 0 |
public GroupManager getGroupManager() {
|
| 146 | 0 |
return groupManager;
|
| 147 |
} |
|
| 148 |
|
|
| 149 |
/**
|
|
| 150 |
* @param manager
|
|
| 151 |
*/
|
|
| 152 | 0 |
public void setGroupManager(GroupManager manager) { |
| 153 | 0 |
groupManager = manager; |
| 154 |
} |
|
| 155 |
|
|
| 156 |
} |
|
| 157 |
|
|
||||||||||