com.baomidou.mybatisplus.core.mapper.BaseMapper Java Examples

The following examples show how to use com.baomidou.mybatisplus.core.mapper.BaseMapper. 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: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryIntersection(Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.and((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	if (pagination == null) {
		return mapper.selectList(query);
	} else {
		IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
		return page.getRecords();
	}
}
 
Example #2
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 6 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryUnion(Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.or((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	if (pagination == null) {
		return mapper.selectList(query);
	} else {
		IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
		return page.getRecords();
	}
}
 
Example #3
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterateUnion(StorageIterator<T> iterator, Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.or((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
	for (T object : page.getRecords()) {
		iterator.iterate(object);
	}
}
 
Example #4
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public <K extends Comparable, T extends IdentityObject<K>> K maximumIdentity(Class<T> clazz, K from, K to) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	query.select(maximumIdSqls.get(metadata.getOrmClass()));
	query.between(metadata.getColumnName(metadata.getPrimaryName()), from, to);
	List<K> values = mapper.selectObjs(query);
	return values.get(0);
}
 
Example #5
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> K minimumIdentity(Class<T> clazz, K from, K to) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	query.select(minimumIdSqls.get(metadata.getOrmClass()));
	query.between(metadata.getColumnName(metadata.getPrimaryName()), from, to);
	List<K> values = mapper.selectObjs(query);
	return values.get(0);
}
 
Example #6
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, I, T extends IdentityObject<K>> List<T> queryInstances(Class<T> clazz, String name, StorageCondition<I> condition) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	String column = metadata.getColumnName(name);
	ConditionType type = condition.getType();
	I[] values = condition.getValues();
	switch (type) {
	case All:
		break;
	case Between:
		query.between(column, values[0], values[1]);
		break;
	case Equal:
		query.eq(column, values[0]);
		break;
	case Higher:
		query.gt(column, values[0]);
		break;
	case In:
		query.in(column, values);
		break;
	case Lower:
		query.lt(column, values[0]);
		break;
	case Unequal:
		query.ne(column, values[0]);
		break;
	}
	List<T> list = mapper.selectList(query);
	return list;
}
 
Example #7
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> List<T> queryInstances(Class<T> clazz, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	if (pagination == null) {
		return mapper.selectList(query);
	} else {
		IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
		return page.getRecords();
	}
}
 
Example #8
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> long countInstances(Class<T> clazz) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	return mapper.selectCount(query);
}
 
Example #9
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> long countIntersection(Class<T> clazz, Map<String, Object> condition) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.and((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	return mapper.selectCount(query);
}
 
Example #10
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> long countUnion(Class<T> clazz, Map<String, Object> condition) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.or((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	return mapper.selectCount(query);
}
 
Example #11
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterate(StorageIterator<T> iterator, Class<T> clazz, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
	for (T object : page.getRecords()) {
		iterator.iterate(object);
	}
}
 
Example #12
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 5 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> void iterateIntersection(StorageIterator<T> iterator, Class<T> clazz, Map<String, Object> condition, StoragePagination pagination) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	for (Entry<String, Object> term : condition.entrySet()) {
		query.and((wrapper) -> {
			return wrapper.eq(metadata.getColumnName(term.getKey()), term.getValue());
		});
	}
	IPage<T> page = mapper.selectPage(new Page(pagination.getPage(), pagination.getSize()), query);
	for (T object : page.getRecords()) {
		iterator.iterate(object);
	}
}
 
Example #13
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, I, T extends IdentityObject<K>> Map<K, I> queryIdentities(Class<T> clazz, String name, StorageCondition<I> condition) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	QueryWrapper<?> query = new QueryWrapper<>();
	String id = metadata.getColumnName(metadata.getPrimaryName());
	String column = metadata.getColumnName(name);
	query.select(id, column);
	ConditionType type = condition.getType();
	I[] values = condition.getValues();
	switch (type) {
	case All:
		break;
	case Between:
		query.between(column, values[0], values[1]);
		break;
	case Equal:
		query.eq(column, values[0]);
		break;
	case Higher:
		query.gt(column, values[0]);
		break;
	case In:
		query.in(column, values);
		break;
	case Lower:
		query.lt(column, values[0]);
		break;
	case Unequal:
		query.ne(column, values[0]);
		break;
	}
	List<Map<String, Object>> list = mapper.selectMaps(query);
	switch (getCaseStrategy()) {
	case LOWER:
		id = id.toLowerCase();
		column = column.toLowerCase();
		break;
	case UPPER:
		id = id.toUpperCase();
		column = column.toUpperCase();
		break;
	}
	Map<K, I> map = new HashMap<>();
	for (Map<String, Object> element : list) {
		map.put((K) element.get(id), (I) element.get(column));
	}
	return map;
}
 
Example #14
Source File: MyBatisMetadata.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
public Class<? extends BaseMapper<?>> getMapperClass() {
    return mapperClass;
}
 
Example #15
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> boolean updateInstance(Class<T> clazz, T object) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	return mapper.updateById(object) > 0;
}
 
Example #16
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> boolean deleteInstance(Class<T> clazz, T object) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	return mapper.deleteById((Serializable) object.getId()) > 0;
}
 
Example #17
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> boolean deleteInstance(Class<T> clazz, K id) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	return mapper.deleteById((Serializable) id) > 0;
}
 
Example #18
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> boolean createInstance(Class<T> clazz, T object) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	return mapper.insert(object) > 0;
}
 
Example #19
Source File: MyBatisAccessor.java    From jstarcraft-core with Apache License 2.0 4 votes vote down vote up
@Override
public <K extends Comparable, T extends IdentityObject<K>> T getInstance(Class<T> clazz, K id) {
	MyBatisMetadata metadata = metadatas.get(clazz);
	BaseMapper mapper = template.getMapper(metadata.getMapperClass());
	return (T) mapper.selectById((Serializable) id);
}
 
Example #20
Source File: AttachmentServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Attachment> getRepository() {
    return attachmentMapper;
}
 
Example #21
Source File: SlideServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Slide> getRepository() {
    return slideMapper;
}
 
Example #22
Source File: MenuServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Menu> getRepository() {
    return menuMapper;
}
 
Example #23
Source File: UserServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<User> getRepository() {
    return userMapper;
}
 
Example #24
Source File: TagServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Tag> getRepository() {
    return tagMapper;
}
 
Example #25
Source File: PermissionServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Permission> getRepository() {
    return permissionMapper;
}
 
Example #26
Source File: LinkServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Link> getRepository() {
    return linkMapper;
}
 
Example #27
Source File: RoleServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Role> getRepository() {
    return roleMapper;
}
 
Example #28
Source File: WidgetServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Widget> getRepository() {
    return widgetMapper;
}
 
Example #29
Source File: CategoryServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Category> getRepository() {
    return categoryMapper;
}
 
Example #30
Source File: CommentServiceImpl.java    From SENS with GNU General Public License v3.0 4 votes vote down vote up
@Override
public BaseMapper<Comment> getRepository() {
    return commentMapper;
}