Monday, 29 July 2019

Gogo shel commands

Gogo shell is available inside of the OSGi Container.
Gogo shell commands :
1. lb (to see list of bundles)
2. start <<bundle-id>>
3. stop <<bundle-id>>
4. headers <<bundle-id>>

OSGi Basics

OSGi is specification and set of standards to develop Java based modular applications.

1. OSGi Framework : It is runtime (OSGi Container) & development environment.
2. Bundle : Basic unit to deploy into the OSGi container. It is a JAR file which contains executable code and OSGi headers in its MANIFEST.MF file.

Bundle = MANIFEST.MF + Java classes + Resources.

             a. Symantic versioning : Major . Minor . Micro - Qualifier (3.0.0-BETA).
             Eg. [1.2, 3.0) (means version 1.2 onwards and upto 3.0 not included 3.0 version)

             b. Bundle lifecycle managed by BundleActivator.

             States are :
                 1. installed (after added into the container), 2. Resolved (all imported dependencies are resolved ), 3. Starting, 4. Active, 5. Stopping, 6. Unistalling.


3. Component : It is an object (java class) which has set of functionalities. It is managed by component framework.
             Component Lifecycle : 1. active, 2. activated. 3. deactivated
4. Service : It is a component registered to OSGi Container 'service registry'.
                   Implements an interface and referenced by its interface in the OSGi Container.

Saturday, 1 December 2018

XML Processing via Java - JAXB

Unmarshal is a process reading from XML to Java
Marshal is a process writing into XML from Java

image.png

Wednesday, 4 July 2018

GenericDaoImpl


@Repository

@Transactional(readOnly = true)

@SuppressWarnings({ "unchecked", "serial" })

public abstract class GenericDaoImpl<E, ID extends Serializable> extends

HibernateTemplate implements GenericDao<E, ID> {

protected Class<E> entityClass;
public GenericDaoImpl() {

setEntityClass(); 

}

public E findById(ID id, boolean lock) {

return (E) super.get(entityClass, id);

}

public E findById(ID id) {

return findById(id, false);

}

public List<E> findAll() throws Exception {

return this.loadAll(entityClass);

}

public List<E> findByCriteria(DetachedCriteria criteria, int startIndex,

int maxResults) {

return (List<E>) super.findByCriteria(criteria, startIndex, maxResults);

}

@Autowired

@Qualifier("hibernateSessionFactory")

public void setSessionFactory(SessionFactory hibernateSessionFactory) {

super.setSessionFactory(hibernateSessionFactory);



}

protected void setEntityClass() {

entityClass = (Class<E>) ((ParameterizedType) getClass()

.getGenericSuperclass()).getActualTypeArguments()[0];

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public E makePersistent(E entity) {

this.checkWriteOperationAllowed(getSession());

this.saveOrUpdate(entity);

return entity;

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public void deleteEntity(E entity) {

this.checkWriteOperationAllowed(getSession());

this.delete(entity);

}



@Transactional(readOnly = false, propagation = Propagation.REQUIRED)

public void deleteAllEntities(Collection<E> entities) {



for (E entity : entities) {

this.checkWriteOperationAllowed(getSession());

this.delete(entity);

}

}

@Override

public Session getSession() {
Session session = getSessionFactory().getCurrentSession();

session.setFlushMode(FlushMode.COMMIT);

return session;

}

}

Session factory configuration in spring

<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">

<property name="jndiName" value="jdbc/TEST" />

</bean>



<bean id="hibernateSessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">

<property name="dataSource" ref="dataSource"></property>

<property name="packagesToScan" value="com.test.model"></property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>

<prop key="hibernate.show_sql">false</prop>

<prop key="hibernate.bytecode.use_reflection_optimizer">false</prop>

<prop key="hibernate.search.autoregister_listeners">false</prop>

<prop key="hibernate.connection.release_mode">after_transaction</prop>

<prop key="hibernate.transaction.auto_close_session">false</prop>

</props>

</property>

</bean>




<bean id="transactionManager"

class="org.springframework.orm.hibernate5.HibernateTransactionManager">

<property name="sessionFactory" ref="hibernateSessionFactory"></property>

</bean>




<tx:annotation-driven transaction-manager="transactionManager"/>

Model listener

Model listeners were designed to perform lightweight actions in response to a create, remove, or update attempt on an entity’s database table or a mapping table

Model listeners are not called when fetching records from the database

Monday, 3 July 2017

import data from file to mongodb collection

import data from file to mongodb collection :