Modern Topics In IT All In One
Introduction to Modern Topics in IT
- Module Code: IT4020
- Enrollment key: IT4020
- Lecturer-In-Charge: Ms. Gaya Thamali Dassanayake
- Lecturers: Mr. Udara Samarathunga, Mr. Ishara Gamage
- Email: thamali.d@sliit.lk
IT Trends in 2022
- The IT world is constantly evolving with new technologies, tools, software frameworks, and innovative ideas.
- Modern technologies develop symbiotically, affecting one another.
- For example, mobile internet depends on cloud computing and facilitates IoT development. A breakthrough in one area stimulates innovations in others.
- Top information technology trends defined in 2022:
- Artificial Intelligence and Machine Learning
- 5G Proliferation
- Quantum Computing
- Blockchain
- Cybersecurity
- Edge Computing
- Robotic Process Automation (RPA)
- Virtual Reality and Augmented Reality
- Growth of IoT Networks
- Cloud Migration
Module Outline
- Module Name: Modern Topics in IT
- Module Code: IT4020
- Version No.: 2017 - 1
- Year/Level: 4
- Semester: 1
- Credit Points: 4
- Pre-requisites: IT1100, IT2020, IT2030
- Co-requisites: None
- Methods of Delivery: Lectures (Face-to-face), Tutorials, Labs
- Hours/Week: Lectures - 2, Tutorials - 1, Labs - 2
- Course Web Site: http://courseweb.sliit.lk/
- Date of Original Approval: January, 2017
- Date of Next Review: January, 2022
Learning Outcomes
- LO1: Apply knowledge of modern development tools, frameworks, and technologies in application development.
- LO2: Justify the usage of software engineering concepts when developing an application.
- LO3: Apply the latest concepts used in designing, deployment, and maintenance of IT infrastructure.
- LO4: Justify ecologies selected for a given requirement.
- LO5: Apply different development architectures for large-scale development.
Assessment Criteria
- Continuous Assessments:
- Assignments: 50% (LO1-LO5)
- End Semester Assessment:
- Final Examination: 50% (LO1 – LO5)
- Total: 100%
Contents
- Code Refactoring Techniques
- Modular Development
- Lambda Expressions and Functional programming
- Augmented Reality
- Microservices
- Cloud Computing
Modular Development and OSGi
- Lecture by Udara Samaratunge
- Topic: Modular Development - Open Service Gateway Initiatives
What is OSGi?
- OSGi (Open Services Gateway initiative)
- OSGi is a framework which allows modular development of applications using Java.
- A Java framework for developing (remotely) deployed service applications that require:
- Reliability
- Large scale distribution
- Wide range of devices
- Collaborative environment
- Created through a collaboration of industry leaders like IBM, Ericsson, Nokia, Sony, Telcordia, Samsung, ProSyst, Gatespace, BenQ, Nortel, Oracle, Sybase, Espial, and many more.
- OSGi containers allow you to break your application into individual modules (JAR files with additional meta information, called bundles in OSGi terminology).
- It manages the cross-dependencies between modules.
- An OSGi framework offers dynamic loading/unloading, configuration, and control of these bundles without requiring restarts.
- Major Framework vendors:
- ProSyst
- Gate space Telematics
- IBM
- Siemens
- Espial
- Open source implementations:
- Apache Felix
- Eclipse Equinox
- Gate space Knopflerfish
Why use OSGi Service Platform?
- Addresses problems like:
- The limited (binary) software portability problem
- The complexity of building heterogeneous software systems
- Supporting the myriad of configuration, variations, and customizations required by today’s devices
- Managing the software on the device
OSGi Platform vs. Service Oriented Architectures (SOA)
- Separate the contract from the implementation
- Allows alternate implementations
- Dynamically discover and bind available implementations
- Binding based on contract (interface definitions)
- Components are reusable
- Components are not coupled to implementation details of other components, only their independent interfaces have to be known
OSGi Framework Architecture
- Mediates between communication & collaborations between applications.
- Provides life cycle management (install, start, stop, update, etc.).
- Policy-free – Policies are provided by bundles.
- Allows applications to share a single Java VM.
- Handles all class loading in a much better-defined way than standard Java (Versioning!).
- Gives isolation/security between applications.
OSGi Bundle Architecture
- Bundles: OSGi components made by developers.
- Services: Connect bundles dynamically, offering a publish-find-bind model for plain old Java objects.
- Life-Cycle: API to install, start, stop, update, and uninstall bundles.
- Modules: Defines how a bundle can import and export code.
- Security: Handles security aspects.
- Execution Environment: Defines what methods and classes are available in a specific platform.
What is a Bundle?
- In Java terms, a bundle is a plain old JAR file.
- In standard Java, everything in a JAR is completely visible to all other JARs.
- OSGi hides everything in that JAR unless explicitly exported.
- Reason for hiding is to maintain multiple versions of the same library.
- By default, there is no sharing.
- A bundle is the deliverable application, like a Windows EXE file.
- Content is a JAR file.
- A bundle registers zero or more services.
- A service is specified in a Java interface and may be implemented by multiple bundles.
- Services are bound to the bundle life-cycle.
- Searches can be used to find services registered by other bundles (Query language).
Bundle Contents
- A Bundle contains (normally in a JAR file):
- Manifest (bundle meta-data)
- Code (classes in packages)
- Resources (other files in the JAR file)
- The Framework:
- Reads the bundle's manifest
- Installs the code and resources
- Resolves dependencies
- Controls the bundle life cycle
- During Runtime:
- Calls the Bundle Activator to start the bundle
- Manages java class path for the bundle as a network of class loaders.
- Handles the service dependencies
- Calls the Bundle Activator to stop the bundle
- Cleans up after the bundle
OSGi Service Platform Layering
- The OSGi Service Platform is divided into a number of layers.
- Execution Environment: Provides a defined context for applications.
- The Module layer: Provides class loading and packaging specifications.
- The Services layer: Provides a collaboration model.
- The extensive Security layer: Is embedded in all layers.
OSGi Service Layer
- Provides an inside-VM service model
- Discover (and get notified about) services based on their interface or properties, no protocol required
- Bind to one or more services by:
- program control,
- default rules, or
- deployment configuration
- Service Oriented Architectures (SOA) Confusion
- Web services bind and discover over the net
- The OSGi Service Platform binds and discovers inside a Java VM
- The OSGi Alliance provides many standardized services
- OSGi defines a standard set of services
- Other organizations can define more (AMI-C, Ertico, JCP)
OSGi Module Layer
- Packaging of applications and libraries in Bundles
- Java has significant deployment issues
- Class Loading modularization
- Java provides the Class Path as an ordered search list, which makes it hard to control multiple applications
- Protection
- Java can not protect certain packages and classes from others.
- Versioning
- Java can not handle multiple versions of the same package in a VM
The Security Layer
- The OSGi Service Platform can be configured to be one of the most secure execution environments
- The security model is dynamic, unlike normal Java
- Fully under control of the operator:
- Fully controlled systems
- Walled gardens
- Fully open systems
- Services can require Service Permission if security is enabled
- Fully under operator control
- A number of extra rules to increase the overall system security
Practical Example
- Scenario: An application interacting with a MySQL database needs to update its mysql-connector library due to a bug fix.
- Traditional Approach: Stop the application and re-package it (or replace the older one).
- OSGi Approach: No need to stop the whole application because everything is exposed either as a component or as a service.
- Just install the new component/service in the OSGi container.
- When the services/components are updated in OSGi container there are various event listeners that propagate the service/component update event to service/component consumers.
- Consumers adapt themselves to use the new version of the web service (on the consumer side we need to listen for various events so that consumers can decide whether to respond for change or not).
OSGi Services
- The Framework Service Registry is available to all bundles to collaborate with other bundles.
- Different bundles (from different vendors) can implement the same interface.
- Implementation is not visible to users
- Allows the operator to replace implementations without disrupting service
- A bundle can create an object and register it with the OSGi service registry under one or more interfaces.
- Other bundles can go to the registry and list all objects that are registered under a specific interface or class.
- A bundle can therefore register a service, get a service, and listen for a service to appear or disappear.
- Multiple bundles can register objects under the same interface or class with the same name.
- Services are associated with properties
- Powerful query language to find appropriate service
- Bundles can update the properties of a service dynamically
- A bundle can decide to withdraw its service from the registry while other bundles are still using this service
- A bundle can use a service (bind to) with any cardinality
- 1..1, 0..1, 0..n
- A service can be discovered dynamically
- Active search with query filter
- Listener interface
- Services are dynamic
- A bundle can decide to withdraw its service from the registry while other bundles are still using this service. Bundles using such a service must then ensure that they no longer use the service object and drop any references.
- Services can go away at any time! This is very dynamic!
Bundle Deployment
- Bundles are deployed on an OSGi framework, the bundle runtime environment.
- This is not a container like Java Application Servers. It is a collaborative environment.
- Bundles run in the same VM and can actually share code.
- The framework uses the explicit imports and exports to wire up the bundles so they do not have to concern themselves with class loading.
Component Interaction and Collaboration
- OSGi is more than an Applet, MIDlet, Xlet runner
- Bundles can collaborate through:
- service objects
- package sharing
- A dynamic registry allows a bundle to find and track service objects
- Framework fully manages this collaboration
- Dependencies, security
Functionalities supported by OSGi:
- Reduces the complexity of the system.
- Managing service/component dependencies.
- Makes the components loosely-coupled and easy to manage.
- Increases the performance of the system.
OSGi and Performance
- Consider a scenario where you have a large application which uses a logging framework.
- This logging framework can be deployed as an OSGi Bundle, which can be managed independently.
- Therefore, it can be started when required by our application and can be stopped when not in use.
- Also the OSGi container makes these bundles available as services, which can be subscribed by other parts of the application.
Custom products uses OSGi
- CQ5, uses the Apache Felix implementation of OSGI.
- Apache Felix is a open-source project to implement the OSGi R4 Service Platform.
- That includes:
- OSGi framework and standard services.
- OSGi-related technologies.
Layers: OSGi Life Cycle Layer
- System Bundle represents the OSGi Framework
- Provides an API for managing bundles:
- Install
- Resolve
- Start
- Stop
- Refresh
- Update
- Uninstall
- Bundle is started by the Bundle Activator class.
- Header in the JAR manifest file refers to this class.
- Bundle Activator interface has 2 methods:
- Start: Initialize and return immediately
- Stop: Cleanup
- The Bundle Activator gets a Bundle Context that provides access to the OSGi Framework functions.
- The Framework provides the Start Level service to control the start/stop of groups of applications.
OSGI life cycle methods States of bundles
- Installed – finish bundle installation
- Active – start the bundle
- Resolved – stop the bundle
- Registers the specified service object with the specified properties under the specified class name with the Framework.
Manipulating Services
- The Bundle Context provides the methods to manipulate the service registry.
- Services registrations are handled by Service Registration objects.
- They can be used to unregister a service or modify its properties
- Service Reference objects give access to the service as well as to the service’s properties.
- Access to service objects is through the getService method. These services should be returned with the ungetService method.
Code Refactoring Techniques
- Lecture 02 by Udara Samaratunge
Usage of Properties
.propertiesis a file extension mainly used in Java technologies.- Used to store configurable parameters of an application.
- Can also be used for storing strings for Internationalization and localization.
- Known as Property Resource Bundles.
- Properties are configuration values managed as key/value pairs.
- In each pair, the key and value are both String values.
- Properties extends
java.util.Hashtable. Some of the methods inherited from Hash Table support the following actions:- Testing to see if a particular key or value is in the Properties object
- Getting the current number of key/value pairs
- Removing a key and its value
- Adding a key/value pair to the Properties list
- Enumerating over the values or the keys
- Retrieving a value by its key
- Finding out if the Properties object is empty.
Read property file
/**
* Read a property file and its key value content
*/
public static void readProperty(){
FileInputStream fIstream = null;
Properties property = new Properties();
try {
fIstream = new FileInputStream(FILE_PATH);
property.load(fIstream);
System.out.println(property.getProperty(SERVER_URL));
System.out.println(property.getProperty(SERVER_USERNAME));
System.out.println(property.getProperty(SERVER_PASSWORD));
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}finally{
if(fIstream != null){
try {
fIstream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
//Constant for Property file path
public static final String FILE_PATH = "src\\Config.properties";
//Constant to read Property file for server url
public static final String SERVER_URL = "tomcat.manager.url";
//Constant to read Property file for server username
public static final String SERVER_USERNAME = "tomcat.manager.username";
//Constant to read Property file for server password
public static final String SERVER_PASSWORD = "tomcat.manager.password";
Output of above code:
http://localhost:8082/manager/text
admin
admin123
Best Practices for Reading Property Files
- Use
InputStreamand access through class path. - Use appropriate File Name
Generate property file
- Don’t use Deprecated methods. Instead, search for the most suitable method.
- Use
store()method instead.
Best Practice for Generating Property Files
/**
* Create property file to store build.xml configurations
*/
public static void createProperty() {
try {
Properties properties = new Properties();
properties.setProperty(APP_NAME, "OnlineDoctor");
properties.setProperty(SOURCE_DIR, "src");
properties.setProperty(BUILD_DIR, "build");
properties.setProperty(WEB_DIR, "WebContent");
properties.setProperty(WEB_PATH, "${web.dir}/WEB-INF");
properties.store(new FileOutputStream(PROPERTY_FILE_NAME),
COMMENT);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
// Constant to write Property file name
public static final String PROPERTY_FILE_NAME = "build.properties";
// Constant to write Property file for Application name
public static final String APP_NAME = "app.name";
// Constant to write Property file for source location
public static final String SOURCE_DIR = "src.dir";
// Constant to write Property file for build directory
public static final String BUILD_DIR = "build.dir";
// Constant to write Property file for web content
public static final String WEB_DIR = "web.dir";
// Constant to write Property file for web path
public static final String WEB_PATH = "web.path";
//Constant to write comment for build.properties
public static final String COMMENT = "This is a build.properties file";
Output of above code:
# This is a build.properties file
#Sun Sep 04 14:47:31 IST 2016
src.dir=src
build.dir=build
web.dir=WebContent
app.name=OnlineDoctor
web.path=${web.dir}/WEB-INF
Property to XML File
public class PropertyToXML {
private static final String INSTITIUTE = "SLIIT";
private static final String NAME = "Udara";
private static final String MODULE = "MTIT";
private static final String YEAR = "4th Year";
private static final String FIELD = "SE";
private static final String COMMENT = "This is a XML file generated through properties";
private static final String PROPERTY_FILE_NAME = "Properties.xml";
/**
* Create property file to store Properties.xml configurations
*/
public static void createProperty() {
try {
Properties properties = new Properties();
properties.setProperty("INSTITIUTE", INSTITIUTE);
properties.setProperty("NAME", NAME);
properties.setProperty("MODULE", MODULE);
properties.setProperty("YEAR", YEAR);
properties.setProperty("FIELD", FIELD);
properties.storeToXML(new FileOutputStream(PROPERTY_FILE_NAME),
COMMENT);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
createProperty();
}
}
Output of above code:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>This is a XML file generated through properties</comment>
<entry key="MODULE">MTIT</entry>
<entry key="INSTITIUTE">SLIIT</entry>
<entry key="NAME">Udara</entry>
<entry key="FIELD">SE</entry>
<entry key="YEAR">4th Year</entry>
</properties>
Pass parameters for Property file
- Use
java.text.MessageFormat - MessageFormat provides a means to produce concatenated messages in a language-neutral way.
- String
java.text.MessageFormat.format(String pattern, Object... arguments) - Pass any number of arguments for the property file using MessageFormat and pass the String Pattern with specifying indexes in curly braces to display passed parameters. Eg:- {0},{1}, {2}…etc
messageFormat Example
Configuration.properties:
message=Error code is {0}. And Error message is {1}
message2=My name is {0} and works in {1}. My subject is {2}.
Java code:
private static final String ERROR_CODE = "4008";
private static final String ERROR_MESSAGE = "Custom Error Message";
private static final String MESSAGE_KEY = "message";
private static final String MESSAGE_KEY_2 = "message2";
private static final String NAME = "Udara";
private static final String PLACE = "SLIIT";
private static final String SUBJECT = "MTIT";
private static final String PROPERTY_FILE = "configuration.properties";
private static Properties properties = null;
static{
properties = new Properties();
try {
properties.load(PropertyParam.class.getResourceAsStream(PROPERTY_FILE));
} catch (IOException e) {
e.printStackTrace();
}
}
String ErrorMsg = MessageFormat.format((String)properties.get(MESSAGE_KEY), ERROR_CODE, ERROR_MESSAGE);
System.out.println(ErrorMsg);
String MyDetailsMsg = MessageFormat.format((String)properties.get(MESSAGE_KEY_2), NAME, PLACE, SUBJECT);
System.out.println(MyDetailsMsg);
Response:
Error code is 4008. And Error message is Custom Error Message
My name is Udara and works in SLIIT. My subject is MTIT.
Embed Queries into XML
Example (BiharGlassQuery.xml):
<?xml version="1.0" encoding="UTF-8"?>
<!--
BiharGlass HQL queries
-->
<Querys>
<!-- Select all customers Query -->
<query id="c1">
<![CDATA[
select customer from Customer as customer
]]>
</query>
<!-- Select a particular customer Query -->
<query id="c2">
<![CDATA[
from Customer as customer where customer.customerId = ?
]]>
</query>
<!-- Select all customer orders Query -->
<query id="co1">
<![CDATA[
select orders from CustomerOrder as orders
]]>
</query>
<!-- Select a particular customer order Query -->
<query id="co2">
<![CDATA[
from CustomerOrder as orders where orders.customerOrderId = ?
]]>
</query>
<!-- Get all material line demand query -->
<query id="ds1">
<![CDATA[
select sum(li.materialQuantity)
from ManufacturingOrderLine as li
where li.status = ? and li.material. materialId = ?
group by li.material.materialId
]]>
</query>
<!-- Get all remaining quantity of inventory query -->
<query id="ds2">
<![CDATA[
select sum(i. remainingQty)
from Inventory as i
where i.materialId = ?
group by i.materialId
]]>
</query>
<!-- Select allocated quantity from inventory Query -->
<query id="in2">
<![CDATA[
select inventory.receivedQuantity from Inventory as inventory where inventory.lotNumber = ?
]]>
</query>
<!-- Select list of items Lot wise Query -->
<query id="in3">
<![CDATA[
select inventory from Inventory as inventory
]]>
</query>
<!-- Select list of elements in item wise Query -->
<query id="in4">
<![CDATA[
select new List (inventory.materialId, sum(inventory.received Quantity), inventory.remainingQty,
sum(inventory.allocated Quantity), inventory.receiptDate, inventory.allocatable, inventory.referenceOrderId)
from Inventory as inventory group by inventory.materialId
]]>
</query>
<!-- Get item by ID Query -->
<query id="in5">
<![CDATA[
select inventory from Inventory as inventory where inventory.lotNumber = ?
]]>
</query>
</Querys>
Read Elements in XML query
public class QueryUtil {
/*
* This method read the SPARQLQuery.xml file and retrieve the query by query id.
*/
public static String queryByID(String id)
{
NodeList nodeList;
Element element = null;
try
{
nodeList = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(new File(System.getProperty("catalina.base") + OntologyConstant.SPARQL_FILE))
.getElementsByTagName("query");
for (int x = 0; x < nodeList.getLength(); x++) {
element = (Element) nodeList.item(x);
if(element.getAttribute("id").equals(id)) break;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return element.getTextContent();
}
}
Another Example
<Querys>
<!-- Create table employee Query -->
<query id="create_employee_table">
<![CDATA[
CREATE TABLE employees (
EmployeeID varchar(10) not null,
Fullname varchar(25),
Address
varchar(50),
Faculty varchar(20),
Department varchar(25),
Designation varchar(20),
primary key (EmployeeID)
)
]]>
</query>
<!-- DROP TABLE EMPLOYEES Query -->
<query id="drop_table">
<![CDATA[
DROP TABLE IF EXISTS employees
]]>
</query>
<! Select a particular employee by id Query -->
<query id="employee_by_id">
<![CDATA[
select * from employees where employees. EmployeeID = ?
]]>
</query>
</Querys>
Usage
preparedStatement = connection.prepareStatement (QueryUtil.queryByID(CommonConstants.QUERY_ID_GET_EMPLOYEE));
preparedStatement.setString (CommonConstants.COLUMN_INDEX_ONE, employeeID);
Inject Parameter to XML file
RestPostRequests.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!-- JSON file -->
<Requests>
<request id="createUser">
<![CDATA[
{
"user":
{
"name": "Udara Samaratunge",
"email": "%1$s"
}
}
]]>
</request>
</Request>
RequestUtil.java:
public class RequestUtil {
private static final String REQUEST_FILE_PATH = "src/RestPostRequests.xml";
private static final String REQUEST = "request";
private static final String ID = "id";
/**
* This method read the RestPostRequests.xml file and retrieve the query by
* query id.
*
* @param type
* @return
*/
public static String requestByID(String id) {
NodeList nodeList;
Element element = null;
try {
nodeList = DocumentBuilderFactory.newInstance().newDocumentBuilder()
.parse(new File(REQUEST_FILE_PATH)).getElementsByTagName(REQUEST);
for (int x = 0; x < nodeList.getLength(); x++) {
element = (Element) nodeList.item(x);
if (element.getAttribute(ID).equals(id))
break;
}
} catch (Exception ex) {
ex.printStackTrace();
}
return element.getTextContent();
}
}
Code:
private static final String CREATE_USER = "createUser";
private static final String EMAIL = "udara.s@sliit.lk";
/**
* Add parameter to XML file
*/
private static void addParamToXML() {
System.out.println("=============Before==============");
System.out.println(RequestUtil.requestByID(CREATE_USER).trim());
System.out.println("=============After==============");
String message = String.format(RequestUtil.requestByID(CREATE_USER), EMAIL).trim();
System.out.println(message);
}
Response:
=============Before==============
{
"user":
{
"name": "Udara Samaratunge",
"email": "%1$s"
}
}
=============After==============
{
"user":
{
"name": "Udara Samaratunge",
"email": "udara.s@sliit.lk"
}
}
Generate XML file
private static void buildXML() throws Exception {
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder().newDocument();
Element rootElement = doc.createElement("cars");
doc.appendChild(rootElement);
Element supercar = doc.createElement("supercars");
rootElement.appendChild(supercar);
// setting attribute to element
Attr attr = doc.createAttribute("company");
attr.setValue("Ferrari");
supercar.setAttributeNode(attr);
// carname element
Element carname = doc.createElement("carname");
Attr attrType = doc.createAttribute("type");
attrType.setValue("formula one");
carname.setAttributeNode(attrType);
carname.appendChild(doc.createTextNode("Ferrari 101"));
supercar.appendChild(carname);
Element carname1 = doc.createElement("carname");
Attr attrType1 = doc.createAttribute("type");
attrType1.setValue("sports");
carname1.setAttributeNode(attrType1);
carname1.appendChild(doc.createTextNode("Ferrari 202"));
supercar.appendChild(carname1);
// write the content into xml file
Transformer transformer = TransformerFactory.newInstance().newTransformer();
DOMSource source = new DOMSource(doc);
transformer.transform(source, new StreamResult(new File("cars.xml")));
transformer.transform(source, new StreamResult(System.out));
}
Response
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<cars>
<supercars company="Ferrari">
<carname type="formula one">Ferrari 101</carname>
<carname type="sports">Ferrari 202</carname>
</supercars>
</cars>
Separation of Logic and refactor considering cohesion and coupling
Problem: Logics were not separated. Cohesiveness of the method
Identify Logics to be separated
- Create XML document builder
- Create Element
- Add name to element
- Create Attributes
- Add attributes to Element
- Transform response to XML
Separation of Logics
- Create XML instance
- Create Elements
- Create Attributes
- Add name to element
- Add attributes to Element
- Transform response to XML
- Build XML file invoking implemented methods and append child elements accordingly
Usage of Generics
Implementation of Generic templates is good practice.
Bad Practice
Generic template NOT USED properly
```java
public class AdminPermissionrequestDBDriver extends DBDriverBase
Session session = SessionFactoryUtil.getSessionFactory().openSession();
/*** Add new Permissions to the Database
- @param rpobj is a RolePermission type object that contains data about new permission
- @return a boolean value. Returns true if new permission inserted successfully else r
*/
public boolean inser PermissionRequest (AdminPermission request rpObj) {
Transaction tx = null;
try{
tx = se ion.beginTransaction();
session.se (rpobj);
tx.commit();
return true;
}catch(RuntimeException ){
if(tx != null &isActive())
{
try{
tx.ro back();
}catch
- @return a boolean value. Returns true if new permission inserted successfully else r