Hibernate ORM EntityPersister - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Hibernate ORM EntityPersister class.

This code example shows how to use the following methods:getEntityName, getFactory, isVersioned, getRootTableIdentifierColumnNames, getRootTableName
		registerColumnType( Types.CHAR, "char(1)" );
		registerColumnType( Types.VARCHAR, "varchar($l)" );
		registerColumnType( Types.FLOAT, "float" );
		registerColumnType( Types.DOUBLE, "double precision" );
		registerColumnType( Types.DATE, "date" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "timestamp" );
		//the BLOB type requires a size arguement - this defaults to 
		//bytes - no arg defaults to 1 whole byte! 
		//other argument mods include K - kilobyte, M - megabyte, G - gigabyte. 
		//refer to the PBdevelopers guide for more info. 
		registerColumnType( Types.VARBINARY, "blob($l)" );
		registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
	} 
 
	public String getAddColumnString() {
		return "add"; 
	} 
 
	public boolean dropConstraints() { 

8
CodeRank
This code example shows how to use the following methods:getEntityName, getFactory, isVersioned, getRootTableIdentifierColumnNames, getRootTableName
public class FrontBaseDialect extends Dialect {
 
	public FrontBaseDialect() { 
		super(); 
 
		registerColumnType( Types.BIT, "bit" );
		registerColumnType( Types.BIGINT, "longint" );
		registerColumnType( Types.SMALLINT, "smallint" );
		registerColumnType( Types.TINYINT, "tinyint" );
		registerColumnType( Types.INTEGER, "integer" );
		registerColumnType( Types.CHAR, "char(1)" );
		registerColumnType( Types.VARCHAR, "varchar($l)" );
		registerColumnType( Types.FLOAT, "float" );
		registerColumnType( Types.DOUBLE, "double precision" );
		registerColumnType( Types.DATE, "date" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "timestamp" );
		registerColumnType( Types.VARBINARY, "bit varying($l)" );
		registerColumnType( Types.NUMERIC, "numeric($p,$s)" );
		registerColumnType( Types.BLOB, "blob" );

8
CodeRank
This code example shows how to use the following methods:getEntityName, getFactory, isVersioned, getRootTableIdentifierColumnNames, getRootTableName
		registerColumnType( Types.SMALLINT, "smallint" );
		registerColumnType( Types.TINYINT, "tinyint" );
		registerColumnType( Types.INTEGER, "integer" );
		registerColumnType( Types.CHAR, "char(1)" );
		registerColumnType( Types.VARCHAR, "varchar($l)" );
		registerColumnType( Types.FLOAT, "float" );
		registerColumnType( Types.DOUBLE, "double" );
		registerColumnType( Types.DATE, "date" );
		registerColumnType( Types.TIME, "time" );
		registerColumnType( Types.TIMESTAMP, "timestamp" );
		registerColumnType( Types.VARBINARY, "varbinary" );
		registerColumnType( Types.NUMERIC, "numeric" );
		registerColumnType( Types.BLOB, "blob" );
		registerColumnType( Types.CLOB, "clob" );
 
		registerFunction( "upper", new StandardSQLFunction("upper") );
		registerFunction( "lower", new StandardSQLFunction("lower") );
		registerFunction( "sqrt", new StandardSQLFunction("sqrt", StandardBasicTypes.DOUBLE) );
		registerFunction( "abs", new StandardSQLFunction("abs") );
		registerFunction( "sign", new StandardSQLFunction( "sign", StandardBasicTypes.INTEGER ) );

8
CodeRank
This code example shows how to use the following methods:getEntityName, isVersioned
		} 
	} 
 
	/** 
	 * @see LockingStrategy#lock 
	 */ 
	public void lock( 
			Serializable id,
			Object version, 
			Object object, 
			int timeout, SessionImplementor session) throws StaleObjectStateException, JDBCException {
		if ( !lockable.isVersioned() ) {
			throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
		} 
		EntityEntry entry = session.getPersistenceContext().getEntry( object );
		EntityIncrementVersionProcess incrementVersion = new EntityIncrementVersionProcess( object, entry );
		EventSource source = (EventSource) session;
		// Register the EntityIncrementVersionProcess action to run just prior to transaction commit.  
		source.getActionQueue().registerProcess( incrementVersion );
	} 
7
CodeRank
This code example shows how to use the following methods:getEntityName, getFactory, isVersioned, getRootTableIdentifierColumnNames, getRootTableName
 * No CLOB/BLOB support  
 * No cascade delete support. 
 * No Calendar support 
 * No support for updating primary keys. 
 *  
 * @author Sherry Listgarten and Max Andersen 
 */ 
public class TimesTenDialect extends Dialect {
	 
	public TimesTenDialect() { 
		super(); 
		registerColumnType( Types.BIT, "TINYINT" );
		registerColumnType( Types.BIGINT, "BIGINT" );
		registerColumnType( Types.SMALLINT, "SMALLINT" );
		registerColumnType( Types.TINYINT, "TINYINT" );
		registerColumnType( Types.INTEGER, "INTEGER" );
		registerColumnType( Types.CHAR, "CHAR(1)" );
		registerColumnType( Types.VARCHAR, "VARCHAR($l)" );
		registerColumnType( Types.FLOAT, "FLOAT" );
		registerColumnType( Types.DOUBLE, "DOUBLE" );

8
CodeRank
This code example shows how to use the following methods:getEntityName, isVersioned
			throw new HibernateException( "[" + lockMode + "] not valid for [" + lockable.getEntityName() + "]" );
		} 
	} 
 
   /** 
	 * @see org.hibernate.dialect.lock.LockingStrategy#lock 
	 */ 
	public void lock( 
      Serializable id,
      Object version, 
      Object object, 
      int timeout, SessionImplementor session) throws StaleObjectStateException, JDBCException {
		if ( !lockable.isVersioned() ) {
			throw new OptimisticLockException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
		} 
		EntityEntry entry = session.getPersistenceContext().getEntry(object);
		EventSource source = (EventSource)session;
		EntityVerifyVersionProcess verifyVersion = new EntityVerifyVersionProcess(object, entry);
		// Register the EntityVerifyVersionProcess action to run just prior to transaction commit. 
		source.getActionQueue().registerProcess(verifyVersion);
7
CodeRank
This code example shows how to use the following methods:getEntityName, isVersioned
		} 
	} 
 
	/** 
	 * {@inheritDoc} 
	 */ 
	public void lock( 
			Serializable id,
			Object version, 
			Object object, 
			int timeout,
			SessionImplementor session) throws StaleObjectStateException, JDBCException {
		if ( !lockable.isVersioned() ) {
			throw new HibernateException( "[" + lockMode + "] not supported for non-versioned entities [" + lockable.getEntityName() + "]" );
		} 
		EntityEntry entry = session.getPersistenceContext().getEntry( object );
		final EntityPersister persister = entry.getPersister();
		Object nextVersion = persister.forceVersionIncrement( entry.getId(), entry.getVersion(), session );
		entry.forceLocked( object, nextVersion );
	} 
7
CodeRank
This code example shows how to use the following methods:getEntityName, getFactory, isVersioned, getRootTableIdentifierColumnNames, getRootTableName
 * 1.1 
 * 1.0  2005-10-24  CDH - First dated version for use with CP 11 
 * 
 * @author Ploski and Hanson 
 */ 
public class RDMSOS2200Dialect extends Dialect { 
 
    private static final CoreMessageLogger LOG = Logger.getMessageLogger(CoreMessageLogger.class, RDMSOS2200Dialect.class.getName()); 
 
	public RDMSOS2200Dialect() { 
		super(); 
        // Display the dialect version. 
        LOG.rdmsOs2200Dialect(); 
 
        /** 
         * This section registers RDMS Biult-in Functions (BIFs) with Hibernate. 
         * The first parameter is the 'register' function name with Hibernate. 
         * The second parameter is the defined RDMS SQL Function and it's 
         * characteristics. If StandardSQLFunction(...) is used, the RDMS BIF 
         * name and the return type (if any) is specified.  If 

8
CodeRank
This code example shows how to use the following methods:getPropertyValues, isMutable
This code example shows how to use the following methods:getFactory, getIdentifierPropertyName, getVersionProperty, isVersioned

6
CodeRank
This code example shows how to use the following methods:getIdentifier, isTransient

6
CodeRank
This code example shows how to use the following methods:getPropertyTypes, getPropertyValues
	 * @param persister 
	 * @throws HibernateException 
	 */ 
	void process(Object object, EntityPersister persister)
	throws HibernateException {
		processEntityPropertyValues( 
			persister.getPropertyValues( object ),
			persister.getPropertyTypes()
		); 
	} 
 
	/** 
	 * Visit a collection. Default superclass 
	 * implementation is a no-op. 
	 * @param collection 
	 * @param type 
	 * @throws HibernateException 
	 */ 
	Object processCollection(Object collection, CollectionType type)
	throws HibernateException {
6
CodeRank
This code example shows how to use the following methods:forceVersionIncrement, getVersionProperty, setPropertyValue
		); 
		entry.forceLocked( object, nextVersion );
	} 
} 

6
CodeRank
This code example shows how to use the following methods:getEntityName
	} 
 
	public EntityPersister getOwner() {
		return owner;
	} 
 
	public String getAssociationPath() {
		return associationPath;
	} 
 
	public String getRole() {
		return role;
	} 
} 
6
CodeRank
This code example shows how to use the following methods:getIdentifier, isTransient
	throws HibernateException {
		if ( object == null ) { 
			return null; 
		} 
		else { 
			Serializable id = session.getContextEntityIdentifier( object );
			if ( id == null ) {
				// context-entity-identifier returns null explicitly if the entity 
				// is not associated with the persistence context; so make some 
				// deeper checks... 
				if ( isTransient(entityName, object, Boolean.FALSE, session) ) {
					throw new TransientObjectException(
							"object references an unsaved transient instance - save the transient instance before flushing: " + 
							(entityName == null ? session.guessEntityName( object ) : entityName)
					); 
				} 
				id = session.getEntityPersister( entityName, object ).getIdentifier( object, session );
			} 
			return id;
		} 

6
CodeRank
This code example shows how to use the following methods:getEntityName
This code example shows how to use the following methods:getEntityName
This code example shows how to use the following methods:getIdentifier, isTransient
 
		if ( isNotEmbedded( session ) ) { 
			return id; 
		} 
		 
		if ( id == null ) { 
			return null; 
		} 
		else { 
			return resolveIdentifier( id, session ); 
		} 
	} 
 
	private Serializable assembleId(Serializable oid, SessionImplementor session) { 
		//the owner of the association is not the owner of the id 
		return ( Serializable ) getIdentifierType( session ).assemble( oid, session, null ); 
	} 
 
	public void beforeAssemble(Serializable oid, SessionImplementor session) { 
		scheduleBatchLoadIfNeeded( assembleId( oid, session ), session ); 

6
CodeRank
This code example shows how to use the following methods:getFactory, getIdentifierType, getRootEntityName
		this.entityName = entityName;
		this.identifierType = identifierType;
		this.isBatchLoadable = batchLoadable;
		this.factory = factory;
		this.tenantId = tenantId;
		this.hashCode = generateHashCode();
	} 
 
	private int generateHashCode() { 
		int result = 17;
		result = 37 * result + rootEntityName.hashCode();
		result = 37 * result + identifierType.getHashCode( identifier, factory );
		return result;
	} 
 
	public boolean isBatchLoadable() { 
		return isBatchLoadable;
	} 
 
	public Serializable getIdentifier() {
5
CodeRank
This code example shows how to use the following methods:implementsLifecycle
This code example shows how to use the following methods:getPropertyTypes, getPropertyValues, setPropertyValues
		return null; 
	} 
 
	@Override 
    void process(Object object, EntityPersister persister) throws HibernateException { 
		final Object[] values = persister.getPropertyValues( object ); 
		final Type[] types = persister.getPropertyTypes(); 
		processEntityPropertyValues( values, types ); 
		if ( isSubstitutionRequired() ) { 
			persister.setPropertyValues( object, values ); 
		} 
	} 
} 
5
CodeRank
This code example shows how to use the following methods:getEntityName
	 * @param id The id of the entity 
	 * @param instance The entity instance 
	 * @param persister The entity persister 
	 */ 
	protected EntityAction(SessionImplementor session, Serializable id, Object instance, EntityPersister persister) {
		this.entityName = persister.getEntityName();
		this.id = id;
		this.instance = instance;
		this.session = session;
		this.persister = persister;
	} 
 
	@Override 
	public BeforeTransactionCompletionProcess getBeforeTransactionCompletionProcess() {
		return null; 
	} 
 
	@Override 
	public AfterTransactionCompletionProcess getAfterTransactionCompletionProcess() {
		return needsAfterTransactionCompletion() 
6
CodeRank
This code example shows how to use the following methods:getVersionProperty, isVersioned
	 * 
	 * @param version The current version 
	 * @param versionType The version type 
	 * @param session The originating session 
	 * @return The incremented optimistic locking value. 
	 */ 
	public static Object increment(Object version, VersionType versionType, SessionImplementor session) { 
		Object next = versionType.next( version, session ); 
        if (LOG.isTraceEnabled()) LOG.trace("Incrementing: " + versionType.toLoggableString(version, session.getFactory()) + " to " 
                                            + versionType.toLoggableString(next, session.getFactory())); 
		return next; 
	} 
 
	/** 
	 * Inject the optimisitc locking value into the entity state snapshot. 
	 * 
	 * @param fields The state snapshot 
	 * @param version The optimisitc locking value 
	 * @param persister The entity persister 
	 */ 
5
CodeRank
This code example shows how to use the following methods:getIdentifierGenerator, getPropertyValues, getVersionProperty, getVersionType, isVersioned
		} 
		if ( id == IdentifierGeneratorHelper.POST_INSERT_INDICATOR ) { 
			id = persister.insert(state, entity, this); 
		} 
		else { 
			persister.insert(id, state, entity, this); 
		} 
		persister.setIdentifier( entity, id, this ); 
		return id; 
	} 
 
 
	// deletes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 
 
	public void delete(Object entity) { 
		errorIfClosed(); 
		delete(null, entity); 
	} 
 
	public void delete(String entityName, Object entity) { 

5
CodeRank
This code example shows how to use the following methods:isMutable
			} 
		} 
	} 
 
	private static EntityKey generateEntityKeyOrNull(Serializable id, SessionImplementor s, String entityName) {
		if ( id == null || s == null || entityName == null ) {
			return null; 
		} 
		return s.generateEntityKey( id, s.getFactory().getEntityPersister( entityName ) );
	} 
 
	@Override 
	public final void unsetSession() { 
		session = null;
		readOnly = false;
		readOnlyBeforeAttachedToSession = null;
	} 
 
	@Override 
	public final void initialize() throws HibernateException {
5
CodeRank
This code example shows how to use the following methods:implementsLifecycle
		finally { 
			session.getPersistenceContext().decrementCascadeLevel(); 
			session.setCacheMode( cacheMode ); 
		} 
	} 
 
	protected void cascadeAfterDelete( 
			EventSource session, 
			EntityPersister persister, 
			Object entity, 
			Set transientEntities) throws HibernateException { 
 
		CacheMode cacheMode = session.getCacheMode(); 
		session.setCacheMode( CacheMode.GET ); 
		session.getPersistenceContext().incrementCascadeLevel(); 
		try { 
			// cascade-delete to many-to-one AFTER the parent was deleted 
			new Cascade( CascadingAction.DELETE, Cascade.BEFORE_INSERT_AFTER_DELETE, session ) 
					.cascade( persister, entity, transientEntities ); 
		} 
5
CodeRank
This code example shows how to use the following methods:getEntityName
This code example shows how to use the following methods:getCurrentVersion, getEntityName
		if ( !entry.getVersion().equals( latestVersion ) ) {
			throw new OptimisticLockException(
					"Newer version [" + latestVersion + 
							"] of entity [" + MessageHelper.infoString( entry.getEntityName(), entry.getId() ) +
							"] found in database" 
			); 
		} 
	} 
} 

5
CodeRank
This code example shows how to use the following methods:getPropertyNames, getPropertyTypes
This code example shows how to use the following methods:getIdentifier, isTransient
	 * Two entities are considered the same when their instances are the same. 
	 * 
	 * 
	 * @param x One entity instance 
	 * @param y Another entity instance 
	 * @return True if x == y; false otherwise. 
	 */ 
	public final boolean isSame(Object x, Object y) { 
		return x == y; 
	} 
 
	/** 
	 * {@inheritDoc} 
	 */ 
	public int compare(Object x, Object y) { 
		return 0; //TODO: entities CAN be compared, by PK, fix this! -> only if/when we can extract the id values.... 
	} 
 
	/** 
	 * {@inheritDoc} 

5
CodeRank
See Code Examples for Hibernate ORM EntityPersister Methods: