![JAR search and dependency download from the Maven repository](/logo.png)
com.jporm.rm.query.update.UpdateQueryImpl Maven / Gradle / Ivy
/*******************************************************************************
* Copyright 2013 Francesco Cina'
*
* 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.
******************************************************************************/
/*
* ---------------------------------------------------------------------------- PROJECT : JPOrm CREATED BY : Francesco
* Cina' ON : Feb 23, 2013 ----------------------------------------------------------------------------
*/
package com.jporm.rm.query.update;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.IntStream;
import com.jporm.commons.core.exception.JpoOptimisticLockException;
import com.jporm.commons.core.inject.ClassTool;
import com.jporm.commons.core.query.cache.SqlCache;
import com.jporm.commons.core.query.strategy.QueryExecutionStrategy;
import com.jporm.commons.core.query.strategy.UpdateExecutionStrategy;
import com.jporm.persistor.Persistor;
import com.jporm.rm.session.SqlExecutor;
import com.jporm.sql.dialect.DBProfile;
import com.jporm.sql.util.ArrayUtil;
/**
*
*
* notes:
*
* ON : Feb 23, 2013
*
* @author Francesco Cina'
* @version $Revision
*/
public class UpdateQueryImpl implements UpdateQuery, UpdateExecutionStrategy {
// private final BEAN bean;
private final Collection beans;
private final Class clazz;
private final String[] pkAndVersionFieldNames;
private final String[] notPksFieldNames;
private final SqlExecutor sqlExecutor;
private final DBProfile dbType;
private final ClassTool ormClassTool;
private final SqlCache sqlCache;
/**
* @param newBean
* @param serviceCatalog
* @param ormSession
*/
public UpdateQueryImpl(final Collection beans, final Class clazz, final ClassTool ormClassTool, final SqlCache sqlCache, final SqlExecutor sqlExecutor,
final DBProfile dbType) {
this.beans = beans;
this.clazz = clazz;
this.ormClassTool = ormClassTool;
this.sqlCache = sqlCache;
this.sqlExecutor = sqlExecutor;
this.dbType = dbType;
pkAndVersionFieldNames = ormClassTool.getDescriptor().getPrimaryKeyAndVersionColumnJavaNames();
notPksFieldNames = ormClassTool.getDescriptor().getNotPrimaryKeyColumnJavaNames();
}
@Override
public List execute() {
return QueryExecutionStrategy.build(dbType).executeUpdate(this);
}
@Override
public List executeWithBatchUpdate() {
String updateQuery = sqlCache.update(clazz);
List updatedBeans = new ArrayList<>();
Collection