org.hibernate.engine.OptimisticLockStyle Java Examples
The following examples show how to use
org.hibernate.engine.OptimisticLockStyle.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GrailsDomainBinder.java From gorm-hibernate5 with Apache License 2.0 | 5 votes |
protected void bindVersion(PersistentProperty version, RootClass entity, InFlightMetadataCollector mappings, String sessionFactoryBeanName) { if(version != null) { SimpleValue val = new SimpleValue(metadataBuildingContext, entity.getTable()); bindSimpleValue(version, null, val, EMPTY_PATH, mappings, sessionFactoryBeanName); if (val.isTypeSpecified()) { if (!(val.getType() instanceof IntegerType || val.getType() instanceof LongType || val.getType() instanceof TimestampType)) { LOG.warn("Invalid version class specified in " + version.getOwner().getName() + "; must be one of [int, Integer, long, Long, Timestamp, Date]. Not mapping the version."); return; } } else { val.setTypeName("version".equals(version.getName()) ? "integer" : "timestamp"); } Property prop = new Property(); prop.setValue(val); bindProperty(version, prop, mappings); prop.setLazy(false); val.setNullValue("undefined"); entity.setVersion(prop); entity.setDeclaredVersion(prop); entity.setOptimisticLockStyle(OptimisticLockStyle.VERSION); entity.addProperty(prop); } }
Example #2
Source File: EntityBinder.java From lams with GNU General Public License v2.0 | 5 votes |
OptimisticLockStyle getVersioning(OptimisticLockType type) { switch ( type ) { case VERSION: return OptimisticLockStyle.VERSION; case NONE: return OptimisticLockStyle.NONE; case DIRTY: return OptimisticLockStyle.DIRTY; case ALL: return OptimisticLockStyle.ALL; default: throw new AssertionFailure( "optimistic locking not supported: " + type ); } }
Example #3
Source File: HibernatePropertyParser.java From mPaaS with Apache License 2.0 | 5 votes |
/** * 构造Hibernate的乐观锁 */ private void handleVersion(Property prop, PersistentClass pclazz) { if (!(pclazz instanceof RootClass)) { throw new AnnotationException( "Unable to define/override @Version on a subclass: " + pclazz.getEntityName()); } RootClass root = (RootClass) pclazz; root.setVersion(prop); root.setDeclaredVersion(prop); root.setOptimisticLockStyle(OptimisticLockStyle.VERSION); }
Example #4
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
public boolean isBatchable() { return optimisticLockStyle() == OptimisticLockStyle.NONE || ( !isVersioned() && optimisticLockStyle() == OptimisticLockStyle.VERSION ) || getFactory().getSessionFactoryOptions().isJdbcBatchVersionedData(); }
Example #5
Source File: OptimisticLockStyleConverter.java From lams with GNU General Public License v2.0 | 4 votes |
public static String toXml(OptimisticLockStyle lockMode) { return lockMode == null ? null : lockMode.name().toLowerCase( Locale.ENGLISH ); }
Example #6
Source File: OptimisticLockStyleConverter.java From lams with GNU General Public License v2.0 | 4 votes |
public static OptimisticLockStyle fromXml(String name) { return OptimisticLockStyle.valueOf( name == null ? null : name.toUpperCase( Locale.ENGLISH ) ); }
Example #7
Source File: EntityHierarchySourceImpl.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public OptimisticLockStyle getOptimisticLockStyle() { return entityElement().getOptimisticLock(); }
Example #8
Source File: EntityMetamodel.java From lams with GNU General Public License v2.0 | 4 votes |
public OptimisticLockStyle getOptimisticLockStyle() { return optimisticLockStyle; }
Example #9
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
protected final OptimisticLockStyle optimisticLockStyle() { return entityMetamodel.getOptimisticLockStyle(); }
Example #10
Source File: AbstractEntityPersister.java From lams with GNU General Public License v2.0 | 4 votes |
private boolean isAllOrDirtyOptLocking() { return entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.DIRTY || entityMetamodel.getOptimisticLockStyle() == OptimisticLockStyle.ALL; }
Example #11
Source File: PersistentClass.java From lams with GNU General Public License v2.0 | 4 votes |
public void setOptimisticLockStyle(OptimisticLockStyle optimisticLockStyle) { this.optimisticLockStyle = optimisticLockStyle; }
Example #12
Source File: PersistentClass.java From lams with GNU General Public License v2.0 | 4 votes |
public OptimisticLockStyle getOptimisticLockStyle() { return optimisticLockStyle; }
Example #13
Source File: PersistentClass.java From lams with GNU General Public License v2.0 | 4 votes |
/** * @deprecated prefer {@link #setOptimisticLockStyle} */ @Deprecated public void setOptimisticLockMode(int optimisticLockMode) { setOptimisticLockStyle( OptimisticLockStyle.interpretOldCode( optimisticLockMode ) ); }
Example #14
Source File: Subclass.java From lams with GNU General Public License v2.0 | 4 votes |
@Override public OptimisticLockStyle getOptimisticLockStyle() { return superclass.getOptimisticLockStyle(); }
Example #15
Source File: ReactiveAbstractEntityPersister.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
default CompletionStage<Boolean> updateReactive( final Serializable id, final Object[] fields, final Object[] oldFields, final Object rowId, final boolean[] includeProperty, final int j, final Object oldVersion, final Object object, final String sql, final SharedSessionContractImplementor session) throws HibernateException { final Expectation expectation = appropriateExpectation( delegate().getUpdateResultCheckStyles()[j] ); // final int jdbcBatchSizeToUse = session.getConfiguredJdbcBatchSize(); // final boolean useBatch = expectation.canBeBatched() && isBatchable() && jdbcBatchSizeToUse > 1; // if ( useBatch && updateBatchKey == null ) { // updateBatchKey = new BasicBatchKey( // delegate.getEntityName() + "#UPDATE", // expectation // ); // } // final boolean callable = delegate.isUpdateCallable( j ); final boolean useVersion = j == 0 && delegate().isVersioned(); if ( log.isTraceEnabled() ) { log.tracev( "Updating entity: {0}", infoString(delegate(), id, delegate().getFactory() ) ); if ( useVersion ) { log.tracev( "Existing version: {0} -> New version:{1}", oldVersion, fields[delegate().getVersionProperty()] ); } } // if ( useBatch ) { // update = session // .getJdbcCoordinator() // .getBatch( updateBatchKey ) // .getBatchStatement( sql, callable ); // } Object[] params = PreparedStatementAdaptor.bind( update -> { int index = 1; index += expectation.prepare( update ); //Now write the values of fields onto the prepared statement index = delegate().dehydrate( id, fields, rowId, includeProperty, delegate().getPropertyColumnUpdateable(), j, update, session, index, true ); // Write any appropriate versioning conditional parameters if ( useVersion && delegate().getEntityMetamodel().getOptimisticLockStyle() == OptimisticLockStyle.VERSION ) { if ( delegate().checkVersion( includeProperty ) ) { delegate().getVersionType().nullSafeSet( update, oldVersion, index, session ); } } else if ( isAllOrDirtyOptimisticLocking() && oldFields != null ) { boolean[] versionability = delegate().getPropertyVersionability(); //TODO: is this really necessary???? boolean[] includeOldField = delegate().getEntityMetamodel().getOptimisticLockStyle() == OptimisticLockStyle.ALL ? delegate().getPropertyUpdateability() : includeProperty; Type[] types = delegate().getPropertyTypes(); for (int i = 0; i < delegate().getEntityMetamodel().getPropertySpan(); i++ ) { boolean include = includeOldField[i] && delegate().isPropertyOfTable( i, j ) && versionability[i]; //TODO: is this really necessary???? if ( include ) { boolean[] settable = types[i].toColumnNullness( oldFields[i], delegate().getFactory() ); types[i].nullSafeSet( update, oldFields[i], index, settable, session ); index += ArrayHelper.countTrue( settable ); } } } } ); // if ( useBatch ) { // session.getJdbcCoordinator().getBatch( updateBatchKey ).addToBatch(); // return true; // } return getReactiveConnection(session) .update( sql, params ) .thenApply( count -> check( count, id, j, expectation, new PreparedStatementAdaptor() ) ); }
Example #16
Source File: ReactiveAbstractEntityPersister.java From hibernate-reactive with GNU Lesser General Public License v2.1 | 4 votes |
default boolean isAllOrDirtyOptimisticLocking() { OptimisticLockStyle optimisticLockStyle = delegate().getEntityMetamodel().getOptimisticLockStyle(); return optimisticLockStyle == OptimisticLockStyle.DIRTY || optimisticLockStyle == OptimisticLockStyle.ALL; }
Example #17
Source File: EntityHierarchySource.java From lams with GNU General Public License v2.0 | 2 votes |
/** * Obtain the optimistic locking style for this entity. * * @return The optimistic locking style. */ public OptimisticLockStyle getOptimisticLockStyle();