com.gs.fw.common.mithra.finder.ImplicitJoinClause Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of reladomo Show documentation
Show all versions of reladomo Show documentation
Reladomo is an object-relational mapping framework.
/*
Copyright 2016 Goldman Sachs.
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 com.gs.fw.common.mithra.finder;
import com.gs.fw.common.mithra.MithraObjectPortal;
import com.gs.fw.common.mithra.attribute.Attribute;
import java.sql.PreparedStatement;
import java.sql.SQLException;
public class ImplicitJoinClause implements JoinClause
{
private final int tableNumber;
private String tableAliasPrefix = "t";
private boolean isMapped = true;
private WhereClause whereClause;
private final MithraObjectPortal portal;
private MapperStackImpl mapperStackImpl;
public ImplicitJoinClause(MithraObjectPortal portal, int tableNumber)
{
this.tableNumber = tableNumber;
this.portal = portal;
}
public ImplicitJoinClause(MithraObjectPortal portal, int tableNumber, String tableAliasPrefix,
MapperStackImpl immutableMapperStack)
{
this(portal, tableNumber);
this.mapperStackImpl = immutableMapperStack;
this.tableAliasPrefix = tableAliasPrefix;
}
public void addAttributeFromMapper(Attribute attr)
{
//nothing to do
}
public void addAttribute(Attribute attr)
{
//nothing to do
}
public boolean belongsToInnerSql(SqlQuery query)
{
return false;
}
public void generateSql(SqlQuery query, boolean notExists)
{
if (notExists || query.getWhereClause().isInOrClause())
{
throw new RuntimeException("triangle joins and notExists/or are not supported");
}
this.whereClause = query.getWhereClause();
}
public String getTableAlias()
{
return tableAliasPrefix+tableNumber;
}
public boolean isMapped()
{
return isMapped;
}
public void setMapped(boolean mapped)
{
isMapped = mapped;
}
public void reset()
{
this.setMapped(false);
}
public WhereClause getWhereClause()
{
return this.whereClause;
}
private int getTableNumber()
{
return tableNumber;
}
private void appendTableAndSuperClasses(SqlQuery query, StringBuilder fromClause, String withLock, String withoutLock)
{
MithraObjectPortal[] superClasses = portal.getSuperClassPortals();
if (superClasses != null)
{
fromClause.append(query.getTableName(superClasses[0], mapperStackImpl));
String tableAlias = "t"+this.getTableNumber();
fromClause.append(' ').append(tableAlias);
query.appendLockMode(fromClause, superClasses[0], withLock, withoutLock);
for(int i=1;i= ");
this.whereClause.append(fullyQualifiedFromColumn).append(" and ") ;
this.whereClause.append(fullyQualifiedLeftColumnName).append(" < ");
this.whereClause.append(fullyQualifiedToColumn).append(") or (");
this.whereClause.append(fullyQualifiedToColumn).append(" = ? and ");
this.whereClause.append(fullyQualifiedLeftColumnName).append(" = ? ))");
}
else
{
this.whereClause.append("((");
this.whereClause.append(fullyQualifiedLeftColumnName).append(" >= ");
this.whereClause.append(fullyQualifiedFromColumn).append(" and ") ;
this.whereClause.append(fullyQualifiedLeftColumnName).append(" < ");
this.whereClause.append(fullyQualifiedToColumn).append(") or (");
this.whereClause.append(fullyQualifiedToColumn).append(" = ? and ");
this.whereClause.append(fullyQualifiedLeftColumnName).append(" = ? ))");
}
this.whereClause.addSqlParameterSetter(parameterSetter);
}
public void generateJoinSql(SqlQuery query, String fullyQualifiedLeftColumnName, String fullyQualifiedRightHandColumn, String operator)
{
query.beginAnd();
query.appendWhereClause(fullyQualifiedLeftColumnName);
query.appendWhereClause(operator);
query.appendWhereClause(fullyQualifiedRightHandColumn);
query.endAnd();
}
public void generateAsOfJoinSql(SqlQuery query, MapperStackImpl mapperStack, String fullyQualifiedLeftColumnName, String fullyQualifiedRightHandColumn, String operator)
{
query.beginAnd();
query.appendWhereClause(fullyQualifiedLeftColumnName);
query.appendWhereClause(operator);
query.appendWhereClause(fullyQualifiedRightHandColumn);
query.endAnd();
}
public boolean isTopLevel()
{
return true;
}
public String getFullyQualifiedColumnNameFor(String fullyQualifiedColumnName)
{
return fullyQualifiedColumnName;
}
public String getFullyQualifiedOrderByColumnNameFor(String orderByColumnName)
{
return orderByColumnName;
}
public boolean mustUseExistsForMapperOnly(SqlQuery query)
{
return false;
}
public boolean allowsInClauseTempJoinReplacement()
{
return false;
}
public void restoreMapper(SqlQuery sqlQuery)
{
throw new RuntimeException("not implemented");
}
@Override
public void computeAggregationForTree()
{
//nothing to do
}
}