예제 #1
0
  private void initStatementString(
      final String projection,
      final String condition,
      final String orderBy,
      final String groupBy,
      final LockMode lockMode)
      throws MappingException {

    final int joins = countEntityPersisters(associations);
    suffixes = BasicLoader.generateSuffixes(joins + 1);

    JoinFragment ojf = mergeOuterJoins(associations);

    Select select =
        new Select(getDialect())
            .setLockMode(lockMode)
            .setSelectClause(
                projection == null
                    ? persister.selectFragment(alias, suffixes[joins]) + selectString(associations)
                    : projection)
            .setFromClause(
                getDialect().appendLockHint(lockMode, persister.fromTableFragment(alias))
                    + persister.fromJoinFragment(alias, true, true))
            .setWhereClause(condition)
            .setOuterJoins(
                ojf.toFromFragmentString(), ojf.toWhereFragmentString() + getWhereFragment())
            .setOrderByClause(orderBy(associations, orderBy))
            .setGroupByClause(groupBy);

    if (getFactory().getSettings().isCommentsEnabled()) {
      select.setComment(getComment());
    }
    sql = select.toStatementString();
  }
예제 #2
0
 public String selectFragment(
     Joinable rhs,
     String rhsAlias,
     String lhsAlias,
     String entitySuffix,
     String collectionSuffix,
     boolean includeCollectionColumns) {
   StringBuffer buf = new StringBuffer();
   if (includeCollectionColumns) {
     //			buf.append( selectFragment( lhsAlias, "" ) )//ignore suffix for collection columns!
     buf.append(selectFragment(lhsAlias, collectionSuffix)).append(", ");
   }
   OuterJoinLoadable ojl = (OuterJoinLoadable) getElementPersister();
   return buf.append(
           ojl.selectFragment(lhsAlias, entitySuffix)) // use suffix for the entity columns
       .toString();
 }