CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-liferay-portal--com-liferay-portal-impl

Core implementation module containing the fundamental services, utilities, and infrastructure components for the Liferay Digital Experience Platform.

Pending
Overview
Eval results
Files

database-orm.mddocs/

Database & ORM Layer

Comprehensive Hibernate ORM integration providing custom types, property accessors, database dialects, dynamic query building, and multi-database support for the Liferay portal framework.

Capabilities

Session Management

Core Hibernate session management with portal-specific enhancements and optimizations.

/**
 * Hibernate SessionFactory wrapper with portal enhancements
 */
public class SessionFactoryImpl implements SessionFactory {
    
    /**
     * Opens a new Hibernate session
     * @return new Session instance
     */
    public Session openSession();
    
    /**
     * Gets the current session bound to the thread
     * @return current Session instance
     */
    public Session getCurrentSession();
    
    /**
     * Closes the SessionFactory and releases resources
     */
    public void close();
}

/**
 * Hibernate Session wrapper with portal-specific enhancements
 */
public class SessionImpl implements Session {
    
    /**
     * Creates a new Query for HQL execution
     * @param queryString the HQL query string
     * @return Query instance
     */
    public Query createQuery(String queryString);
    
    /**
     * Creates a new SQLQuery for native SQL execution
     * @param queryString the native SQL query string
     * @return SQLQuery instance
     */
    public SQLQuery createSQLQuery(String queryString);
    
    /**
     * Begins a new transaction
     * @return Transaction instance
     */
    public Transaction beginTransaction();
    
    /**
     * Saves or updates the given entity
     * @param entity the entity to save or update
     */
    public void saveOrUpdate(Object entity);
    
    /**
     * Deletes the given entity
     * @param entity the entity to delete
     */
    public void delete(Object entity);
}

Dynamic Query Framework

Flexible query building system enabling type-safe dynamic query construction at runtime.

/**
 * Factory for creating dynamic queries
 */
public class DynamicQueryFactoryImpl implements DynamicQueryFactory {
    
    /**
     * Creates a dynamic query for the specified class
     * @param clazz the entity class
     * @return DynamicQuery instance
     */
    public DynamicQuery forClass(Class<?> clazz);
    
    /**
     * Creates a dynamic query for the specified class with custom ClassLoader
     * @param clazz the entity class
     * @param classLoader the ClassLoader to use
     * @return DynamicQuery instance
     */
    public DynamicQuery forClass(Class<?> clazz, ClassLoader classLoader);
}

/**
 * Dynamic query builder implementation
 */
public class DynamicQueryImpl implements DynamicQuery {
    
    /**
     * Adds a criterion to the query
     * @param criterion the query criterion
     * @return this DynamicQuery for method chaining
     */
    public DynamicQuery add(Criterion criterion);
    
    /**
     * Adds an ordering to the query
     * @param order the ordering specification
     * @return this DynamicQuery for method chaining
     */
    public DynamicQuery addOrder(Order order);
    
    /**
     * Sets the maximum number of results
     * @param maxResults maximum results to return
     * @return this DynamicQuery for method chaining
     */
    public DynamicQuery setLimit(int start, int end);
    
    /**
     * Executes the query and returns results as a list
     * @return List of query results
     */
    public List<Object> list();
    
    /**
     * Executes the query and returns a single result
     * @return single query result or null
     */
    public Object uniqueResult();
}

Query Criteria and Restrictions

Query building components for constructing complex database queries with type safety.

/**
 * Query criterion implementation for building WHERE clauses
 */
public class CriterionImpl implements Criterion {
    // Implementation for individual query criteria
}

/**
 * Conjunction (AND) criteria combination
 */
public class ConjunctionImpl implements Criterion {
    
    /**
     * Adds a criterion to the AND conjunction
     * @param criterion the criterion to add
     * @return this Conjunction for method chaining
     */
    public Conjunction add(Criterion criterion);
}

/**
 * Disjunction (OR) criteria combination  
 */
public class DisjunctionImpl implements Criterion {
    
    /**
     * Adds a criterion to the OR disjunction
     * @param criterion the criterion to add
     * @return this Disjunction for method chaining
     */
    public Disjunction add(Criterion criterion);
}

/**
 * Factory for creating query ordering
 */
public class OrderFactoryImpl implements OrderFactory {
    
    /**
     * Creates ascending order for property
     * @param propertyName the property name
     * @return Order instance for ascending sort
     */
    public Order asc(String propertyName);
    
    /**
     * Creates descending order for property
     * @param propertyName the property name
     * @return Order instance for descending sort
     */
    public Order desc(String propertyName);
}

/**
 * Factory for creating query projections
 */
public class ProjectionFactoryImpl implements ProjectionFactory {
    
    /**
     * Creates count projection
     * @param propertyName the property to count
     * @return Projection for count operation
     */
    public Projection count(String propertyName);
    
    /**
     * Creates sum projection
     * @param propertyName the property to sum
     * @return Projection for sum operation
     */
    public Projection sum(String propertyName);
    
    /**
     * Creates property projection
     * @param propertyName the property to project
     * @return Projection for property selection
     */
    public Projection property(String propertyName);
}

/**
 * Factory for creating query restrictions
 */
public class RestrictionsFactoryImpl implements RestrictionsFactory {
    
    /**
     * Creates equality restriction
     * @param propertyName the property name
     * @param value the value to match
     * @return Criterion for equality check
     */
    public Criterion eq(String propertyName, Object value);
    
    /**
     * Creates inequality restriction
     * @param propertyName the property name
     * @param value the value to compare against
     * @return Criterion for inequality check
     */
    public Criterion ne(String propertyName, Object value);
    
    /**
     * Creates LIKE restriction for pattern matching
     * @param propertyName the property name
     * @param value the pattern to match
     * @return Criterion for LIKE operation
     */
    public Criterion like(String propertyName, String value);
    
    /**
     * Creates IN restriction for multiple values
     * @param propertyName the property name
     * @param values the collection of values
     * @return Criterion for IN operation
     */
    public Criterion in(String propertyName, Collection<?> values);
}

Database Dialect Support

Multi-database support through custom Hibernate dialects optimized for each database platform.

/**
 * IBM DB2 database dialect with enterprise optimizations
 */
public class DB2Dialect extends Dialect {
    // DB2-specific SQL generation and optimizations
}

/**
 * HSQL Database dialect for embedded database support
 */
public class HSQLDialect extends Dialect {
    // HSQL-specific SQL generation and in-memory optimizations
}

/**
 * MariaDB/MySQL dialect with MariaDB-specific optimizations
 */
public class MariaDBDialect extends Dialect {
    // MariaDB-specific SQL generation and performance optimizations
}

/**
 * Oracle 10g+ dialect with Oracle-specific features
 */
public class Oracle10gDialect extends Dialect {
    // Oracle-specific SQL generation and advanced features
}

/**
 * SQL Server 2005 dialect
 */
public class SQLServer2005Dialect extends Dialect {
    // SQL Server 2005-specific SQL generation
}

/**
 * SQL Server 2008+ dialect with enhanced features
 */
public class SQLServer2008Dialect extends Dialect {
    // SQL Server 2008+ specific SQL generation and features
}

Custom Hibernate Types

Portal-specific Hibernate type handlers for enhanced data type support and serialization.

/**
 * Boolean type handler with portal-specific logic
 */
public class BooleanType implements UserType {
    public int[] sqlTypes();
    public Class<?> returnedClass();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner);
    public void nullSafeSet(PreparedStatement st, Object value, int index);
}

/**
 * String type handler with portal enhancements
 */
public class StringType implements UserType {
    public int[] sqlTypes();
    public Class<?> returnedClass();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner);
    public void nullSafeSet(PreparedStatement st, Object value, int index);
}

/**
 * String CLOB type handler for large text fields
 */
public class StringClobType implements UserType {
    public int[] sqlTypes();
    public Class<?> returnedClass();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner);
    public void nullSafeSet(PreparedStatement st, Object value, int index);
}

/**
 * Map type handler for serialized Map storage
 */
public class MapType implements UserType {
    public int[] sqlTypes();
    public Class<?> returnedClass();
    public Object nullSafeGet(ResultSet rs, String[] names, Object owner);
    public void nullSafeSet(PreparedStatement st, Object value, int index);
}

Property Access Strategies

Flexible property access mechanisms supporting various field and method access patterns.

/**
 * Base property accessor strategy for Liferay entities
 */
public class LiferayPropertyAccessor implements PropertyAccessor {
    
    /**
     * Gets property value from entity
     * @param entity the target entity
     * @param propertyName the property name
     * @return property value
     */
    public Object get(Object entity, String propertyName);
    
    /**
     * Sets property value on entity
     * @param entity the target entity
     * @param propertyName the property name
     * @param value the value to set
     */
    public void set(Object entity, String propertyName, Object value);
}

/**
 * Camel case property accessor
 */
public class CamelCasePropertyAccessor extends LiferayPropertyAccessor {
    // Camel case property name handling
}

/**
 * Method-based property accessor using getter/setter methods
 */
public class MethodPropertyAccessor extends LiferayPropertyAccessor {
    // Method-based property access
}

/**
 * Private field property accessor using reflection
 */
public class PrivateFieldPropertyAccessor extends LiferayPropertyAccessor {
    // Direct private field access
}

/**
 * Public field property accessor
 */
public class PublicFieldPropertyAccessor extends LiferayPropertyAccessor {
    // Direct public field access
}

Usage Examples

Basic Session Operations:

SessionFactoryImpl sessionFactory = new SessionFactoryImpl();
SessionImpl session = (SessionImpl) sessionFactory.openSession();

try {
    Transaction tx = session.beginTransaction();
    
    // Save entity
    User user = new User();
    user.setName("John Doe");
    session.saveOrUpdate(user);
    
    // Query entities
    Query query = session.createQuery("FROM User WHERE active = :active");
    query.setParameter("active", true);
    List<User> users = query.list();
    
    tx.commit();
} finally {
    session.close();
}

Dynamic Query Building:

DynamicQueryFactoryImpl queryFactory = new DynamicQueryFactoryImpl();
RestrictionsFactoryImpl restrictions = new RestrictionsFactoryImpl();
OrderFactoryImpl orderFactory = new OrderFactoryImpl();

DynamicQuery query = queryFactory.forClass(User.class)
    .add(restrictions.eq("active", true))
    .add(restrictions.like("name", "John%"))
    .addOrder(orderFactory.asc("name"))
    .setLimit(0, 10);

List<Object> results = query.list();

Custom Type Usage:

// Custom types are automatically used by Hibernate when configured
// in mapping files or annotations
@Type(type = "com.liferay.portal.dao.orm.hibernate.StringClobType")
private String description;

@Type(type = "com.liferay.portal.dao.orm.hibernate.MapType")
private Map<String, Object> attributes;

Integration with Portal Framework

The database and ORM layer provides foundational data access for the entire portal:

  • Entity Management - All portal entities use this ORM layer
  • Service Layer Integration - Portal services build on these database capabilities
  • Transaction Management - Comprehensive transaction support for portal operations
  • Multi-tenant Support - Database isolation and partitioning capabilities
  • Performance Optimization - Database-specific optimizations and caching
  • Migration Support - Schema evolution and upgrade capabilities

Supported Databases

  • IBM DB2 - Enterprise database with advanced features and optimizations
  • HSQL Database - Embedded database for development, testing, and simple deployments
  • MariaDB/MySQL - Open source databases with MariaDB-specific enhancements
  • Oracle 10g+ - Enterprise Oracle database with version-specific features
  • Microsoft SQL Server 2005/2008+ - Microsoft database platforms with version compatibility

Error Handling

Common database-related exceptions and error scenarios:

  • HibernateException - General Hibernate ORM exceptions
  • DataAccessException - Data access layer exceptions
  • ConstraintViolationException - Database constraint violations
  • OptimisticLockingFailureException - Concurrent modification conflicts
  • ConnectionException - Database connectivity issues

Best practices include proper transaction management, connection pooling configuration, and comprehensive error logging for database operations.

Install with Tessl CLI

npx tessl i tessl/maven-com-liferay-portal--com-liferay-portal-impl

docs

bean-management.md

database-orm.md

database-upgrades.md

framework-integration.md

index.md

lifecycle-events.md

portlet-framework.md

service-layer.md

template-processing.md

utility-services.md

web-security.md

tile.json