當前位置: 首頁>>代碼示例>>Java>>正文


Java UniqueConstraint類代碼示例

本文整理匯總了Java中javax.persistence.UniqueConstraint的典型用法代碼示例。如果您正苦於以下問題:Java UniqueConstraint類的具體用法?Java UniqueConstraint怎麽用?Java UniqueConstraint使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


UniqueConstraint類屬於javax.persistence包,在下文中一共展示了UniqueConstraint類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildUniqueConstraints

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private static void buildUniqueConstraints(AnnotationDescriptor annotation, Element element) {
	List uniqueConstraintElementList = element.elements( "unique-constraint" );
	UniqueConstraint[] uniqueConstraints = new UniqueConstraint[uniqueConstraintElementList.size()];
	int ucIndex = 0;
	Iterator ucIt = uniqueConstraintElementList.listIterator();
	while ( ucIt.hasNext() ) {
		Element subelement = (Element) ucIt.next();
		List<Element> columnNamesElements = subelement.elements( "column-name" );
		String[] columnNames = new String[columnNamesElements.size()];
		int columnNameIndex = 0;
		Iterator it = columnNamesElements.listIterator();
		while ( it.hasNext() ) {
			Element columnNameElt = (Element) it.next();
			columnNames[columnNameIndex++] = columnNameElt.getTextTrim();
		}
		AnnotationDescriptor ucAnn = new AnnotationDescriptor( UniqueConstraint.class );
		copyStringAttribute( ucAnn, subelement, "name", false );
		ucAnn.setValue( "columnNames", columnNames );
		uniqueConstraints[ucIndex++] = AnnotationFactory.create( ucAnn );
	}
	annotation.setValue( "uniqueConstraints", uniqueConstraints );
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:23,代碼來源:JPAOverriddenAnnotationReader.java

示例2: buildUniqueConstraintHolders

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
/**
 * Build a list of {@link org.hibernate.cfg.UniqueConstraintHolder} instances given a list of
 * {@link UniqueConstraint} annotations.
 *
 * @param annotations The {@link UniqueConstraint} annotations.
 *
 * @return The built {@link org.hibernate.cfg.UniqueConstraintHolder} instances.
 */
public static List<UniqueConstraintHolder> buildUniqueConstraintHolders(UniqueConstraint[] annotations) {
	List<UniqueConstraintHolder> result;
	if ( annotations == null || annotations.length == 0 ) {
		result = java.util.Collections.emptyList();
	}
	else {
		result = new ArrayList<UniqueConstraintHolder>( CollectionHelper.determineProperSizing( annotations.length ) );
		for ( UniqueConstraint uc : annotations ) {
			result.add(
					new UniqueConstraintHolder()
							.setName( uc.name() )
							.setColumns( uc.columnNames() )
			);
		}
	}
	return result;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:26,代碼來源:TableBinder.java

示例3: getLabels

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
@Override
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "MCRCategoryLabels",
    joinColumns = @JoinColumn(name = "category"),
    uniqueConstraints = {
        @UniqueConstraint(columnNames = { "category", "lang" }) })
public Set<MCRLabel> getLabels() {
    return super.getLabels();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:10,代碼來源:MCRCategoryImpl.java

示例4: register

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
protected <T> void register(OObjectDatabaseTx db, OSchema schema, Class<T> aClass) {
    if (schema.getClass(aClass.getSimpleName()) == null) {
        db.getEntityManager().registerEntityClasses(aClass, true);
        OClass cls = db.getMetadata().getSchema().getClass(aClass);
        String indexName = aClass.getName() + ".unq";
        Table t = aClass.getAnnotation(Table.class);
        if (t != null) {
            Set<String> fields = new HashSet<>();
            for (UniqueConstraint uc : t.uniqueConstraints()) {
                fields.addAll(Lists.newArrayList(uc.columnNames()));
            }
            if (fields.size() > 0) {
                LOG.info("Registering unique constraint for fields: " + fields);
                for (String field : fields)
                    cls.createIndex(indexName + "." + field, OClass.INDEX_TYPE.UNIQUE_HASH_INDEX, field);
            }
        }
    } else {
        db.getEntityManager().registerEntityClasses(aClass, true);
    }
}
 
開發者ID:dmart28,項目名稱:gcplot,代碼行數:22,代碼來源:AbstractOrientDbRepository.java

示例5: instpectUniqueConstraint

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private void instpectUniqueConstraint(final UniqueConstraint constraint) {
	UniquePropertyQuality currentQuality = UniquePropertyQuality.onlyRequiredPrimitives;
	final List<SingularProperty<E, ?>> uniques = new ArrayList<>();
	final String[] columnNames = constraint.columnNames();
	for (final String columnName : columnNames) {
		for (final Property<E, ?> property : this.properties.values()) {
			if (property instanceof SingularProperty) {
				final SingularProperty<E, ?> singularProperty = (SingularProperty<E, ?>) property;
				if (columnName.equals(singularProperty.getColumn().getName())) {
					final UniquePropertyQuality quality = UniquePropertyQuality.getMatchingQuality(property);
					if (quality != null) {
						if (quality.ordinal() > currentQuality.ordinal()) {
							currentQuality = quality;
						}
						uniques.add(singularProperty);
					}
				}
			}
		}
	}
	if (uniques.size() == columnNames.length && isBetterUniquePropertyQuality(currentQuality)) {
		this.uniqueProperties = uniques;
		this.uniquePropertiesQuality = currentQuality;
	}
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:26,代碼來源:EntityClass.java

示例6: buildUniqueConstraints

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
/**
 * @deprecated Use {@link #buildUniqueConstraintHolders} instead
 */
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static List<String[]> buildUniqueConstraints(UniqueConstraint[] constraintsArray) {
	List<String[]> result = new ArrayList<String[]>();
	if ( constraintsArray.length != 0 ) {
		for (UniqueConstraint uc : constraintsArray) {
			result.add( uc.columnNames() );
		}
	}
	return result;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:15,代碼來源:TableBinder.java

示例7: _getFieldsFromUniqueConstraint

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private ArrayList<String[]> _getFieldsFromUniqueConstraint(Object value){
    ArrayList<String[]> result = new ArrayList<>();

    if(value.getClass().isAnnotationPresent(Table.class)){
        Table ta = value.getClass().getAnnotation(Table.class);
        for(UniqueConstraint uc : ta.uniqueConstraints()){
            result.add(uc.columnNames());
        }
    }

    return result;
}
 
開發者ID:Klinton90,項目名稱:UniqueValidator,代碼行數:13,代碼來源:UniqueValidator.java

示例8: getUniqueColumns

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private static String getUniqueColumns(Class<?> clazz, String name) {
    return Optional.of(clazz)
        .map(c -> c.getAnnotation(Table.class))
        .map(Table::uniqueConstraints)
        .map(Stream::of)
        .flatMap(s -> s
            .filter(uc -> uc.name().equals(name))
            .findAny()
            .map(UniqueConstraint::columnNames))
        .map(Stream::of)
        .map(s -> s.collect(Collectors.joining(", ")))
        .get();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:14,代碼來源:MCRHibernateConfigHelper.java

示例9: validateCompositeUniqueConstraints

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private List<String> validateCompositeUniqueConstraints(Identifiable<?> entity) {
    Class<?> entityClass = getClassWithoutInitializingProxy(entity);
    Table table = findAnnotation(entityClass, Table.class);
    if (table == null) {
        return emptyList();
    }
    List<String> errors = newArrayList();
    for (UniqueConstraint uniqueConstraint : table.uniqueConstraints()) {
        if (!checkCompositeUniqueConstraint(entity, entityClass, uniqueConstraint)) {
            errors.add(compositeUniqueConstraintErrorCode(entity, uniqueConstraint));
        }
    }
    return errors;
}
 
開發者ID:ddRPB,項目名稱:rpb,代碼行數:15,代碼來源:JpaUniqueUtil.java

示例10: getPropertyConstraints

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private Map<String, Object> getPropertyConstraints(Object entity, Class<?> entityClass, UniqueConstraint u, String prefix) {
    Map<String, Object> values = newHashMap();
    for (String column : u.columnNames()) {
        Method method = columnNameToMethod(entityClass, column);
        if (method != null) {
            values.put(prefix + methodToProperty(method), invokeMethod(method, entity));
        } else {
            Field field = columnNameToField(entityClass, column);
            if (field != null) {
                values.put(prefix + field.getName(), getValueFromField(field, entity));
            }
        }
    }
    return values;
}
 
開發者ID:ddRPB,項目名稱:rpb,代碼行數:16,代碼來源:JpaUniqueUtil.java

示例11: buildUniqueProperties

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
private void buildUniqueProperties(final UniqueConstraint[] uniqueConstraints) {
	for (final UniqueConstraint constraint : uniqueConstraints) {
		if (constraint.columnNames().length <= this.context.getMaxUniqueProperties()) {
			instpectUniqueConstraint(constraint);
		}
	}
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:8,代碼來源:EntityClass.java

示例12: getCourtReporters_

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
@ElementCollection
@CollectionTable(name="judgment_court_reporter", uniqueConstraints={@UniqueConstraint(name="judgment_court_reporter_unique", columnNames={"fk_judgment", "court_reporter"})})
@Column(name="court_reporter")
@OrderBy("court_reporter")
private List<String> getCourtReporters_() {
    return courtReporters;
}
 
開發者ID:CeON,項目名稱:saos,代碼行數:8,代碼來源:Judgment.java

示例13: getLegalBases_

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
@ElementCollection
@CollectionTable(name="judgment_legal_bases", uniqueConstraints={@UniqueConstraint(name="judgment_legal_base_unique", columnNames={"fk_judgment", "legal_base"})})
@Column(name="legal_base")
@OrderBy("legal_base")
private List<String> getLegalBases_() {
    return legalBases;
}
 
開發者ID:CeON,項目名稱:saos,代碼行數:8,代碼來源:Judgment.java

示例14: getLowerCourtJudgments_

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
@ElementCollection
@CollectionTable(name="judgment_lower_court_judgments", uniqueConstraints={@UniqueConstraint(name="judgment_lower_court_judgment_unique", columnNames={"fk_judgment", "lower_court_judgment"})})
@Column(name="lower_court_judgment")
@OrderBy("lower_court_judgment")
private List<String> getLowerCourtJudgments_() {
    return lowerCourtJudgments;
}
 
開發者ID:CeON,項目名稱:saos,代碼行數:8,代碼來源:Judgment.java

示例15: getAuthors_

import javax.persistence.UniqueConstraint; //導入依賴的package包/類
@ElementCollection
@CollectionTable(name="ct_judgment_opinion_author",
                joinColumns = {@JoinColumn(name = "fk_ct_judgment_opinion", nullable = false)},
                uniqueConstraints={@UniqueConstraint(name="ct_judgment_opinion_author_unique", columnNames={"fk_ct_judgment_opinion", "author"})})
@Column(name="author", nullable=false)
private List<String> getAuthors_() {
    return authors;
}
 
開發者ID:CeON,項目名稱:saos,代碼行數:9,代碼來源:ConstitutionalTribunalJudgmentDissentingOpinion.java


注:本文中的javax.persistence.UniqueConstraint類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。