All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dynamoframework.dao.impl.DefaultDaoImpl Maven / Gradle / Ivy

There is a newer version: 4.0.0-RC2
Show newest version
package org.dynamoframework.dao.impl;

/*-
 * #%L
 * Dynamo Framework
 * %%
 * Copyright (C) 2014 - 2024 Open Circle Solutions
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import com.querydsl.core.types.dsl.EntityPathBase;
import org.dynamoframework.dao.FetchJoinInformation;
import org.dynamoframework.domain.AbstractEntity;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;

/**
 * A default DAO implementation for handling database access for a simple
 *
 * @param  the type of the primary key
 * @param   the type of the entity
 * @author bas.rutten
 */
@Transactional
public class DefaultDaoImpl> extends BaseDaoImpl {

	private final EntityPathBase dslRoot;

	private final Class entityClass;

	private final String[] fetchPropertyIds;

	/**
	 * Constructor
	 *
	 * @param dslRoot     the query DSL root path
	 * @param entityClass the entity class
	 */
	public DefaultDaoImpl(EntityPathBase dslRoot, Class entityClass) {
		this(dslRoot, entityClass, (String[]) null);
	}

	/**
	 * Constructor
	 *
	 * @param dslRoot          the query DSL root path
	 * @param entityClass      the entity class
	 * @param fetchPropertyIds the IDs of the properties to fetch
	 */
	public DefaultDaoImpl(EntityPathBase dslRoot, Class entityClass, String... fetchPropertyIds) {
		this.dslRoot = dslRoot;
		this.entityClass = entityClass;
		this.fetchPropertyIds = fetchPropertyIds;
	}

	@Override
	public EntityPathBase getDslRoot() {
		return dslRoot;
	}

	@Override
	public Class getEntityClass() {
		return entityClass;
	}

	@Override
	protected FetchJoinInformation[] getJoins() {
		if (fetchPropertyIds == null || fetchPropertyIds.length == 0) {
			return super.getJoins();
		}

		return Arrays.stream(fetchPropertyIds).map(FetchJoinInformation::new).toList()
			.toArray(new FetchJoinInformation[0]);
	}

	@Override
	protected FetchJoinInformation[] getDetailJoins() {
		if (fetchPropertyIds == null || fetchPropertyIds.length == 0) {
			return super.getDetailJoins();
		}

		return Arrays.stream(fetchPropertyIds).map(FetchJoinInformation::new).toList()
			.toArray(new FetchJoinInformation[0]);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy