All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.google.code.liquidform.SelectClause Maven / Gradle / Ivy

Go to download

Provides a Java Domain Specific Language for building type-safe and refactoring proof JPA queries.

The newest version!
/*
 * Copyright (C) 2008-2009 the original author or authors
 * 
 * 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.google.code.liquidform;

import java.util.Collection;

import com.google.code.liquidform.internal.AliasFactory;
import com.google.code.liquidform.internal.managedobjects.FrameworkManagedObject;

/**
 * Represents the SELECT x, y, z part of a query. Selected elements can
 * be persistent entities or properties thereof. Selected elements can be
 * referenced using their alias, or directly via a getter method call
 * like such :
 * 
 * 
 * final Person p = LiquidForm.use(Person.class, "p");
 * select(p.getFirstName()).from(Person.class).as(p); // etc
 * 
* */ // Previous clause is null anyways public class SelectClause extends AbstractClause { private final Object[] selectedElements; /* default */SelectClause(Object[] selectedElements) { super(null); this.selectedElements = selectedElements; } /** * Express an identification variable declaration to a single valued * property. * * @return a stub that may be later used to restrict the query */ public FromClause from(T singleValued) { return new SingleValuedFromClause(this, singleValued); } /** * Express an identification variable declaration to a member of a * collection. * * @return a stub that may be later used to restrict the query */ public FromClause from(Collection collectionValued) { return new CollectionValuedFromClause(this, collectionValued); } /** * Express an identification variable declaration to an abstract schema * type. * * @return a stub that may be later used to restrict the query */ public FromClause from(Class type) { return new AbstractSchemaTypeFromClause(this, type); } /** * Express an identification variable declaration to a member of a * collection. * * @return a stub that may be later used to restrict the query */ public FromClause from(InCollection inCollection) { return new InCollectionFromClause(this, inCollection); } @Override /* default */StringBuilder addTo(StringBuilder buffer) { buffer.append("select "); for (int i = 0; i < selectedElements.length; i++) { FrameworkManagedObject fmo = AliasFactory .about(selectedElements[i]); buffer.append(fmo.getPreferredStringRepresentation()); if (i < selectedElements.length - 1) { buffer.append(", "); } } return buffer; } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy