netbeans 7.0 applications client from database entity beans and session beans - netbeans

In netbeans versions previous 7.0 was possible to write the following,
#Stateless(mappedName="Soelprotocol")
public class ProtocolFacade implements ProtocolFacadeLocal, ProtocolFacadeRemote {
#PersistenceContext(unitName = "SOEL-ejbPU")
private EntityManager em;
public void create(Protocol protocol) {
em.persist(protocol);
}
public void edit(Protocol protocol) {
em.merge(protocol);
}
public void remove(Protocol protocol) {
em.remove(em.merge(protocol));
}
public Protocol find(Object id) {
return em.find(Protocol.class, id);
}
public List<Protocol> findAll() {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(Protocol.class));
return em.createQuery(cq).getResultList();
}
public List<Protocol> findRange(int[] range) {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
cq.select(cq.from(Protocol.class));
Query q = em.createQuery(cq);
q.setMaxResults(range[1] - range[0]);
q.setFirstResult(range[0]);
return q.getResultList();
}
public int count() {
CriteriaQuery cq = em.getCriteriaBuilder().createQuery();
Root<Protocol> rt = cq.from(Protocol.class);
cq.select(em.getCriteriaBuilder().count(rt));
Query q = em.createQuery(cq);
return ((Long) q.getSingleResult()).intValue();
}
}
When I try to create a remote session bean for database entity beans the check box label says "Remote in a project" with a message:
There is no suitable project available into which Remote interface could be stored. An open Ant based Java Class Library project is required.
With netbans 7.0 how to create an application client that uses remote session beans that created for database entity beans?
Is somewhere an complete example?

Vivien,
Create your application client as a separate Java application (or class library) project. If this project is open when you create the remote session bean in your EJB Module project, and you check the "create remote interface" option, Netbeans will propose this project for the remote interface.
It will then add the remote interface and EJB client container libraries to the client project.
Here's a complete example: http://netbeans.org/kb/docs/javaee/entappclient.html
good luck!

Related

Run method after deploying and save the result with to database

I have started a Quarkus project and i have there 2 tables, i am trying to run a Method immediately after deploying, In the method i use Entitymanger to save some results in the database.
In pure Jakarta EE, you could an EJB and annotate it with #Startup. But Since quarkus uses CDI.
#ApplicationScoped
public class StartApp {
private static final String PERSISTENCE_UNIT_NAME = "Employee";
public void init(#Observes #Initialized(ApplicationScoped.class) Object init) {
EntityManagerFactory factory =
Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
EntityManager em = factory.createEntityManager();
Directory directory = new Directory("/some/info", true, false, ".xml");
em.persist(directory);
em.close();
}
}
How can i do that!? some guess !
I think what you need is this:
#ApplicationScoped
class StartApp {
void startup(#Observes StartupEvent event) {
// Do whatever needs to be done.
}
}
More information and options can be found on the very well documented quarkus pages. https://quarkus.io/guides/cdi-reference#startup-event
Ps. don't forget about your transactions and maybe take a look at Hibernate ORM.

Deploying OLD EJBs to Weblogic 12. Desactivate EJB Checker

I´m in trouble with old EJBs that i have no control over the source code, there is no source code, only the ejb jar. They were born in weblogic 5.
We are migrating to weblogic 12c and When i deploy then, the EJB checker give me some compliance ejb errors.
I have been investigating the class ...
[Loaded weblogic.ejb.container.compliance.EJBComplianceChecker from ......product/Oracle_Home/wlserver/modules/com.oracle.weblogic.ejb.jar]
Decompiled and I have found this ....
public final class EJBComplianceChecker
extends BaseComplianceChecker
implements ComplianceChecker, PlatformConstants
{
public static final boolean isNeedCheck = Boolean.getBoolean("ignoreEJBChecker");
static final ComplianceChecker INSTANCE = new EJBComplianceChecker();
public void checkDeploymentInfo(DeploymentInfo di)
throws ErrorCollectionException
{
if (isNeedCheck) {
return;
}
Set<Class<?>> deploymentInfoCheckers = new HashSet();
Object interceptorChecker = null;
Object[] relationshipCheckers = null;
for (BeanInfo bi : di.getBeanInfos()) ....
I think this might be some kind of deployment configuration, but i have found no information about it...
public static final boolean isNeedCheck = Boolean.getBoolean("ignoreEJBChecker");
it controls the value and let it check or not.
if (isNeedCheck) {
return;
}
thanks
that seems to work. Know i can not see the error.
Thank for all Emmanuel

Inject EntityManager in SwitchYard Junit implementation

I am trying to implement Junit in SwitchYard Application.
i am using JPA , without using Camel. i have persistence.xml with the following details. And i am using resource producer pattern to expose EntityManager.
But when i am testing a service, i am getting null Invocation for EntityManager in DAO layer.
Is there any way , i can mock or inject EntityManager in SwitchYard Junit
#RunWith(SwitchYardRunner.class)
#SwitchYardTestCaseConfig(config = SwitchYardTestCaseConfig.SWITCHYARD_XML, mixins = {
CDIMixIn.class, HTTPMixIn.class, NamingMixIn.class })
public class SalesModuleServiceTest {
private SwitchYardTestKit testKit;
private CDIMixIn cdiMixIn;
private HTTPMixIn httpMixIn;
private static NamingMixIn namingMixIn;
private TransformerRegistry transformerRegistry;
#ServiceOperation("SalesModuleService")
private Invoker service;
//------ JUnit test with REST binding fails if no resteasy properties defined ------
#BeforeDeploy
public void setProperties()
{
System.setProperty("org.switchyard.component.resteasy.standalone.port", "8081");
System.setProperty("org.switchyard.component.resteasy.standalone.path", "");
}
#Test
public void testUpdateCustomerStatus() throws Exception {
SalesDetailsRequest message = null;
BudgetResponse<?> result = service.operation("updateCustomerStatus")
.sendInOut(message).getContent(SalesResponse.class);
// validate the results
Assert.assertTrue("Implement me", false);
}
}

Spring Data JPA | Dynamic runtime multiple database connection

Use Case:
During JBoss server startup, one permanent database connection is already made using Spring Data JPA configurations(xml based approach).
Now when application is already up and running, requirement is to connect to multiple Database and connection string is dynamic which is available on run-time.
How to achieve this using Spring Data JPA?
One way to switch out your data source is to define a "runtime" repository that is configured with the "runtime" data source. But this will make client code aware of the different repos:
package com...runtime.repository;
public interface RuntimeRepo extends JpaRepository<OBJECT, ID> { ... }
#Configuration
#EnableJpaRepositories(
transactionManagerRef="runtimeTransactionManager",
entityManagerFactoryRef="runtimeEmfBean")
#EnableTransactionManagement
public class RuntimeDatabaseConfig {
#Bean public DataSource runtimeDataSource() {
DriverManagerDataSource rds = new DriverManagerDataSource();
// setup driver, username, password, url
return rds;
}
#Bean public LocalContainerEntityManagerFactoryBean runtimeEmfBean() {
LocalContainerEntityManagerFactoryBean factoryBean = new LocalContainerEntityManagerFactoryBean();
factoryBean.setDataSource(runtimeDataSource());
// setup JpaVendorAdapter, jpaProperties,
return factoryBean;
}
#Bean public PlatformTransactionManager runtimeTransactionManager() {
JpaTransactionManager jtm = new JpaTransactionManager();
jtm.setEntityManagerFactory(runtimeEmfBean());
return jtm;
}
}
I have combined the code to save space; you would define the javaconfig and the repo interface in separate files, but within the same package.
To make client code agnostic of the repo type, implement your own repo factory, autowire the repo factory into client code and have your repo factory check application state before returning the particular repo implementation.

Creating a REST Service with Glassfish 4 outside of a WAR

I have a rest service implemented as follows
#Stateless
#Path("/Person")
#Produces(MediaType.APPLICATION_XML)
public class RestService {
#PersistenceContext(unitName = "mysqlPU")
EntityManager em;
#GET
#Path("{id}")
public Response Book(#PathParam("id") Long id) {
Person person = em.find(Person.class, id);
if(person == null) {
return Response.status(Response.Status.FORBIDDEN).build();
}
return Response.ok(person).build();
}
}
#ApplicationPath("/rs")
public class ApplicationConfig extends Application {
private final Set<Class<?>> classes;
public ApplicationConfig() {
HashSet<Class<?>> c = new HashSet<Class<?>>();
c.add(RestService.class);
classes = Collections.unmodifiableSet(c);
}
#Override
public Set<Class<?>> getClasses() {
return classes;
}
}
It is packaged in a jar file with other ejbs, outside of any .war. I'm am only able to access the service if I happen to have a war package inside the ear. I can access it with the context root of the war such as localhost:8080/warContextRoot/rs/. Is there any way to deploy a rest service without also deploying a war and still access it?
I think the reason is that you implemented the REST web service within an EJB session bean and EJBs are typically bundled in EAR files.
An alternative is that you can implement the REST web service as a regular Servlet, which serves requests through its standard GET/POST methods, then it can be deployed in a WAR. And you can invoke the REST web service through an URL defined in servlet mapping of web.xml.
Hope this helps.