javax.persistence.Version Java Examples
The following examples show how to use
javax.persistence.Version.
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: EntityUtils.java From deltaspike with Apache License 2.0 | 6 votes |
public static Property<Serializable> getVersionProperty(Class<?> entityClass) { List<PropertyCriteria> criteriaList = new LinkedList<PropertyCriteria>(); criteriaList.add(new AnnotatedPropertyCriteria(Version.class)); String fromMappingFiles = PersistenceUnitDescriptorProvider.getInstance().versionField(entityClass); if (fromMappingFiles != null) { criteriaList.add(new NamedPropertyCriteria(fromMappingFiles)); } for (PropertyCriteria criteria : criteriaList) { PropertyQuery<Serializable> query = PropertyQueries.<Serializable> createQuery(entityClass).addCriteria(criteria); Property<Serializable> result = query.getFirstResult(); if (result != null) { return result; } } return null; }
Example #2
Source File: HibernateMetadata.java From jstarcraft-core with Apache License 2.0 | 5 votes |
/** * 构造方法 * * @param metadata */ HibernateMetadata(Class<?> clazz) { ormClass = clazz; ormName = clazz.getName(); ReflectionUtility.doWithFields(ormClass, (field) -> { if (Modifier.isStatic(field.getModifiers()) || Modifier.isTransient(field.getModifiers())) { return; } if (field.isAnnotationPresent(Version.class)) { versionName = field.getName(); return; } Class<?> type = ClassUtility.primitiveToWrapper(field.getType()); if (String.class == type) { fields.put(field.getName(), type); } else if (type.isEnum()) { fields.put(field.getName(), type); } else if (Collection.class.isAssignableFrom(type) || type.isArray()) { fields.put(field.getName(), List.class); } else if (Date.class.isAssignableFrom(type)) { fields.put(field.getName(), Date.class); } else { fields.put(field.getName(), Map.class); } if (field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class)) { primaryName = field.getName(); primaryClass = type; } }); Table table = clazz.getAnnotation(Table.class); if (table != null) { for (Index index : table.indexes()) { indexNames.add(index.columnList()); } } }
Example #3
Source File: OptimisticLockingInterceptor.java From spring-content with Apache License 2.0 | 5 votes |
protected Object lock(Object entity) { if (em == null) { return entity; } if (BeanUtils.hasFieldWithAnnotation(entity, Version.class) == false) { return entity; } entity = em.merge(entity); em.lock(entity, LockModeType.OPTIMISTIC); return entity; }
Example #4
Source File: ContentPropertyRestController.java From spring-content with Apache License 2.0 | 5 votes |
private void replaceContentInternal(HttpHeaders headers, Repositories repositories, ContentStoreService stores, String repository, String id, String contentProperty, String contentId, String mimeType, String originalFileName, InputStream stream) throws HttpRequestMethodNotSupportedException { Object domainObj = findOne(repositories, repository, id); String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null); Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null); HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate); PersistentProperty<?> property = this.getContentPropertyDefinition(repositories.getPersistentEntity(domainObj.getClass()), contentProperty); Object contentPropertyValue = this.getContentProperty(domainObj, property, contentId); if (BeanUtils.hasFieldWithAnnotation(contentPropertyValue, MimeType.class)) { BeanUtils.setFieldWithAnnotation(contentPropertyValue, MimeType.class, mimeType); } if (originalFileName != null && StringUtils.hasText(originalFileName)) { if (BeanUtils.hasFieldWithAnnotation(contentPropertyValue, OriginalFileName.class)) { BeanUtils.setFieldWithAnnotation(contentPropertyValue, OriginalFileName.class, originalFileName); } } Class<?> contentEntityClass = ContentPropertyUtils.getContentPropertyType(property); ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, contentEntityClass); info.getImpementation().setContent(contentPropertyValue, stream); save(repositories, domainObj); }
Example #5
Source File: ContentPropertyRestController.java From spring-content with Apache License 2.0 | 5 votes |
@StoreType("contentstore") @RequestMapping(value = BASE_MAPPING, method = RequestMethod.DELETE) @ResponseBody public ResponseEntity<?> deleteContent(@RequestHeader HttpHeaders headers, @PathVariable String repository, @PathVariable String id, @PathVariable String contentProperty, @PathVariable String contentId) throws HttpRequestMethodNotSupportedException { Object domainObj = findOne(repositories, repository, id); String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null); Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null); HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate); PersistentProperty<?> property = this.getContentPropertyDefinition( repositories.getPersistentEntity(domainObj.getClass()), contentProperty); Object contentPropertyValue = getContentProperty(domainObj, property, contentId); Class<?> contentEntityClass = ContentPropertyUtils.getContentPropertyType(property); ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, contentEntityClass); info.getImpementation().unsetContent(contentPropertyValue); // remove the content property reference from the data object // setContentProperty(domainObj, property, contentId, null); save(repositories, domainObj); return new ResponseEntity<Object>(HttpStatus.NO_CONTENT); }
Example #6
Source File: AbstractEntityMetaProvider.java From katharsis-framework with Apache License 2.0 | 5 votes |
private boolean hasJpaAnnotations(MetaAttribute attribute) { List<Class<? extends Annotation>> annotationClasses = Arrays.asList(Id.class, EmbeddedId.class, Column.class, ManyToMany.class, ManyToOne.class, OneToMany.class, OneToOne.class, Version.class, ElementCollection.class); for (Class<? extends Annotation> annotationClass : annotationClasses) { if (attribute.getAnnotation(annotationClass) != null) { return true; } } return false; }
Example #7
Source File: JpaResourceFieldInformationProvider.java From crnk-framework with Apache License 2.0 | 5 votes |
@Override public Optional<Boolean> isPatchable(BeanAttributeInformation attributeDesc) { Optional<Column> column = attributeDesc.getAnnotation(Column.class); Optional<Version> version = attributeDesc.getAnnotation(Version.class); if (!version.isPresent() && column.isPresent()) { return Optional.of(column.get().updatable()); } Optional<GeneratedValue> generatedValue = attributeDesc.getAnnotation(GeneratedValue.class); if (generatedValue.isPresent()) { return Optional.of(false); } return Optional.empty(); }
Example #8
Source File: JpaResourceFieldInformationProvider.java From crnk-framework with Apache License 2.0 | 5 votes |
@Override public Optional<Boolean> isPostable(BeanAttributeInformation attributeDesc) { Optional<Column> column = attributeDesc.getAnnotation(Column.class); Optional<Version> version = attributeDesc.getAnnotation(Version.class); if (!version.isPresent() && column.isPresent()) { return Optional.of(column.get().insertable()); } Optional<GeneratedValue> generatedValue = attributeDesc.getAnnotation(GeneratedValue.class); if (generatedValue.isPresent()) { return Optional.of(false); } return Optional.empty(); }
Example #9
Source File: EntityMetaManager.java From das with Apache License 2.0 | 4 votes |
public static EntityMeta extract(Class<?> clazz) { if(registeredTable.containsKey(clazz)) { return registeredTable.get(clazz); } String tableName = null; TableDefinition td = null; Map<String, ColumnDefinition> colMap = new HashMap<>(); try { Field tableDef = clazz.getDeclaredField(clazz.getSimpleName().toUpperCase()); td = (TableDefinition)tableDef.get(null); tableName = td.getName(); } catch (Throwable e) { // It is OK for only the query entity } if(td != null) { for(ColumnDefinition colDef: td.allColumns()) { colMap.put(colDef.getColumnName(), colDef); } } Field[] allFields = clazz.getDeclaredFields(); if (null == allFields || allFields.length == 0) { throw new IllegalArgumentException("The entity[" + clazz.getName() +"] has no fields."); } Map<String, Field> fieldMap = new HashMap<>(); Field idField = null; List<ColumnMeta> columns = new ArrayList<>(); for (Field f: allFields) { Column column = f.getAnnotation(Column.class); Id id = f.getAnnotation(Id.class); // Column must be specified if (column == null) { continue; } String columnName = column.name().trim().length() == 0 ? f.getName() : column.name(); if(tableName != null) { Objects.requireNonNull(colMap.get(columnName), "Column " + columnName + " must be defined in " + tableName); } f.setAccessible(true); fieldMap.put(columnName, f); GeneratedValue generatedValue = f.getAnnotation(GeneratedValue.class); boolean autoIncremental = null != generatedValue && (generatedValue.strategy() == GenerationType.AUTO || generatedValue.strategy() == GenerationType.IDENTITY); if(idField != null && autoIncremental) { throw new IllegalArgumentException("Found duplicate Id columns"); } else if (id != null) { idField = f; } JDBCType type = colMap.containsKey(columnName) ? colMap.get(columnName).getType() : null; columns.add(new ColumnMeta( columnName, type, autoIncremental, id != null, column.insertable(), column.updatable(), f.getAnnotation(Version.class) != null)); } if(tableName!= null && columns.size() != colMap.size()) { throw new IllegalArgumentException("The columns defined in table definition does not match the columns defined in class"); } EntityMeta tableMeta = new EntityMeta(td, columns.toArray(new ColumnMeta[0]), fieldMap, idField); registeredTable.putIfAbsent(clazz, tableMeta); return registeredTable.get(clazz); }
Example #10
Source File: HibernateEntityForDDLAutoCreate.java From micro-server with Apache License 2.0 | 4 votes |
@Version @Column(name = "version", nullable = false) public int getVersion() { return version; }
Example #11
Source File: HibernateEntity.java From micro-server with Apache License 2.0 | 4 votes |
@Version @Column(name = "version", nullable = false) public int getVersion() { return version; }
Example #12
Source File: JPAAnnotationsConfigurer.java From oval with Eclipse Public License 2.0 | 4 votes |
protected void initializeChecks(final Column annotation, final Collection<Check> checks, final AccessibleObject fieldOrMethod) { /* If the value is generated (annotated with @GeneratedValue) it is allowed to be null * before the entity has been persisted, same is true in case of optimistic locking * when a field is annotated with @Version. * Therefore and because of the fact that there is no generic way to determine if an entity * has been persisted already, a not-null check will not be performed for such fields. */ if (!annotation.nullable() // && !fieldOrMethod.isAnnotationPresent(GeneratedValue.class) // && !fieldOrMethod.isAnnotationPresent(Version.class) // && !fieldOrMethod.isAnnotationPresent(NotNull.class) // && !containsCheckOfType(checks, NotNullCheck.class) // ) { checks.add(new NotNullCheck()); } // add Length check based on Column.length parameter, but only: if (!fieldOrMethod.isAnnotationPresent(Lob.class) && // if @Lob is not present !fieldOrMethod.isAnnotationPresent(Enumerated.class) && // if @Enumerated is not present !fieldOrMethod.isAnnotationPresent(Length.class) // if an explicit @Length constraint is not present ) { final LengthCheck lengthCheck = new LengthCheck(); lengthCheck.setMax(annotation.length()); checks.add(lengthCheck); } // add Range check based on Column.precision/scale parameters, but only: if (!fieldOrMethod.isAnnotationPresent(Range.class) // if an explicit @Range is not present && annotation.precision() > 0 // if precision is > 0 && Number.class.isAssignableFrom(fieldOrMethod instanceof Field // ? ((Field) fieldOrMethod).getType() // : ((Method) fieldOrMethod).getReturnType()) // if numeric field type ) { /* precision = 6, scale = 2 => -9999.99<=x<=9999.99 * precision = 4, scale = 1 => -999.9<=x<=999.9 */ final RangeCheck rangeCheck = new RangeCheck(); rangeCheck.setMax(Math.pow(10, annotation.precision() - annotation.scale()) - Math.pow(0.1, annotation.scale())); rangeCheck.setMin(-1 * rangeCheck.getMax()); checks.add(rangeCheck); } }
Example #13
Source File: UserAccount.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #14
Source File: Portal.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #15
Source File: ApplicationConfiguration.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #16
Source File: Agency.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #17
Source File: ApplicationSession.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #18
Source File: JavaxPersistenceImpl.java From ormlite-core with ISC License | 4 votes |
@Override public DatabaseFieldConfig createFieldConfig(DatabaseType databaseType, Field field) { Column columnAnnotation = field.getAnnotation(Column.class); Basic basicAnnotation = field.getAnnotation(Basic.class); Id idAnnotation = field.getAnnotation(Id.class); GeneratedValue generatedValueAnnotation = field.getAnnotation(GeneratedValue.class); OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class); JoinColumn joinColumnAnnotation = field.getAnnotation(JoinColumn.class); Enumerated enumeratedAnnotation = field.getAnnotation(Enumerated.class); Version versionAnnotation = field.getAnnotation(Version.class); if (columnAnnotation == null && basicAnnotation == null && idAnnotation == null && oneToOneAnnotation == null && manyToOneAnnotation == null && enumeratedAnnotation == null && versionAnnotation == null) { return null; } DatabaseFieldConfig config = new DatabaseFieldConfig(); String fieldName = field.getName(); if (databaseType.isEntityNamesMustBeUpCase()) { fieldName = databaseType.upCaseEntityName(fieldName); } config.setFieldName(fieldName); if (columnAnnotation != null) { if (stringNotEmpty(columnAnnotation.name())) { config.setColumnName(columnAnnotation.name()); } if (stringNotEmpty(columnAnnotation.columnDefinition())) { config.setColumnDefinition(columnAnnotation.columnDefinition()); } config.setWidth(columnAnnotation.length()); config.setCanBeNull(columnAnnotation.nullable()); config.setUnique(columnAnnotation.unique()); } if (basicAnnotation != null) { config.setCanBeNull(basicAnnotation.optional()); } if (idAnnotation != null) { if (generatedValueAnnotation == null) { config.setId(true); } else { // generatedValue only works if it is also an id according to {@link GeneratedValue) config.setGeneratedId(true); } } if (oneToOneAnnotation != null || manyToOneAnnotation != null) { // if we have a collection then make it a foreign collection if (Collection.class.isAssignableFrom(field.getType()) || ForeignCollection.class.isAssignableFrom(field.getType())) { config.setForeignCollection(true); if (joinColumnAnnotation != null && stringNotEmpty(joinColumnAnnotation.name())) { config.setForeignCollectionColumnName(joinColumnAnnotation.name()); } if (manyToOneAnnotation != null) { FetchType fetchType = manyToOneAnnotation.fetch(); if (fetchType != null && fetchType == FetchType.EAGER) { config.setForeignCollectionEager(true); } } } else { // otherwise it is a foreign field config.setForeign(true); if (joinColumnAnnotation != null) { if (stringNotEmpty(joinColumnAnnotation.name())) { config.setColumnName(joinColumnAnnotation.name()); } config.setCanBeNull(joinColumnAnnotation.nullable()); config.setUnique(joinColumnAnnotation.unique()); } } } if (enumeratedAnnotation != null) { EnumType enumType = enumeratedAnnotation.value(); if (enumType != null && enumType == EnumType.STRING) { config.setDataType(DataType.ENUM_STRING); } else { config.setDataType(DataType.ENUM_INTEGER); } } if (versionAnnotation != null) { // just the presence of the version... config.setVersion(true); } if (config.getDataPersister() == null) { config.setDataPersister(DataPersisterManager.lookupForField(field)); } config.setUseGetSet(DatabaseFieldConfig.findGetMethod(field, databaseType, false) != null && DatabaseFieldConfig.findSetMethod(field, databaseType, false) != null); return config; }
Example #19
Source File: ApplicationActionEvent.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #20
Source File: TaskAnswer.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@Version @Temporal(TemporalType.TIMESTAMP) @Column(name = "timestamp", nullable = false, length = 19) public Date getTimestamp() { return this.timestamp; }
Example #21
Source File: LanguageData.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #22
Source File: LanguageContentData.java From cia with Apache License 2.0 | 4 votes |
/** * Gets the value of the modelObjectVersion property. * */ @Version @Column(name = "MODEL_OBJECT_VERSION") public int getModelObjectVersion() { return modelObjectVersion; }
Example #23
Source File: B.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
@Version public int getVersion() { return version; }
Example #24
Source File: IssueHJIII35Test.java From hyperjaxb3 with BSD 2-Clause "Simplified" License | 4 votes |
public void testEntityAnnotation() throws Exception { Assert.assertNotNull(IssueHJIII35Type.class.getMethod("getHjversion", new Class[0]).getAnnotation(Version.class)); }
Example #25
Source File: Model.java From hermes with Apache License 2.0 | 4 votes |
@Version public Long getVersion() { return version; }
Example #26
Source File: User.java From ankush with GNU Lesser General Public License v3.0 | 4 votes |
/** * Gets the version. * * @return the version */ @Version @JsonIgnore public Integer getVersion() { return version; }
Example #27
Source File: DocumentNominalLabel.java From AIDR with GNU Affero General Public License v3.0 | 4 votes |
@Version @Temporal(TemporalType.TIMESTAMP) @Column(name = "timestamp", nullable = false, length = 19) public Date getTimestamp() { return this.timestamp; }
Example #28
Source File: ContentEntityRestController.java From spring-content with Apache License 2.0 | 4 votes |
protected void handleMultipart(HttpServletRequest request, HttpServletResponse response, HttpHeaders headers, String store, String id, InputStream content, MediaType mimeType, String originalFilename) throws HttpRequestMethodNotSupportedException, IOException { ContentStoreInfo info = ContentStoreUtils.findContentStore(storeService, store); if (info == null) { throw new IllegalArgumentException( String.format("Store for path %s not found", store)); } Object domainObj = findOne(repositories, info.getDomainObjectClass(), id); String etag = (BeanUtils.getFieldWithAnnotation(domainObj, Version.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, Version.class).toString() : null); Object lastModifiedDate = (BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) != null ? BeanUtils.getFieldWithAnnotation(domainObj, LastModifiedDate.class) : null); HeaderUtils.evaluateHeaderConditions(headers, etag, lastModifiedDate); boolean isNew = true; if (BeanUtils.hasFieldWithAnnotation(domainObj, ContentId.class)) { isNew = (BeanUtils.getFieldWithAnnotation(domainObj, ContentId.class) == null); } if (BeanUtils.hasFieldWithAnnotation(domainObj, MimeType.class)) { BeanUtils.setFieldWithAnnotation(domainObj, MimeType.class, mimeType.toString()); } if (originalFilename != null && StringUtils.hasText(originalFilename)) { if (BeanUtils.hasFieldWithAnnotation(domainObj, OriginalFileName.class)) { BeanUtils.setFieldWithAnnotation(domainObj, OriginalFileName.class, originalFilename); } } domainObj = info.getImpementation().setContent(domainObj, content); save(repositories, domainObj); if (isNew) { response.setStatus(HttpStatus.CREATED.value()); } else { response.setStatus(HttpStatus.OK.value()); } }
Example #29
Source File: AbstractEntityMetaFactory.java From crnk-framework with Apache License 2.0 | 4 votes |
@Override protected void initAttribute(MetaAttribute attr) { ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class); ManyToOne manyOneAnnotation = attr.getAnnotation(ManyToOne.class); OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class); OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class); Version versionAnnotation = attr.getAnnotation(Version.class); Lob lobAnnotation = attr.getAnnotation(Lob.class); Column columnAnnotation = attr.getAnnotation(Column.class); boolean idAttr = attr.getAnnotation(Id.class) != null || attr.getAnnotation(EmbeddedId.class) != null; boolean attrGenerated = attr.getAnnotation(GeneratedValue.class) != null; attr.setVersion(versionAnnotation != null); attr.setAssociation( manyManyAnnotation != null || manyOneAnnotation != null || oneManyAnnotation != null || oneOneAnnotation != null); attr.setLazy(isJpaLazy(attr.getAnnotations(), attr.isAssociation())); attr.setLob(lobAnnotation != null); attr.setFilterable(lobAnnotation == null); attr.setSortable(lobAnnotation == null); attr.setCascaded(getCascade(manyManyAnnotation, manyOneAnnotation, oneManyAnnotation, oneOneAnnotation)); if (attr.getReadMethod() == null) { throw new IllegalStateException("no getter found for " + attr.getParent().getName() + "." + attr.getName()); } Class<?> attributeType = attr.getReadMethod().getReturnType(); boolean isPrimitiveType = ClassUtils.isPrimitiveType(attributeType); boolean columnNullable = (columnAnnotation == null || columnAnnotation.nullable()) && (manyOneAnnotation == null || manyOneAnnotation.optional()) && (oneOneAnnotation == null || oneOneAnnotation.optional()); attr.setNullable(!isPrimitiveType && columnNullable); boolean hasSetter = attr.getWriteMethod() != null; attr.setInsertable(hasSetter && (columnAnnotation == null || columnAnnotation.insertable()) && !attrGenerated && versionAnnotation == null); attr.setUpdatable( hasSetter && (columnAnnotation == null || columnAnnotation.updatable()) && !idAttr && versionAnnotation == null); }
Example #30
Source File: Agency.java From wangmarket with Apache License 2.0 | 4 votes |
@Version public Integer getVersion() { return this.version; }