use of org.osgi.service.jdbc.DataSourceFactory in project aries by apache.
the class AbstractTransactionTest method programaticConnection.
private Connection programaticConnection(Properties jdbc) {
JDBCConnectionProviderFactory resourceProviderFactory = getService(JDBCConnectionProviderFactory.class, 5000);
DataSourceFactory dsf = getService(DataSourceFactory.class, 5000);
provider = resourceProviderFactory.getProviderFor(dsf, jdbc, resourceProviderConfig());
return provider.getResource(txControl);
}
use of org.osgi.service.jdbc.DataSourceFactory in project karaf by apache.
the class DSFactoriesCommand method execute.
@Override
public Object execute() throws Exception {
ShellTable table = new ShellTable();
table.column("Name");
table.column("Class");
table.column("Version");
Collection<ServiceReference<DataSourceFactory>> refs = context.getServiceReferences(DataSourceFactory.class, null);
for (ServiceReference<DataSourceFactory> ref : refs) {
String driverName = (String) ref.getProperty(DataSourceFactory.OSGI_JDBC_DRIVER_NAME);
String driverClass = (String) ref.getProperty(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS);
String driverVersion = (String) ref.getProperty(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION);
table.addRow().addContent(driverName, driverClass, driverVersion);
}
table.print(System.out);
return null;
}
use of org.osgi.service.jdbc.DataSourceFactory in project aries by apache.
the class TxDBServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
pw = response.getWriter();
pw.write(LOGO_HEADER);
// Get the bundle context from ServletContext attributes
BundleContext ctx = (BundleContext) getServletContext().getAttribute(OSGI_BUNDLECONTEXT_ATTRIBUTE);
pw.println("<html>");
pw.println("<head>");
pw.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"tableTemplate.css\"/>");
pw.println("<body>");
pw.println("<h2 align=center><p><font face=\"Tahoma\">Sample Application for JDBC usage in JTA Transactions.</font></h2>");
pw.println("<p><p>");
ServiceReference tmServiceRef = ctx.getServiceReference("javax.transaction.TransactionManager");
ServiceReference derbyServiceRef = ctx.getServiceReference(DataSourceFactory.class.getName());
if (tmServiceRef == null || derbyServiceRef == null) {
pw.println("<font face=\"Tahoma\">TransactionManager or Derby driver are not available in the OSGI registry.</font><br>");
} else {
TransactionManager tm = (TransactionManager) ctx.getService(tmServiceRef);
DataSourceFactory derbyRegistry = (DataSourceFactory) ctx.getService(derbyServiceRef);
try {
// Set the needed properties for the database connection
Properties props = new Properties();
props.put(DataSourceFactory.JDBC_URL, "jdbc:derby:txDemo");
props.put(DataSourceFactory.JDBC_DATABASE_NAME, "txDemo");
props.put(DataSourceFactory.JDBC_USER, "");
props.put(DataSourceFactory.JDBC_PASSWORD, "");
XADataSource xaDataSource = derbyRegistry.createXADataSource(props);
pw.println("<center><form><table><tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndCommit' size='100'/></td></tr>");
pw.println("<tr><td align='right'>Value: </td><td align=left><input type='text' name='value' value='' size='12'/><input type='submit' name='action' value='InsertAndRollback' size='100'/></center></td></tr>");
pw.println("<tr colspan='2' align='center'><td> </td><td><input type='submit' name='action' value='cleanTable' size='100' /> <input type='submit' name='action' value='printTable' size='100'/></td><tr></table></form></center>");
String value = request.getParameter("value");
String action = request.getParameter("action");
if (action != null && action.equals("InsertAndCommit")) {
insertIntoTransaction(xaDataSource, tm, value, true);
} else if (action != null && action.equals("InsertAndRollback")) {
insertIntoTransaction(xaDataSource, tm, value, false);
} else if (action != null && action.equals("cleanTable")) {
cleanTable(xaDataSource);
}
printTable(xaDataSource);
} catch (Exception e) {
pw.println("<font face=\"Tahoma\">Unexpected exception occurred " + e.toString() + ".</font><br>");
e.printStackTrace(pw);
}
}
pw.println("</body>");
pw.println("</html>");
pw.flush();
}
use of org.osgi.service.jdbc.DataSourceFactory in project aries by apache.
the class AbstractManagedJPADataSourceSetup method addingService.
@Override
public AbstractManagedJPAEMFLocator addingService(ServiceReference<DataSourceFactory> reference) {
DataSourceFactory service = context.getService(reference);
AbstractManagedJPAEMFLocator toReturn;
try {
Map<String, Object> jpaProps = decorateJPAProperties(service, unmodifiableMap(providerProperties), (Properties) jdbcProperties.clone(), new HashMap<>(baseJPAProperties));
toReturn = getManagedJPAEMFLocator(context, pid, jpaProps, providerProperties, () -> cleanupOnClose(jpaProps));
} catch (Exception e) {
LOG.error("An error occured creating the Resource provider for pid {}", pid, e);
return null;
}
updateService(reference, toReturn);
return toReturn;
}
Aggregations