javax.ejb.FinderException Java Examples

The following examples show how to use javax.ejb.FinderException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JpaCmpEngine.java    From tomee with Apache License 2.0 6 votes vote down vote up
public List<Object> queryBeans(final BeanContext beanContext, final String signature, final Object[] args) throws FinderException {
    final EntityManager entityManager = getEntityManager(beanContext);

    Query query = createNamedQuery(entityManager, signature);
    if (query == null) {
        final int parenIndex = signature.indexOf('(');
        if (parenIndex > 0) {
            final String shortName = signature.substring(0, parenIndex);
            query = createNamedQuery(entityManager, shortName);
        }
        if (query == null) {
            throw new FinderException("No query defined for method " + signature);
        }
    }
    return executeSelectQuery(query, args);
}
 
Example #2
Source File: EjbSelect.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static int execute_int(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;

    final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "int", args);
    return result.intValue();
}
 
Example #3
Source File: EjbSelect.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static float execute_float(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;

    final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "float", args);
    return result.floatValue();
}
 
Example #4
Source File: BasicBmp2DataSourcesBean.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Maps to BasicBmp2DataSourcesHome.findByPrimaryKey
 *
 * @param primaryKey
 * @return Integer
 * @throws javax.ejb.FinderException
 */
public Integer ejbFindByPrimaryKey(final Integer primaryKey)
    throws javax.ejb.FinderException {
    boolean found = false;
    try {
        final InitialContext jndiContext = new InitialContext();
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/jdbc/basic/entityDatabase");
        final Connection con = ds.getConnection();

        try {
            final PreparedStatement stmt = con.prepareStatement("select * from entity where id = ?");
            try {
                stmt.setInt(1, primaryKey.intValue());
                found = stmt.executeQuery().next();
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        throw new FinderException("FindByPrimaryKey failed");
    }

    if (found) return primaryKey;
    else throw new javax.ejb.ObjectNotFoundException();
}
 
Example #5
Source File: EjbSelect.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static boolean execute_boolean(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;

    final Boolean result = (Boolean) cmpContainer.select(beanContext, methodSignature, "byte", args);
    return result;
}
 
Example #6
Source File: EmployeeBean.java    From tomee with Apache License 2.0 5 votes vote down vote up
public Integer ejbFindByPrimaryKey(final Integer primaryKey)
    throws javax.ejb.FinderException {
    boolean found = false;
    try {
        final InitialContext jndiContext = new InitialContext();

        final javax.sql.DataSource ds = (javax.sql.DataSource) jndiContext.lookup("java:comp/env/jdbc/orders");

        final Connection con = ds.getConnection();

        try {
            final PreparedStatement stmt = con.prepareStatement("select * from Employees where EmployeeID = ?");
            try {
                stmt.setInt(1, primaryKey.intValue());
                final ResultSet rs = stmt.executeQuery();
                found = rs.next();
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        e.printStackTrace();
        throw new FinderException("FindByPrimaryKey failed");
    }

    if (found)
        return primaryKey;
    else
        throw new javax.ejb.ObjectNotFoundException();


}
 
Example #7
Source File: BasicBmpBean.java    From tomee with Apache License 2.0 5 votes vote down vote up
/**
 * Maps to BasicBmpHome.findByPrimaryKey
 *
 * @param lastName
 * @return
 * @throws javax.ejb.FinderException
 * @see BasicBmpHome#sum
 */
public java.util.Collection ejbFindByLastName(final String lastName)
    throws javax.ejb.FinderException {
    final java.util.Vector keys = new java.util.Vector();
    try {
        final InitialContext jndiContext = new InitialContext();
        final DataSource ds = (DataSource) jndiContext.lookup("java:comp/env/jdbc/basic/entityDatabase");
        final Connection con = ds.getConnection();

        try {
            final PreparedStatement stmt = con.prepareStatement("SELECT id FROM entity WHERE last_name = ?");
            try {
                stmt.setString(1, lastName);
                final ResultSet set = stmt.executeQuery();
                while (set.next()) keys.add(new Integer(set.getInt("id")));
            } finally {
                stmt.close();
            }
        } finally {
            con.close();
        }
    } catch (final Exception e) {
        throw new FinderException("FindByPrimaryKey failed");
    }

    if (keys.size() > 0) return keys;
    else throw new javax.ejb.ObjectNotFoundException();
}
 
Example #8
Source File: EjbSelect.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static char execute_char(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;

    final Character result = (Character) cmpContainer.select(beanContext, methodSignature, "char", args);
    return result;
}
 
Example #9
Source File: EjbSelect.java    From tomee with Apache License 2.0 5 votes vote down vote up
public static long execute_long(final Object obj, final String methodSignature, final Object... args) throws FinderException {
    final BeanContext beanContext = (BeanContext) obj;
    final Container container = beanContext.getContainer();
    if (!(container instanceof CmpContainer)) {
        throw new FinderException("Deployment is not connected to a CmpContainer " + beanContext.getDeploymentID());
    }
    final CmpContainer cmpContainer = (CmpContainer) container;

    final Number result = (Number) cmpContainer.select(beanContext, methodSignature, "long", args);
    return result.longValue();
}
 
Example #10
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a collection local ejb
 */
public Collection ejbHomeSelectCollectionLocalEjb() throws FinderException {
    return ejbSelectCollectionLocalEjb();
}
 
Example #11
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a single float field
 */
public float ejbHomeSelectSingleFloatField(final float value) throws FinderException {
    return ejbSelectSingleFloatField(value);
}
 
Example #12
Source File: CmpContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
public int update(final BeanContext beanContext, final String methodSignature, final Object... args) throws FinderException {
    final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;

    // exectue the update query
    return cmpEngine.executeUpdateQuery(beanContext, signature, args);
}
 
Example #13
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a single boolean field
 */
public boolean ejbHomeSelectSingleBooleanField(final boolean value) throws FinderException {
    return ejbSelectSingleBooleanField(value);
}
 
Example #14
Source File: CmpContainer.java    From tomee with Apache License 2.0 4 votes vote down vote up
public Object select(final BeanContext beanContext, final String methodSignature, final String returnType, final Object... args) throws FinderException {
    final String signature = beanContext.getAbstractSchemaName() + "." + methodSignature;

    try {
        // execute the select query
        final Collection<Object> results = cmpEngine.queryBeans(beanContext, signature, args);

        //
        // process the results
        //

        // If we need to return a set...
        final Collection<Object> proxies;
        if (returnType.equals("java.util.Set")) {
            // we collect values into a LinkedHashSet to preserve ordering
            proxies = new LinkedHashSet<>();
        } else {
            // otherwise use a simple array list
            proxies = new ArrayList<>();
        }

        final boolean isSingleValued = !returnType.equals("java.util.Collection") && !returnType.equals("java.util.Set");
        ProxyFactory proxyFactory = null;
        for (Object value : results) {
            // if this is a single valued query and we already have results, throw FinderException
            if (isSingleValued && !proxies.isEmpty()) {
                throw new FinderException("The single valued query " + methodSignature + "returned more than one item");
            }

            // if we have an EntityBean, we need to proxy it
            if (value instanceof EntityBean) {
                final EntityBean entityBean = (EntityBean) value;
                if (proxyFactory == null) {
                    final BeanContext result = getBeanContextByClass(entityBean.getClass());
                    if (result != null) {
                        proxyFactory = new ProxyFactory(result);
                    }
                }

                if (proxyFactory != null) {
                    if (beanContext.isRemoteQueryResults(methodSignature)) {
                        value = proxyFactory.createRemoteProxy(entityBean, this);
                    } else {
                        value = proxyFactory.createLocalProxy(entityBean, this);
                    }
                }
            }
            proxies.add(value);
        }

        // if not single valued, return the set
        if (!isSingleValued) {
            return proxies;
        }

        // single valued query that returned no rows, is an exception
        if (proxies.isEmpty()) {
            throw new ObjectNotFoundException();
        }

        // return the single item.... multiple return values was handled in for loop above
        return proxies.iterator().next();
    } catch (final RuntimeException e) {
        throw new EJBException(e);
    }
}
 
Example #15
Source File: ManyToManyComplexPkTests.java    From tomee with Apache License 2.0 4 votes vote down vote up
private PlatformLocal findPlatform(final int platformId) throws FinderException {
    return platformLocalHome.findByPrimaryKey(new PlatformPk(platformId, "value" + platformId));
}
 
Example #16
Source File: OneToOneComplexPkTests.java    From tomee with Apache License 2.0 4 votes vote down vote up
private PersonLocal findPerson(final int personId) throws FinderException {
    return personLocalHome.findByPrimaryKey(new PersonPk(personId, "value" + personId));
}
 
Example #17
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a collection int field
 */
public Collection ejbHomeSelectCollectionIntField() throws FinderException {
    return ejbSelectCollectionIntField();
}
 
Example #18
Source File: ABean.java    From tomee with Apache License 2.0 4 votes vote down vote up
public ALocal ejbHomeSelectTest(final String test) throws FinderException {
    return ejbSelectTest(test);
}
 
Example #19
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a single long field
 */
public long ejbHomeSelectSingleLongField(final long value) throws FinderException {
    return ejbSelectSingleLongField(value);
}
 
Example #20
Source File: TradeWebSoapProxy.java    From dacapobench with Apache License 2.0 4 votes vote down vote up
public AccountDataBean getAccountData(String userID) throws FinderException, RemoteException {
	return convertAccountDataBean(getTrade().getAccountData(userID));
}
 
Example #21
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a single remote ejb
 */
public Object ejbHomeSelectSingleRemoteEjb(final int value) throws FinderException {
    return ejbSelectSingleRemoteEjb(value);
}
 
Example #22
Source File: QueryBean.java    From tomee with Apache License 2.0 4 votes vote down vote up
/**
 * Select a collection long field
 */
public Collection ejbHomeSelectCollectionLongField() throws FinderException {
    return ejbSelectCollectionLongField();
}
 
Example #23
Source File: QueryHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a single long field
 */
public abstract long selectSingleLongField(long value) throws FinderException, RemoteException;
 
Example #24
Source File: BasicBmp2DataSourcesBean.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Maps to BasicBmp2DataSourcesHome.findEmptyCollection
 *
 * @return Collection
 * @throws javax.ejb.FinderException
 */
public java.util.Collection ejbFindEmptyCollection()
    throws javax.ejb.FinderException, java.rmi.RemoteException {
    return new java.util.Vector();
}
 
Example #25
Source File: QueryLocalHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a single long field
 */
public abstract long ejbSelectSingleLongField(long value) throws FinderException;
 
Example #26
Source File: QueryLocalHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a single int field
 */
public abstract int ejbSelectSingleIntField(int value) throws FinderException;
 
Example #27
Source File: QueryLocalHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a collection byte field
 */
public abstract Collection ejbSelectCollectionByteField(byte test) throws FinderException;
 
Example #28
Source File: QueryLocalHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a collection boolean field
 */
public abstract Collection ejbSelectCollectionBooleanField(boolean test) throws FinderException;
 
Example #29
Source File: QueryLocalHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a collection remote ejb
 */
public abstract Collection ejbSelectCollectionRemoteEjb(String test) throws FinderException;
 
Example #30
Source File: QueryHome.java    From tomee with Apache License 2.0 2 votes vote down vote up
/**
 * Select a single float field
 */
public abstract float selectSingleFloatField(float value) throws FinderException, RemoteException;