Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * OfficeFloor - http://www.officefloor.net
   * Copyright (C) 2005-2013 Daniel Sagenschneider
   *
   * This program is free software: you can redistribute it and/or modify
   * it under the terms of the GNU General Public License as published by
   * the Free Software Foundation, either version 3 of the License, or
   * (at your option) any later version.
   *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 package net.officefloor.plugin.jdbc.datasource;
 
 
 
net.officefloor.frame.api.execute.Task providing testing of a java.sql.Connection from a DataSourceManagedObjectSource.

Author(s):
Daniel Sagenschneider
 
 public class DataSourceTask extends AbstractSingleTask<WorkIndexedNone> {

 
 	private final ConnectionValidator validator;

Initiate.

 
 	public DataSourceTask(ConnectionValidator validator) {
 		this. = validator;
 	}

Constructs this net.officefloor.frame.api.execute.Task.

Parameters:
officeBuilder net.officefloor.frame.api.build.OfficeBuilder to construct against.
namePrefix Prefix for net.officefloor.frame.api.execute.Work and net.officefloor.frame.api.execute.Task names.
dataSourceMoName Name of the DataSourceManagedObjectSource.
teamName Name of the net.officefloor.frame.spi.team.Team.
Returns:
Name of net.officefloor.frame.api.execute.Work it is registered under so may be invoked.
 
 	public String construct(OfficeBuilder officeBuilderString namePrefix,
 			String dataSourceMoNameString teamNamethrows Exception {
 
 		// Ensure have a name prefix
 		namePrefix = (namePrefix == null ? "" : namePrefix);
 
 		// Create the work name
 		String workName = namePrefix + "Work";
 
 		// Configure the Work
 		WorkBuilder<WorkworkBuilder = this.registerWork(workName,
 				officeBuilder);
 		workBuilder.addWorkManagedObject("mo"dataSourceMoName);
 
 		// Configure the Task
 		TaskBuilder<WorkIndexedNonetaskBuilder = this.registerTask(
 				"Task"teamNameworkBuilder);
 		taskBuilder.linkManagedObject(0, "mo"DataSource.class);
 
 		// Return the work name
 		return workName;
 	}
 
 	/*
 	 * =================== AbstractSingleTask =========================
 	 */
 
	public Object doTask(TaskContext<WorkIndexedNonecontext)
			throws Throwable {
		// Obtain the DataSource
		DataSource dataSource = (DataSourcecontext.getObject(0);
		TestCase.assertNotNull("Must have DataSource"dataSource);
		// Obtain the connection
		Connection connection = dataSource.getConnection();
		// Validate the connection
		this..validateConnection(connection);
		// Close the connection
		connection.close();
		// Nothing to return
		return null;
	}
New to GrepCode? Check out our FAQ X