SCBCD - EJB SQL
1)Which expression tests whether or not a collection designated by the collection-valued path expression is empty (i.e, has no elements)?
1)IS NULL
2)IS EMPTY
3)ISEMPTY
4)IS NOTHING
2)Which of the following clauses can be part of an EJB QL query? [Select all correct answers]
1)SELECT2)RETRIEVE
3)FROM
4)WHERE
5)WHEN
3)Which one of the following statements regarding EJB QL is correct?
1)It is valid in a EJB QL query to use an asterisk in the SELECT
clause as shorthand for retrieving an object.
2)EJB QL queries can take in parameters to allow dynamic specification of criteria values.
3)Only the SELECT
clause of an EJB QL query is required, you can optionally use a FROM
and WHERE
clause.
4)EJB QL queries have the FROM
clause to specify the criteria the results must match to be returned.
4)You want to use an EJB QL query to search for all the accounts for a specific department. The query needs to take the department name as a parameter (which will be available as a finder method with one parameter). Which one is the correct EJB QL query?
1)SELECT OBJECT(a) FROM Accounts a WHERE a.department = ?0
2)SELECT OBJECT(o) FROM Accounts a WHERE a.department = ?1
3)SELECT OBJECT(a) FROM Accounts a WHERE a.department = ?1
4)SELECT OBJECT(b) FROM Accounts a WHERE a.department = ?1
5)Which EJB QL query will return all the accounts for the sales department?
1)SELECT OBJECT(a) FROM Accounts a WHERE o.department = 'sales'
2)SELECT OBJECT(o) FROM Accounts a WHERE a.department = 'sales'
3)SELECT OBJECT(a) FROM Accounts a WHERE a.department = 'sales'
4)SELECT OBJECT(a) FROM Accounts a WHERE a.department <> 'sales'
6)Which of the following are restrictions regarding the use of EJB QL? [Select all correct answers]
1)EJB QL does not support the use of comments.
2)EJB QL does not support a mechanism to return only unique results from a query.
3)The data model for container-managed persistence supports inheritance as long as it is not multiple inheritance.
4)The data model for container-managed persistence does not currently support inheritance.
7)Which line of EJB QL will return back all accounts?
SELECT OBJECT(a) FROM Accounts a
SELECT * FROM Accounts
SELECT * FROM OBJECT
SELECT EJB(a) FROM Accounts a
8)Which of the following are reserved identifiers in EJB QL? [Select all correct answers]
1)FALSE
2)MEMBER
3)BUT
4)IF
9)Which of the following statements are correct? [Select all correct answers]
1)EJB QL uses a SQL-like syntax to select objects or values based on the abstract schema types and relationships of entity beans.
2)EJB QL has exactly the same keywords and statements as ANSI SQL. However it does not support INSERT statements.
3)The path expressions of EJB QL allow the Bean Provider to navigate over relationships defined by the cmr-fields
of the abstract schema types of entity beans.
4)EJB QL provides a facility to create triggers on the underlying database which can provide extended functionality such as auditing and extra security.
10)Which of the following statements are true regarding the BETWEEN expression? [Select all correct answers]
1)o.height BETWEEN 100 and 180 is equivalent to o.height > 100 AND o.height <180
2)o.height BETWEEN 100 and 180 is equivalent to o.height>= 100 AND o.height<= 180
3)o.height NOT BETWEEN 100 and 180 is equivalent to o.height<= 100 OR o.height>= 180
4)o.height NOT BETWEEN 100 and 180 is equivalent to o.height < 100 OR o.height > 180
Answers:
1)2
-
IS NULL
is used to test whether acmp-field
or single-valuedcmr-field
value isNULL
. This does not test if a collection is empty.IS EMPTY
tests whether or not the collection designated by the collection-valued path expression is empty (i.e., has no elements). A collection-valued path expression can only be used in theWHERE
clause in an empty collection comparison expression or in a collection member expression.ISEMPTY
is incorrect as it requires a space between the two words.IS NOTHING
is fictional and is not used within EJB QL.
2)1,3,4
-
Answers 1, 3 and 4 are correct.
An EJB QL query consists of a
SELECT
clause, which determines the type of the objects or values to be selected, aFROM
clause, which provides declarations that designate the domain to which the expressions specified in theSELECT
clause andWHERE
clause of the query apply and optionally aWHERE
clause, which may be used to restrict the results that are returned by the query.
-
Answer 1 is incorrect you cannot use an asterisk in the
SELECT
clause of an EJB QL query.Answer 2 is correct you can pass parameters into EJB QL queries. Input parameters can only be used in the
WHERE
clause of an EJB QL query. Input parameters are specified using the question mark "?" prefix followed by the number of the parameter .e.g. ?1. The number of input parameters in an EJB QL query must not exceed the number of input parameters for the finder or select method. It is not required that the EJB QL query use all of the input parameters for the finder or select method. An input parameter evaluates to the type of the corresponding parameter defined in the signature of the finder or select method with which the query is associated.Answer 3 is incorrect for an EJB QL query to be valid it must have both a valid
SELECT
clause and a validFROM
clause.Answer 4 is incorrect the
FROM
clause is used to specify the query domain of the EJB QL query. TheWHERE
clause is used to specify the criteria of the query.
-
Answer 1 is incorrect as the parameters of a finder method use a 1 based index (instead of a zero based index).
Answer 2 is incorrect as there is no alias 'o' specified in the
FROM
clause of the query.Answer 3 is correct as it uses the correct syntax for an EJB QL query and labels the parameter using a "?1" which specifies the only parameter for the finder method.
Answer 4 is incorrect because there is no alias 'b' specified in the
FROM
clause of the EJB QL query (this would have been correct if theFROM
has aliased Accounts as 'b').
-
Answer 3 is the correct answer as it conforms to the correct EJB QL syntax and uses an alias of "a" for the
SELECT
,FROM
andWHERE
clause.Answer 1 refers to
o.department
in theWHERE
clause which is wrong becauseAccounts
is aliased using "a" in theFROM
clause.Answer 2 uses the wrong alias of "o" in the
SELECT
clause, as the alias is defined as "a" in theFROM
clause.Answer 4 selects all the accounts apart from the sales department ones, which is incorrect.
6)1,4
-
Answer 1 is correct the EJB QL does not support the use of comments.
Answer 2 is incorrect, using the keyword
DISTINCT
allows you to specify a query that only returns unique results from a query.Answer 3 is incorrect and so therefore answer 4 is correct. The data model for container-managed persistence does not support inheritance. For this reason entity objects or value classes of different types cannot be compared. Any EJB QL queries that contain such comparisons are invalid. Another restriction regarding the use of EJB QL is that date and time values should use the standard Java long millisecond value.
-
Answer 1 is the only correct answer. Answers 2 and 3 are SQL Queries which EJB QL will not understand. Answer 4 uses EJB instead of OBJECT, this which will not work.
An EJB QL query must consist of a
SELECT
clause and aFROM
clause. An EJB QL query can also optionally use aWHERE
clause.The
SELECT
clause determines the type of the objects or values to be selected by the query.The
FROM
clause provides declarations that determine the domain to which the expressionsSELECT
andWHERE
clause should apply.A
WHERE
clause (which is optional) can be used to filter the results returned by the EJB QL query.
-
Answers 1 and 2 are correct. The following are the reserved identifiers in EJB QL:
SELECT
,FROM
,WHERE
,DISTINCT
,OBJECT
,NULL
,TRUE
,FALSE
,NOT
,AND
,OR
,BETWEEN
,LIKE
,IN
,AS
,UNKNOWN
(not used as yet but reserved),EMPTY
,MEMBER
,OF
andIS
.An identifier in EJB QL must be a valid Java identifier and is not allowed to have the same name as either an abstract-schema-name or an ejb-name within the same deployment descriptor. Case is not important for an identifier as EJB QL is case insensitive. An identifier is not allowed to be any of the EJB QL reserved keywords.
9)1,3
-
Answer 1 is correct, EJB-QL uses a SQL-like syntax to select objects or values based on the abstract schema types and relationships of entity beans.
Answer 2 is incorrect, EJB QL has similarities to ANSI SQL however they do not use the same statements and keywords. SQL is used for querying relational database management systems such as DB2 or Oracle. EJB QL provides facility for querying objects and their relationships.
Answer 3 is correct, a path expression is an identification variable followed by a period (.) and either a
cmr-field
orcmp-field
. As in Java notation e.g.object.childobject.name
, Path expressions can be composed from other path expressions as long as the original path expression evaluates to a single type i.e. not a collection.Answer 4 is incorrect as EJB QL is a query language and does not provide access to underlying persistence storage functionality.
-
Answers 2 and 4 are correct.
The
Between
expression is the equivalent of using a combination of '<' and '>' and is used in the same way as theBETWEEN
expression in SQL.If the value of an arithmetic expression used in a between expression is
NULL
, the value of theBETWEEN
expression is unknown.
No comments:
Post a Comment