Flexible queries are already cached in hybris commerce which provide good performance in most of projects. Generally, hybris regions cache performs well when system has more read of data than writes. Frequent changes to data (products, images, master data etc.) will result in invalidation of cached entities, types and flexible queries on all nodes forcing system to fetch data from database as cache has been invalidated. Projects having very frequent changes in database can suffer from high performance degradation due to frequent invalidations.
In this post we will be discussing an option to stop invalidation of query for specified amount of time irrespective of change in items in database, this feature is called TTL – Tme To Live. The value of TTL is defined in session context which enforces query to live at least for this duration. Implementation of TTL can significantly improve performance in applications which have frequent changes in database.
Below are steps to executed to implement TTL in a project:
Create an aspect class as below – this class is picking configurable properties: a flag and duration of TTL (in seconds) from configuration file and sets in session context:
Define spring bean:
Add AOP configuration for specific methods to enable TTL caching:
Please note this feature should be tuned as per your use case. Applications with less writes than reads can have adverse affect on performance. Downside of this configuration is that cached queries will not pick changes immediately on storefront for the defined time so there need to be ballance between performace gain vs data accuracy. Overall this is a very good option to finetune the performance of hybris applications.
SAP Hybris commerce ships with an extension generator tool called extgen, which is short for extension generator. Using extgen tool, you can create new extension based on extension templates. With the extgen tool, you can create one new extension using one template extension. From a technical perspective, any extension can be used as a template extension. The extgen tool is fairly basic in that it simply replaces the tokens configured in properties file.
SAP Hybris Commerce installation
Before running the extgen tool, you need to download the latest version of SAP Hybris Commerce.
Once you have downloaded SAP Hybris Commerce, extract the Hybris Commerce ZIP file.
1.Open a command prompt.
2.Navigate to the %HYBRIS_HOME_DIR%/installer directory.
3. Invoke the installer with the b2c_acc recipe by entering the following command.
Steps to create an extension using extgen
1.Navigate to the %HYBRIS_HOME_DIR%/hybris/bin/platform directory
2. Now run setantenv.bat file. Do not close the command prompt.
Extgen prompts you to specify values for the technical aspects of an extension. Extgen comes with default values for all these technical aspects.
These default values are defined in the project.properties file in the extgen directory. The default value is displayed in brackets ([ and ])
Choose a template for generation
Press enter to use the default value. Here default value is [yempty] and we press enter.
Choose the name of extension
Here we specify the name of the extension is hybrisdiary.
Choose the package name
We can choose default package name for our extension but we specify the name of the package is org.bitbyte .
Now observe that new extension(hybrisdiary) has been created inside hybris/bin/custom folder.
Configure localextension.xml file
Add your extension to your X:\%HYBRIS_HOME_DIR%\hybris\config/localextensions.xml. After the creation of extensions using extgen, make sure to update the localextensions.xml file as below
SmartEdit provides Navigation management that enables you to add, move, edit and delete navigation nodes for a content catalog. You can easily change the order of the navigation nodes using drag and drop feature. You can also add, edit and remove entries from navigation nodes. Entries are pages, media, and components that you associate with navigation nodes.
When you create a website based on an existing content catalog, a default navigation structure is created for your content catalog. If you create a website based on a new content catalog, you must build navigation structure for your new content catalog.
Signing into SmartEdit
SmartEdit provides an intuitive user interface that allows content managers to easily edit the content catalog of their companies website.
We assume that your server has started already and now follow following steps to sign in into SmartEdit
MVC stands for model view controller. It is a software design pattern for developing web applications. It is very popular because it isolates the application logic from the user interface layer and supports separation of concerns. The controller receives all requests for the application and then works with the model to prepare any data model by the view. The view then uses the data prepared by the controller to generate a final presentable response. The MVC abstraction can be graphically represents as follows
It is responsible for managing application data. It responds to the request from view and to the instructions from controller to update itself.
It is responsible for displaying all data or only a portion of data to users. It also specifies the data in a particular format triggered by the controller’s decision to present the data.
It is responsible to control the relation models and views. It responds to user input and performs interactions on the data model objects. The controller receives input, validates it, and then performs business operations that modify the state of the data models.
Scope is passed as first argument to controller during its constructor definition.
$scope.firstName and $scope.lastName are the models.
We have set values to models which will be reflected in the application module whose controller is myController.
A module defines an application. It is container for the different parts of your application like controller, services, filters, directives etc.
Controller always belong to a module.
Creation of a module
A module is created by using the AngularJS function angular.module
The “myApp” parameters refers to an HTML element in which the application will run. Now we can add controllers, directives, filters, and more, to your AngularJS application.
In the following example we will explain module and controller.
ng-app directive is used to denote that this application should be considered as an angular application. “myApp” is the name given to our AngularJS application.
In body tag we have added an ng-controller directive along with the name of our controller “myControl”. This basically makes our body tag the ability to access the contents of the “myControl”. We need to mention the name of the controller under the directive to ensure that we are able to access the functionality defined within the controller.
We are creating a module which will attached to our “myApp” So this module now becomes part of our application.
In the module, we define a function which assigns a value of “Bit” and “Byte” to our firstName and lastName variables respectively.
ng-bind:-This directive binds the value of HTML inputs controls to application data.
ng-model:-This directive binds the values of AngularJS application data to HTML input controls(input, selection, text area).
ng-repeat:-This directive repeats HTML elements for each item an collection.
ng-app directive defines the root element. It starts an AngularJS application and automatically initializes or bootstraps the application when web page containing AngularJS application is loaded. It is also used to load various AngularJS modules in AngularJS application.
The ng-app directive also tells AngularJS that the <body> is the owner of the AngularJS application.
ng-init directive initializes an AngularJS application data. It is used to put values to the variables to be used in the application.
In the following example. we will initialize the variable
ng-bind directive bind the application data to HTML view. The ng-bind directive bind AngularJS data to HTML the same way as AngularJS expression.
This directive binds the values of AngularJS application data to HTML input controls. In following example, we’ve defined a model named “name” and access that variable using ng-bind directive.
ng-repeat directive repeats HTML elements for each item in a collection
We have so many other built in directives that we will discuss later.
Before entering into spring boot just a brief summary about spring
What is Spring??
Spring is a high performance, lightweight, non-invasive, easily testable application framework. Using spring we can develop all layer implementations unlike struts (struts framework supports only developing web applications).
In one line we can say spring is the end to end application development framework.
The core concept of spring framework is dependency injection. By dependency injection, we can achieve loose coupling.
What does it do??
Spring approach is developing enterprise Java applications by using POJOs. Because of using POJOs no need of application server we can use the servlet container.
There are so many enterprise Java applications, all these applications having some similarities. When we write a business service to solve business problem spring handle all those things like connecting to the database, establishing transaction service and so on…Spring provides a template for this to build these applications.
The flexibility with the spring is we can concentrate only building on business services and spring handle rest of the common things like connecting to the database, running queries and handling HTTP requests…
Spring provides infrastructure support, for example, spring connecting to the databases like the relational database and mango DB, spring has infrastructure support when we are building our applications.
Spring framework Pros and Cons….
Multiple setup and configuration steps.
Multiple build and deploy steps.
The learning curve would be high.
So Spring Boot comes as handy…!!!
What is Spring Boot??
“Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can just run.” — from official spring.io
The main aim of spring boot is accelerating (speed up) application development, by the “convention over configuration” approach.
By using Spring Boot, we can develop end to end application with production ready.
What does it do??
Spring Boot reduces the complexity of dependency management with the help of spring boot starters concept. Whereas in spring we need to search for the required libraries for specific spring version.
For example, if we want to declare the web related dependencies, in general, we need to declare each and every dependency related to the web. But in the case of Spring Boot, we declare only one dependency “spring-boot-starter-web” it pulls all the required dependencies for the web module.
Some common configurations such as DataSource, JdbcTemplate, DispatcherServlet, HandlerMapping……. Spring Boot comes with the auto configuration to configure all these configurations by adding @SpringBootApplication or @EnableAutoConfiguration.
By using Spring Boot, we can create the standalone application and just run like normal java application we don’t have to find out servlet container because Spring Boot comes with the embedded servlet container. Whereas traditional Spring application we are building a war file and deploy in the servlet container.
Spring Boot comes with production ready features.
We will use Maven or Gradle build for Spring Boot application.
Spring Boot works with Spring 4.x version and later. And JDK 1.8
Eclipse or STS
To build spring application we need to manage dependencies, so we need to add required jars for the specific version of spring. We will add the jars to the classpath so that the classes in jars are available to that application.
We are not following this approach, we are using Maven (build and dependency management tool) in Maven we will declare all the dependencies in pom.xml file and so that maven tool will automatically import required jars from the repository to our classpath.
Sample Spring Boot Application:
Create a simple Maven project.
Skip the archetype by selecting the create a simple project
Enter the group id, Artifact Id, and Name
Package Structure of SampleSpringBoot project
The default dependency file (pom.xml) is like below.
We adding the dependency spring boot starter parent which will act as a parent for the all remaining spring boot dependencies. And we are adding Java version and spring boot starter web dependency
We are creating SpringBootDemo application this is the starting point for our application and @SpringBootApplication tells spring this is spring boot application and create servlet container and deploy in a container.
What SpringApplication class will do??
Setup default configuration
Starts spring application context
Every spring application has application context which runs the spring application
Performs class path scan
If we declare a class with annotation @Service or @Controller … spring will look at those classes and treated service annotation service, controller annotation as a controller to identify all these classes it has to be scan the class path
Starts Tomcat Server
No need to download any Tomcat server by default it comes with spring boot so the output of the application is as standard application
We are creating Rest Controller to handle HTTP requests.
Overriding Tomcat port number in “application. properties” file, if the Tomcat default port (8080) is listening to some other process.
Run the sample spring boot application as like normal Java application.
By running sample spring boot application as a standalone java application, tomcat will have started automatically on the port 9090.
To verify this in the browser, just enter the localhost port number and request mapping.