Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package net.nan21.dnet.core.web.controller.data;
  
  import java.util.List;
  
  import  javax.servlet.http.HttpServletRequest;
  import  javax.servlet.http.HttpServletResponse;
  
  import  org.apache.commons.lang.time.StopWatch;
 import  org.springframework.web.bind.annotation.PathVariable;
 import  org.springframework.web.bind.annotation.RequestMapping;
 import  org.springframework.web.bind.annotation.RequestMethod;
 import  org.springframework.web.bind.annotation.RequestParam;
 import  org.springframework.web.bind.annotation.ResponseBody;
 
 
 public class AbstractDsWriteController<M, F, P> extends
 		AbstractDsRpcController<M, F, P> {

Default handler for insert action.

Parameters:
resourceName
dataformat
dataString
paramString
Returns:
Throws:
Exception
 
 	@RequestMapping(method = RequestMethod.POST, params = .
 			+ "=" + .)
 	@ResponseBody
 	public String insert(
 			@PathVariable String resourceName,
 			@PathVariable String dataFormat,
 			@RequestParam(value = ., required = false, defaultValue = "{}"String dataString,
 			@RequestParam(value = ., required = false, defaultValue = "{}"String paramString,
 			HttpServletRequest request, HttpServletResponse response)
 			throws Exception {
 		try {
 
 			StopWatch stopWatch = new StopWatch();
 			stopWatch.start();
 
 			if (.isDebugEnabled()) {
 				.debug("Processing request: {}.{} -> action = {} ",
 						new String[] { resourceNamedataFormat,
 			}
 			this.prepareRequest(requestresponse);
 
 					resourceName.substring(0, resourceName.length() - 2),
 
 			if (!dataString.startsWith("[")) {
 				dataString = "[" + dataString + "]";
 			}
 
 			IDsService<M, F, P> service = this.findDsService(resourceName);
 			IDsMarshaller<M, F, P> marshaller = service
 					.createMarshaller(dataFormat);
 
 			List<M> list = marshaller.readListFromString(dataString);
 			P params = marshaller.readParamsFromString(paramString);
 
 			service.insert(listparams);
 
 			IActionResultSave result = this.packResultSave(listparams);
 			stopWatch.stop();
 			result.setExecutionTime(stopWatch.getTime());
 
 			return marshaller.writeResultToString(result);
 		} catch (Exception e) {
 			return this.handleException(eresponse);
 		} finally {
 			this.finishRequest();
 		}
 	}

Default handler for update action.

Parameters:
resourceName
dataformat
dataString
paramString
Returns:
Throws:
Exception
 
 	@RequestMapping(method = RequestMethod.POST, params = .
"=" + .)
	@ResponseBody
	public String update(
			@PathVariable String resourceName,
			@PathVariable String dataFormat,
			@RequestParam(value = ., required = false, defaultValue = "{}"String dataString,
			@RequestParam(value = ., required = false, defaultValue = "{}"String paramString,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			StopWatch stopWatch = new StopWatch();
			stopWatch.start();
				.debug("Processing request: {}.{} -> action = {} ",
						new String[] { resourceNamedataFormat,
			}
			this.prepareRequest(requestresponse);
					resourceName.substring(0, resourceName.length() - 2),
			if (!dataString.startsWith("[")) {
				dataString = "[" + dataString + "]";
			}
			IDsService<M, F, P> service = this.findDsService(resourceName);
			IDsMarshaller<M, F, P> marshaller = service
					.createMarshaller(dataFormat);
			List<M> list = marshaller.readListFromString(dataString);
params = marshaller.readParamsFromString(paramString);
			service.update(listparams);
			IActionResultSave result = this.packResultSave(listparams);
			stopWatch.stop();
			result.setExecutionTime(stopWatch.getTime());
			return marshaller.writeResultToString(result);
catch (Exception e) {
			this.handleException(eresponse);
			return null;
finally {
		}
	}

Default handler for delete action.

Parameters:
resourceName
dataformat
idsString
paramString
Returns:
Throws:
Exception
	@RequestMapping(method = RequestMethod.POST, params = .
"=" + .)
	@ResponseBody
	public String delete(
			@PathVariable String resourceName,
			@PathVariable String dataFormat,
			@RequestParam(value = ., required = false, defaultValue = "{}"String dataString,
			@RequestParam(value = ., required = false, defaultValue = "{}"String paramString,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			StopWatch stopWatch = new StopWatch();
			stopWatch.start();
				.debug("Processing request: {}.{} -> action = {} ",
						new String[] { resourceNamedataFormat,
			}
			this.prepareRequest(requestresponse);
					resourceName.substring(0, resourceName.length() - 2),
			if (!dataString.startsWith("[")) {
				dataString = "[" + dataString + "]";
			}
			IDsService<M, F, P> service = this.findDsService(resourceName);
			IDsMarshaller<M, F, P> marshaller = service
					.createMarshaller(dataFormat);
			List<M> list = marshaller.readListFromString(dataString);
			// P params = marshaller.readParamsFromString(paramString);
			List<Objectids = new ArrayList<Object>();
			for (M ds : list) {
				ids.add(((IModelWithIdds).getId());
			}
			service.deleteByIds(ids);
			stopWatch.stop();
			result.setExecutionTime(stopWatch.getTime());
			return marshaller.writeResultToString(result);
catch (Exception e) {
			this.handleException(eresponse);
			return null;
finally {
		}
	}

Default handler for delete action.

Parameters:
resourceName
dataformat
idsString
paramString
Returns:
Throws:
Exception
	@RequestMapping(method = RequestMethod.POST, params = .
"=" + . + "ById")
	@ResponseBody
			@PathVariable String resourceName,
			@PathVariable String dataFormat,
			@RequestParam(value = ., required = false, defaultValue = "{}"String idsString,
			@RequestParam(value = ., required = false, defaultValue = "{}"String paramString,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		try {
			StopWatch stopWatch = new StopWatch();
			stopWatch.start();
			this.prepareRequest(requestresponse);
					resourceName.substring(0, resourceName.length() - 2),
			if (!idsString.startsWith("[")) {
				idsString = "[" + idsString + "]";
			}
			IDsService<M, F, P> service = this.findDsService(resourceName);
			IDsMarshaller<M, F, P> marshaller = service
					.createMarshaller(dataFormat);
			List<Objectlist = marshaller.readListFromString(idsString,
					Object.class);
			service.deleteByIds(list);
			stopWatch.stop();
			result.setExecutionTime(stopWatch.getTime());
			return marshaller.writeResultToString(result);
catch (Exception e) {
			this.handleException(eresponse);
			return null;
finally {
		}
	}
	public IActionResultSave packResultSave(List<M> data, P params) {
		pack.setData(data);
		// pack.setParams(params);
		return pack;
	}
		return pack;
	}
New to GrepCode? Check out our FAQ X