
br.com.objectos.way.orm.compiler.SingletonTableInfoMap Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014-2015 Objectos, Fábrica de Software LTDA.
*
* 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.
*/
package br.com.objectos.way.orm.compiler;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import br.com.objectos.core.collections.MoreCollectors;
import br.com.objectos.way.code.SimpleTypeInfo;
import br.com.objectos.way.orm.Insertable;
import br.com.objectos.way.pojo.plugin.PojoInfo;
import br.com.objectos.way.schema.info.TableInfoAnnotationInfo;
import com.squareup.javapoet.ClassName;
/**
* @author [email protected] (Marcio Endo)
*/
class SingletonTableInfoMap extends TableInfoMap {
private final TableInfoAnnotationInfo tableInfo;
private final List propertyList;
private final List primaryKeyPropertyList;
private SingletonTableInfoMap(TableInfoAnnotationInfo tableInfo,
List propertyList,
List primaryKeyPropertyList) {
this.tableInfo = tableInfo;
this.propertyList = propertyList;
this.primaryKeyPropertyList = primaryKeyPropertyList;
}
public static TableInfoMap of(TableInfoAnnotationInfo tableInfo, List propertyList) {
Set pkNameSet = tableInfo.primaryKeyClassNameSet();
return new SingletonTableInfoMap(
tableInfo,
propertyList,
propertyList.stream()
.filter(col -> col.matchesAny(pkNameSet))
.collect(MoreCollectors.toImmutableList()));
}
@Override
public boolean containsPrimaryKey() {
Set pkNameSet = tableInfo.primaryKeyClassNameSet();
return !pkNameSet.isEmpty() && pkNameSet.size() == primaryKeyPropertyList.size();
}
@Override
public T onFirstEntry(TableInfoMapAction action) {
return action.onEntry(tableInfo, propertyList);
}
@Override
public List primaryKeyPropertyList() {
return primaryKeyPropertyList;
}
@Override
public QuerySelectExpression selectExpression() {
return new SingletonQuerySelectExpression(
tableInfo.className(),
propertyList);
}
@Override
public int size() {
return 1;
}
@Override
public OrmInsertable toOrmInsertable(PojoInfo pojoInfo) {
if (!pojoInfo.instanceOf(Insertable.class)) {
return NotOrmInsertable.INSTANCE;
}
List columnAnnotationClassList = propertyList.stream()
.filter(property -> !property.isGenerated())
.flatMap(m -> m.columnAnnotationClassList().stream())
.collect(Collectors.toList());
return tableInfo.containsAll(columnAnnotationClassList)
? IsOrmInsertable.of(tableInfo, propertyList)
: NotOrmInsertable.INSTANCE;
}
@Override
List testableValues() {
return propertyList;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy