本文整理匯總了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 );
}
示例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;
}
示例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();
}
示例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);
}
}
示例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;
}
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}