Search in sources :

Example 6 with SelectFragment

use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.

the class AbstractEntityPersister method propertySelectFragmentFragment.

public SelectFragment propertySelectFragmentFragment(String tableAlias, String suffix, boolean allProperties) {
    SelectFragment select = new SelectFragment().setSuffix(suffix).setUsedAliases(getIdentifierAliases());
    int[] columnTableNumbers = getSubclassColumnTableNumberClosure();
    String[] columnAliases = getSubclassColumnAliasClosure();
    String[] columnReaderTemplates = getSubclassColumnReaderTemplateClosure();
    for (int i = 0; i < getSubclassColumnClosure().length; i++) {
        boolean selectable = (allProperties || !subclassColumnLazyClosure[i]) && !isSubclassTableSequentialSelect(columnTableNumbers[i]) && subclassColumnSelectableClosure[i];
        if (selectable) {
            String subalias = generateTableAlias(tableAlias, columnTableNumbers[i]);
            select.addColumnTemplate(subalias, columnReaderTemplates[i], columnAliases[i]);
        }
    }
    int[] formulaTableNumbers = getSubclassFormulaTableNumberClosure();
    String[] formulaTemplates = getSubclassFormulaTemplateClosure();
    String[] formulaAliases = getSubclassFormulaAliasClosure();
    for (int i = 0; i < getSubclassFormulaTemplateClosure().length; i++) {
        boolean selectable = (allProperties || !subclassFormulaLazyClosure[i]) && !isSubclassTableSequentialSelect(formulaTableNumbers[i]);
        if (selectable) {
            String subalias = generateTableAlias(tableAlias, formulaTableNumbers[i]);
            select.addFormula(subalias, formulaTemplates[i], formulaAliases[i]);
        }
    }
    if (entityMetamodel.hasSubclasses()) {
        addDiscriminatorToSelect(select, tableAlias, suffix);
    }
    if (hasRowId()) {
        select.addColumn(tableAlias, rowIdName, ROWID_ALIAS);
    }
    return select;
}
Also used : SelectFragment(org.hibernate.sql.SelectFragment)

Example 7 with SelectFragment

use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.

the class AbstractEntityPersister method createSelect.

protected SelectFragment createSelect(final int[] subclassColumnNumbers, final int[] subclassFormulaNumbers) {
    SelectFragment selectFragment = new SelectFragment();
    int[] columnTableNumbers = getSubclassColumnTableNumberClosure();
    String[] columnAliases = getSubclassColumnAliasClosure();
    String[] columnReaderTemplates = getSubclassColumnReaderTemplateClosure();
    for (int i = 0; i < subclassColumnNumbers.length; i++) {
        int columnNumber = subclassColumnNumbers[i];
        if (subclassColumnSelectableClosure[columnNumber]) {
            final String subalias = generateTableAlias(getRootAlias(), columnTableNumbers[columnNumber]);
            selectFragment.addColumnTemplate(subalias, columnReaderTemplates[columnNumber], columnAliases[columnNumber]);
        }
    }
    int[] formulaTableNumbers = getSubclassFormulaTableNumberClosure();
    String[] formulaTemplates = getSubclassFormulaTemplateClosure();
    String[] formulaAliases = getSubclassFormulaAliasClosure();
    for (int i = 0; i < subclassFormulaNumbers.length; i++) {
        int formulaNumber = subclassFormulaNumbers[i];
        final String subalias = generateTableAlias(getRootAlias(), formulaTableNumbers[formulaNumber]);
        selectFragment.addFormula(subalias, formulaTemplates[formulaNumber], formulaAliases[formulaNumber]);
    }
    return selectFragment;
}
Also used : SelectFragment(org.hibernate.sql.SelectFragment)

Example 8 with SelectFragment

use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.

the class MapEntryNode method determineValueSelectExpressions.

private void determineValueSelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator(1);
    appendSelectExpressions(collectionPersister.getElementColumnNames(), selections, aliasGenerator);
    Type valueType = collectionPersister.getElementType();
    if (valueType.isAssociationType()) {
        EntityType valueEntityType = (EntityType) valueType;
        Queryable valueEntityPersister = (Queryable) sfi().getEntityPersister(valueEntityType.getAssociatedEntityName(sfi()));
        SelectFragment fragment = valueEntityPersister.propertySelectFragmentFragment(elementTableAlias(), null, false);
        appendSelectExpressions(fragment, selections, aliasGenerator);
    }
}
Also used : EntityType(org.hibernate.type.EntityType) SelectFragment(org.hibernate.sql.SelectFragment) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) AliasGenerator(org.hibernate.sql.AliasGenerator) Queryable(org.hibernate.persister.entity.Queryable)

Example 9 with SelectFragment

use of org.hibernate.sql.SelectFragment in project hibernate-orm by hibernate.

the class MapEntryNode method determineKeySelectExpressions.

private void determineKeySelectExpressions(QueryableCollection collectionPersister, List selections) {
    AliasGenerator aliasGenerator = new LocalAliasGenerator(0);
    appendSelectExpressions(collectionPersister.getIndexColumnNames(), selections, aliasGenerator);
    Type keyType = collectionPersister.getIndexType();
    if (keyType.isEntityType()) {
        MapKeyEntityFromElement mapKeyEntityFromElement = findOrAddMapKeyEntityFromElement(collectionPersister);
        Queryable keyEntityPersister = mapKeyEntityFromElement.getQueryable();
        SelectFragment fragment = keyEntityPersister.propertySelectFragmentFragment(mapKeyEntityFromElement.getTableAlias(), null, false);
        appendSelectExpressions(fragment, selections, aliasGenerator);
    }
}
Also used : SelectFragment(org.hibernate.sql.SelectFragment) EntityType(org.hibernate.type.EntityType) Type(org.hibernate.type.Type) AliasGenerator(org.hibernate.sql.AliasGenerator) Queryable(org.hibernate.persister.entity.Queryable)

Aggregations

SelectFragment (org.hibernate.sql.SelectFragment)9 Queryable (org.hibernate.persister.entity.Queryable)2 AliasGenerator (org.hibernate.sql.AliasGenerator)2 Select (org.hibernate.sql.Select)2 SimpleSelect (org.hibernate.sql.SimpleSelect)2 EntityType (org.hibernate.type.EntityType)2 Type (org.hibernate.type.Type)2 JoinFragment (org.hibernate.sql.JoinFragment)1