/* Description:--- This custom plug-in takes SQL statement that returns single string value and transforms that value as output stream. Input expected by this Plugin:--- DB info activity Id and database query that should return single value to be converted to stream. These values should be set in context variable's( "dbInfoId" and "dbQuery" before using this Custom Plugin. Output of this Plugin:--- Output stream. */ import java.sql.Connection; import java.sql.ResultSet; import java.sql.Statement; import javax.security.auth.Subject; import com.adeptia.indigo.logging.Logger; import com.adeptia.indigo.services.transport.connector.DatabaseConnectionInfo; import com.adeptia.indigo.storage.Entity; import com.adeptia.indigo.storage.EntityManager; import com.adeptia.indigo.storage.EntityManagerFactory; import com.adeptia.indigo.storage.TypedEntityId; import com.adeptia.indigo.system.GuiBeanPluginManager; import com.adeptia.indigo.utils.JdbcUtils; // VARIABLE DECLARATION............. Connection connection = null; Statement statement = null; ResultSet resultSet = null; String xmlValue = ""; DatabaseConnectionInfo dbInfo = null; String dbInfoId = (String) context.get("dbInfoId"); String dbQuery = (String) context.get("dbQuery"); Logger logger = service.getLogger(); try { // GETTING CONNECTION OF DB..................... Subject subject = service.getSubject(); GuiBeanPluginManager pluginManager = new GuiBeanPluginManager(); Class pluginClass = pluginManager .getPlugin("DatabaseConnectionInfo"); EntityManager entityManager = EntityManagerFactory .getEntityManager(pluginClass, subject); TypedEntityId typedEntityId = new TypedEntityId(dbInfoId, "DatabaseConnectionInfo"); Entity entity = entityManager.retrieve(typedEntityId); DatabaseConnectionInfo databaseConnectionInfo = (DatabaseConnectionInfo) entity; connection = JdbcUtils.getConnection(databaseConnectionInfo, subject); logger.info("connection has been established."); statement = connection.createStatement(); resultSet = statement.executeQuery(dbQuery); // CHECK IF RESULTSET IS NULL OR NOT........... if (resultSet.next()) xmlValue = resultSet.getString(1); // CONVERTING STRING INTO INPUT STREAM........ service.getOutputStream().write(xmlValue.getBytes()); } catch (Exception e) { logger.error("Error while converting String to stream", e.getMessage(), e); e.printStackTrace(); } finally { try { if (statement != null) { statement.close(); } if (connection != null) { connection.close(); } } catch (Exception e1) { logger.error("Closing connection ", e1.getMessage(), e1); e1.printStackTrace(); } }