javax.persistence.Index Java Examples

The following examples show how to use javax.persistence.Index. 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: HibernateMetadata.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
/**
 * 构造方法
 * 
 * @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 #2
Source File: CheckCore.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkLobIndex(List<Class<?>> classes) throws Exception {
	for (Class<?> cls : classes) {
		List<Field> fields = FieldUtils.getAllFieldsList(cls);
		for (Field field : fields) {
			Lob lob = field.getAnnotation(Lob.class);
			Index index = field.getAnnotation(Index.class);
			if ((null != lob) && (null != index)) {
				System.err.println(String.format("checkLobIndex error: class: %s, field: %s.", cls.getName(),
						field.getName()));
			}
		}
	}
}
 
Example #3
Source File: CheckCore.java    From o2oa with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void checkIdCreateTimeUpdateTimeSequenceIndex(List<Class<?>> classes) throws Exception {
	for (Class<?> cls : classes) {
		Field idField = FieldUtils.getField(cls, JpaObject.id_FIELDNAME, true);
		Field createTimeField = FieldUtils.getField(cls, JpaObject.createTime_FIELDNAME, true);
		Field updateTimeField = FieldUtils.getField(cls, JpaObject.updateTime_FIELDNAME, true);
		Field sequenceField = FieldUtils.getField(cls, JpaObject.sequence_FIELDNAME, true);
		if ((null != idField.getAnnotation(Index.class)) || (null != createTimeField.getAnnotation(Index.class))
				|| (null != updateTimeField.getAnnotation(Index.class))
				|| (null != sequenceField.getAnnotation(Index.class))) {
			System.err.println(
					String.format("checkIdCreateTimeUpdateTimeSequenceIndex error: class: %s.", cls.getName()));
		}
	}
}
 
Example #4
Source File: JPAIndexHolder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public JPAIndexHolder(Index index) {
	StringTokenizer tokenizer = new StringTokenizer( index.columnList(), "," );
	List<String> tmp = new ArrayList<String>();
	while ( tokenizer.hasMoreElements() ) {
		tmp.add( tokenizer.nextToken().trim() );
	}
	this.name = index.name();
	this.columns = new String[tmp.size()];
	this.ordering = new String[tmp.size()];
	this.unique = index.unique();
	initializeColumns( columns, ordering, tmp );
}
 
Example #5
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static void buildIndex(AnnotationDescriptor annotation, Element element){
	List indexElementList = element.elements( "index" );
	Index[] indexes = new Index[indexElementList.size()];
	for(int i=0;i<indexElementList.size();i++){
		Element subelement = (Element)indexElementList.get( i );
		AnnotationDescriptor indexAnn = new AnnotationDescriptor( Index.class );
		copyStringAttribute( indexAnn, subelement, "name", false );
		copyStringAttribute( indexAnn, subelement, "column-list", true );
		copyBooleanAttribute( indexAnn, subelement, "unique" );
		indexes[i] = AnnotationFactory.create( indexAnn );
	}
	annotation.setValue( "indexes", indexes );
}
 
Example #6
Source File: MCRUser.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.EAGER)
@CollectionTable(name = "MCRUserAttr",
    joinColumns = @JoinColumn(name = "id"),
    indexes = { @Index(name = "MCRUserAttributes", columnList = "name, value"),
        @Index(name = "MCRUserValues", columnList = "value") })
@SortNatural
@XmlElementWrapper(name = "attributes")
@XmlElement(name = "attribute")
public SortedSet<MCRUserAttribute> getAttributes() {
    return this.attributes;
}
 
Example #7
Source File: EntityType.java    From requery with Apache License 2.0 5 votes vote down vote up
@Override
public String[] tableUniqueIndexes() {
    if (annotationOf(javax.persistence.Table.class).isPresent()) {
        Index[] indexes = annotationOf(javax.persistence.Table.class)
                .map(javax.persistence.Table::indexes)
                .orElse(new Index[0]);
        Set<String> names = Stream.of(indexes).filter(Index::unique)
                .map(Index::name).collect(Collectors.toSet());
        return names.toArray(new String[names.size()]);
    }
    return annotationOf(Table.class).map(Table::uniqueIndexes).orElse(new String[]{});
}
 
Example #8
Source File: TaskData.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "TASK_DATA_DEPENDENCIES", joinColumns = { @JoinColumn(name = "JOB_ID", referencedColumnName = "TASK_ID_JOB"),
                                                                  @JoinColumn(name = "TASK_ID", referencedColumnName = "TASK_ID_TASK") }, indexes = { @Index(name = "TASK_DATA_DEP_JOB_ID", columnList = "JOB_ID"),
                                                                                                                                                      @Index(name = "TASK_DATA_DEP_TASK_ID_JOB_ID", columnList = "TASK_ID,JOB_ID"),
                                                                                                                                                      @Index(name = "TASK_DATA_DEP_TASK_ID", columnList = "TASK_ID"), })
@BatchSize(size = 100)
public List<DBTaskId> getDependentTasks() {
    return dependentTasks;
}
 
Example #9
Source File: TaskData.java    From scheduling with GNU Affero General Public License v3.0 5 votes vote down vote up
@ElementCollection(fetch = FetchType.LAZY)
@CollectionTable(name = "TASK_DATA_JOINED_BRANCHES", joinColumns = { @JoinColumn(name = "JOB_ID", referencedColumnName = "TASK_ID_JOB"),
                                                                     @JoinColumn(name = "TASK_ID", referencedColumnName = "TASK_ID_TASK") }, indexes = { @Index(name = "TASK_DATA_JB_JOB_ID", columnList = "JOB_ID"),
                                                                                                                                                         @Index(name = "TASK_DATA_JB_TASK_ID_JOB_ID", columnList = "TASK_ID,JOB_ID"),
                                                                                                                                                         @Index(name = "TASK_DATA_JB_TASK_ID", columnList = "TASK_ID"), })
@BatchSize(size = 100)
public List<DBTaskId> getJoinedBranches() {
    return joinedBranches;
}
 
Example #10
Source File: User.java    From vpn-over-dns with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@OneToMany(cascade = javax.persistence.CascadeType.ALL, fetch = javax.persistence.FetchType.EAGER)
@JoinTable(indexes = { @Index(columnList = "user_id"), @Index(columnList = "accounts_id") })
public Collection<Account> getAccounts() {
	return accounts;
}