EJB Annotations

Annotations are like meta-tags that you can add to the code and apply to package declarations, type declarations, constructors, methods, fields, parameters, and variables. They provide helpful ways to indicate whether the methods are dependent on other methods, whether they are incomplete, whether the classes have references to other classes, and so on.

Below is a list of Junos Space SDK annotations that can be used on EJB resources.

Junos Space Annotations for EJBs

Annotations for the EJB Implementation Class

ANNOTATION EXAMPLE DESCRIPTION
@Cursor @Cursor(
   entityClass = CountryEntity.CLASSNAME,
   queryName = CountryEntity.GET_ALL_COUNTRIES
)

public PagingResult<country> getCountries(PagingContext ctx) throws Exception </country>

Applicable on an EJB method. This annotation enables paging on EJB API variables.

Variables

entityClass
Name of the JPA entity class whose query will be used for paging.
queryName
Name of the query that will be used for filtering.
@Domain @TransactionAttribute(TransactionAttributeType.REQUIRED)
@Domain
public Country addCountry(ApiContextInterface ctx, Country country) throws Exception

All EJB APIs that create a new object need to be marked with the @Domain annotation. If this annotation is not added, the objects is created in the SYSTEM domain. We recommend that you add the @Domain annotation to all object create/add methods in the EJB session beans. If an application wants all objects to be created in the Global domain only, then set @Domain(enabled=false). Only entities that have the @ManagedObject annotation in the entity definition will have the domainId column populated. Once the API is annotated with the @Domain annotation, Junos Space will populate the domainId column of the object being created.

Variables

None

@DomainWriteProtect @DomainWriteProtect(value = CountryEntity.CLASSNAME)
public Country updateCountry(ApiContextInterface ctx, @Modifiables int countryId, Country country) throws Exception

Each EJB method that updates or deletes an object needs to be annotated with @DomainWriteProtect. This annotation disallow update/delete actions on objects (parent domain objects) by users that have read only access (due to parent read up enabled on the subdomain). The purpose of the @DomainWriteProtect is to provide write protection on objects that are not accessible to users who do not have access to the domain to wich the object belongs. The use of @DomainWriteProtect is not required for add/insert methods.

The @Modifiables annotation is required on the primary key the method. In the example, countryId is the primary key used to find the object in the database.

Variables

value
The object on which to disallow update or delete actions.
@JobData @JobData(
    name = "World Cities Country Report",
    iconFileName = "WorldCities_ui/jssdk/world-cities_job_countries_tree_265x315.png",
    detailsActionURL = "/mainui/ctrl/deviceScriptManagerWeb/CMPServlet?
    action = net.juniper.jmp.cems.deviceScriptManagerUI.action.ScriptMgmtJobReportBuilder",
    detailsActionType = "grid"
)

@Schedulable
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public JobInfoTO runDeployScriptsOnDevices(Collection<scriptmgmtmo> scriptMgmtMOList,
    ScheduleContext sctx)

@JobData (
     name = "World Country Report",
     iconFileName =      "WorldCities/ui/jssdk/countries_tree_265x315.png”,
     detailsREST_HREF=“/api/jssdk/world-cities/job-instances/{job-id}/world-cities-results”,
     detailsREST_MediaType=“vnd.jssdk.world-cities.world-cities-results"
)

@Schedulable
@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
public JobInfoTO runCountriesReport(ScheduleContext scheduleCtx)

Applicable on schedulable APIs of an EJB. This attribute is used to display the job scheduled by the corresponding API of the EJB in the Junos Space UI.

Variables

name (required)
The GUI-facing name for this job.
iconFileName
The file name for this icon in the job manager's thumbnail view. The file name format is <app-name>_<root-context-from-application.xml>_<icon-file-path-relative-to-preload-directory>. The icon file is located in a subdirectory of your application (under /web/images/preload). For example the path WorldCities_ui/jssdk/world-cities_job_countries_tree_265x315.png corresponds to the file WorldCitiesWeb/web/images/preload/jobs/countries_tree_265x315.png image file.
detailsActionURL
If you need a special URL for showing job result details (for example, when you double click on a job in the job manager's inventory landing page), specify the URL with this variable. Otherwise, the default form is used.
detailsActionType
If detailsActionURL is set, set this variable to either “form” or “grid”, depending on the top-level element of the URL.
detailsREF_HREF
detailsREST_MediaType
These fields are used when querying the REST API for drilling down to job details. In general, developers are responsible for creating and maintaining stores that save job results. Hence, when retrieving job results, there must be a proxy between the request to Job Manager and the implementing job’s service. The detailsREST_HREF variable must include the {job-id} property, and you must always use hard-coded "job-id".
@Modifiables @DomainWriteProtect(value = CityEntity.CLASSNAME)
public City updateCity(@Modifiables int cityId, City city) throws Exception
Required on the primary key parameter when using @DomainWriteProtect to write protects objects that can be updated or deleted by an EJB method. In the example, cityId is the primary key used to find the object in the database..
@Schedulable @Schedulable
@TransactionAttribute( TransactionAttributeType.REQUIRED )
public JobInfoTO getCountriesScheduledLRR(ScheduleContext scheduleCtx);
throws Exception;

Applicable on an EJB method. This annotation is used to mark the methods that can be scheduled in the future. This annotation is used by the job manager interceptor to push scheduling information.

Variables

None

Annotations for the Managed Object Class

ANNOTATION EXAMPLE DESCRIPTION
@Filterable @Filterable(entityAttrName = "country")
public String getName() {
   return name;
}

Applicable on the getter/setter of an EJB managed object class. This annotation enables filtering at the EJB level. @Filterable provides the name of an attribute in a JPA entity mapped to the attribute name in the managed object that is used in creating the filtering query criteria.

Variables

entityAttrName
Name of the attribute in the JPA entity class.
entityClassName
Name of the JPA entity class.
@JmpNotification @JmpNotification(destination = "topic/WorldCitiesDatabaseChange")
@XmlAccessorType(XmlAccessType.NONE)
public class Country extends AbstractManagedObject implements Serializable {}

Applicable on a managed object class in an EJB. This annotation specifies that if there is any change in the JPA entity of this managed object, the change should be published on the topic provided as the destination value.

Variables

destination
Name of the topic on which a change notification needs to be published.

Annotations for the JPA Entity Class

ANNOTATION EXAMPLE DESCRIPTION
@ManagedObject @Table(name = "CountryEntity", uniqueConstraints = {
@UniqueConstraint(columnNames = "country") })
@ManagedObject(value={"net.juniper.jmp.worldcities.ejb.Country"},uri="/api/space/WorldCities/countries/{id})
public class CountryEntity extends OptimisticEntity

Applicable on a JPA entity class. This annotation specifies the name of a managed object class for a JPA entity.

Variables

value
Name of the managed object class for this JPA entity.
uri
Pattern of the URI. This URI is added for all data change notifications for this entity.
@Sortable @Sortable(entityAttrName = "country")
public String getName() {
   return name;
}

Applicable on the getter or setter of an EJB managed object class. This annotation enables sorting at the EJB level. @Sortable provides the name of the attribute in the JPA entity mapped to the attribute name in the managed object that will be used in creating the sorting query criteria.

Variables

entityAttrName
Name of the attribute in the JPA entity class.
entityClassName
Name of the JPA entity class.