Posts

Showing posts from August, 2020

Calling template function within template class, with template return type || assigning template type during function call

In c++, you have to determine which type of data T holds during compile time otherwise. It will throw,  template argument deduction/substitution failed:                              couldn't deduce template parameter 'E' ADS_set<size_t> a; a.w<size_t>();           // This way size_t will be reside in the template

SpringMVC

Image
 For creating spring MVC there are five steps: 1) Configure the dispatcher servlet in the web.xml < servlet > < servlet-name >spring</ servlet-name > < servlet-class >org.springframework.web.servlet.DispatcherServlet</ servlet-class > </ servlet > < servlet-mapping > < servlet-name >spring</ servlet-name > < url-pattern >/</ url-pattern > </ servlet-mapping > 2) Create spring configuration file e.g spring-servlet.xml         --The starting name of spring configuration file should be same as servlet-name above: spring              and the servlet behind. 3) Configure view resolver, it will be declare as bean inside spring configuration file. < bean class ="org.springframework.web.servlet.view.InternalResourceViewResolver" name ="viewResolver" > < property name ="prefix" value ="/WEB-INF/views/" /> < property name ="suffix" value =&quo

Intro SpringORM

Image
  ProductDao required HibernateTemplate object HibernateTemplate need SessionFactor object through LocalSessionFactorBean LocalSessionFactoryBean need dataSource, HibernateProperties, AnnotatedClass ProductDAO required HibernateTemplate .  HibernateTemplate has all the method required for CRUD operation. HibernateTemplate r equire SessionFactory. Since SessionFactory interface we have to give LocalSessionFactoryBean.  LocalSessionFactorBean require DataSource, HibernateProperties, AnnotatedClass. Dependencies are springorm, mysql-connector-java, hibernate @Transcational should be used before a method with has write operation and configure HibernateTranscationManager in xml like below. This is how it is set <? xml version ="1.0" encoding ="UTF-8" ?> < beans xmlns ="http://www.springframework.org/schema/beans" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx ="http://www.springframework.org/schema/

create company database

  CREATE TABLE employee ( emp_id int primary key , first_name varchar ( 40 ), last_name varchar ( 40 ), birth_day DATE , sex VARCHAR ( 1 ), salary INT , super_id INT , branch_id INT ); CREATE TABLE branch ( branch_id INT PRIMARY KEY , branch_name VARCHAR ( 40 ), mgr_id INT , mgr_start_date DATE , FOREIGN KEY ( mgr_id ) REFERENCES employee ( emp_id ) ON DELETE SET NULL ); ALTER TABLE employee ADD FOREIGN KEY ( branch_id ) REFERENCES branch ( branch_id ) ON DELETE SET NULL ; ALTER TABLE employee ADD FOREIGN KEY ( super_id ) REFERENCES employee ( emp_id ) ON DELETE SET NULL ; CREATE TABLE client ( client_id INT PRIMARY KEY , client_name VARCHAR ( 40 ), branch_id INT , FOREIGN KEY ( branch_id ) REFERENCES branch ( branch_id ) ON DELETE SET NULL ); CREATE TABLE works_with ( emp_id INT , client_id INT , total_sales INT , PRIMARY KEY ( emp_id , client_id ), FOREIGN KEY ( emp_id ) REFERENCES employee ( emp_

std::function

Simple example of using std::function  #include <functional> #include <iostream> int sum ( int x , int y , int z ){ return x + y ; } int check ( std :: function < int ( int , int , int )> & s , int x , int y ){ return s ( x , y ); } int main (){ std :: function < int ( int , int , int )> s ( sum ); std :: cout << check ( s , 10 , 20 ) << std :: endl ;     // Here a datatype of std::function is define and passed to check,    // which returns int and takes     // three argument int, int, int types } To Create a std::function with template example: template < class E > bool h ( const E & par1 ){ std :: cout << "This is correct" ; return true ; } template < class E > E z ( std :: function < bool ( const E &)> F ){ } int main (){ std :: function < bool ( const int &)> v ( h < int >); std :: cout << v ( 10 ) ; }

Intro jdbc project

For using SpringJDBC, we have two class a) JdbcTemplate b)DriverManagerDataSource In DriverManagerDataSource, we have to give the property of url, drivername, username and password and create a bean with it. We inject the bean of DriverManagerDataSource to JdbcTemplate. We have all the method in JbbcTemplate for creating, inserting  deleting in database. update() -> is used for insert, update, delete execute() -> select It is inserted like this: String query = "insert into student(name, address) values ( ? , ? )" ; int result = jdbcTemplate . update ( query , s . getName (), s . getAddress ()); Updating and deleting is same as inserting but with different query. public int update ( Student s ) { String query = "UPDATE student SET name= ? , address= ? WHERE id= ? " ; int result = jdbcTemplate . update ( query , s . getName (), s . getAddress (), s . getId ()); return result ; } public int delete ( int studentId ) { String query = "DELETE

@Configuration, Removing the xml configuration

Beans can be created in three ways 1) using xml configuration 2) using @Component 3) using @Bean When using @Component, component should be scan in either xml or in configuration java class . To remove xml file and create  bean from java class: @Configuration is used in one java class @ComponentScan is used to scan packages, when @Component is used to create bean other wise not required this. To declare the context with java class: ApplicationContext context = new AnnotationConfigApplicationContext(javaConfig.class); @Bean({"name1", "name2"}) public Student getStudent() { return new Student(); } Bean can be given any name. The default name is getStudent for this bean.

SpEL

  SpelExpressionParser spelExpressionParser = new SpelExpressionParser (); Expression expression = spelExpressionParser.parseExpression("22+44"); System.out.println(expression.getValue()); It can be used like that, In @Value("#{give the expression}") Expression language is used with classes, variables, methods, constructors, and objects As well as with char, numeric, operators, keywords and special symbols which returns a value                                         To Call Static Method and Variable inside expression language T(Class).method(param), T(class).variable class should be full class path e.g  T( java.lang.Math ). sqrt (25); T(java.lang.Math).E                             To Create Objects new Object(value) e.g:    @Value ( "#{new java.lang.String ('H')}" )                                  Boolean Type in SpEL @Value("#{8>2}")

Bean scope

it's of five type: a)singleton b)prototype c)session d)requests e)global session -> singleton is by default. so the hash code of all singleton object will be same.     it can be changed in two ways:      1)In config file:  <bean class ="" name="" scope=""/>      2)Under @Component                    @Scope("")    scope is only used with component. -> prototype: every time new object is give and has different hash code

Stereotype Annotation(@value, @component)

@Component, @Value @Component is use to declare object of class like bean declaration, and bean name can specify in @Component("here"). Base class should be specify through context: <context:component-scan base-package="com."/> IoC will scan the base package and its sub package as well. @Value is used to give the value directly. For eg: For Collection, declare in xml file with util and use id #{id} inside @Value("#{id}") @Component public class Student { @Value ( "H" ) private String studentName ; @Value("Ktm") private String city; @Value("#{temp}") private List<String> address; }

Using standalone collection in xml

To use standalone collection use xmlns:util ="http://www.springframework.org/schema/util" along with its schema location:   http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd After this simply use in .xml file like this:   < util :list list-class ="java.util.LinkedList" id ="myBestFriends" > < value >Tore</ value > < value >Amrit</ value > < value >Arun</ value > </ util :list > < bean class ="com.mountech.collection.Person" name ="person" > < property name ="friends" > < ref bean ="myBestFriends" /> </ property > </ bean >

Auto wiring introduction with xml and annotation

-> it is used to inject dependencies automatically -> it can't be used to inject primitive and string values, it works with reference only. It can be done by two ways: 1)XML 2)ANNOTATION With XML:     Autowiring can be done in           a)byName          b)byType          c)constructor          d)autodetect- -It is deprecated since spring 3 With Annotations:         a)Autowired          b)Qualifier                                  Autowiring  of Bean in xml  Object can be decleared in two ways: This two are same: Either cast the bean or give the bean class: Emp  emp  =  context . getBean ( "emp" ,  Emp . class ); Emp emp = (Emp)context.getBean("emp); "When using byName" When giving the Autowired property to reference variable class. The bean name and the object name should be similar e.g private Address address ; <bean class="some class" name=" address "/>  This both address should be same. it will not give error, but gives

Spring injection using setter and constructor, use inti and destroy method in bean

Whenever a single bean object is created in a this config file, all of the beans declared in this file will be created. Using setter-------------------   <bean class="" name="" init-method="" destroy-method="">      <properties name="">          <value>            //give value here          </value>     </properties> </bean> or <bean class="" name="" init-method="" destroy-method="">     <properties name="" value="">     </properties> </bean> or <bean class="" name="" p:nameOfVariable="" init-method="" destroy-method=""/>          //this is using p schema Using constructor  Using setter-------------------  <bean class="" name="" init-method="" destroy-method="">     <constructor-args name="">         &l

Dash to dock setting installation

1) Search for gnome dash dock extension in google. https://extensions.gnome.org/extension/307/dash-to-dock/   Go to this link and turn it on , then it ll be downloaded. Go to tweak and turn on dash to dock setting . I am ready to go.

Barrier not working on opensuse and fedora.

   D isabling wayland in /etc/gdm/custom.conf then relogin. https://github.com/debauchee/barrier/issues/479

Problem of pop os for forgetting password, changing graphics driver to nvidia

 Press space continuously on booting to get window for recovery, Go to recovery, And to change password go to this link https://support.system76.com/articles/password-pop/?fbclid=IwAR2er2n_lpo2ErOoaN6ZF1HCW1dr-vFOz5WeM9FgDunwMTCRMN-9LnGVlrI To go to terminal without recovery, Press current pop os , then esc , then ctrl + alt +f5. Enter user name and password. Install graphics for desktop and file system, sudo apt-get install --reinstall ubuntu-desktop Search for file system installation command in google and enter.