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

org.apache.cayenne.access.QueryTranslator Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
/*****************************************************************
 *   Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 org.apache.cayenne.access;

import java.sql.Connection;
import java.sql.PreparedStatement;

import org.apache.log4j.Level;
import org.apache.cayenne.dba.DbAdapter;
import org.apache.cayenne.map.DbEntity;
import org.apache.cayenne.map.EntityInheritanceTree;
import org.apache.cayenne.map.EntityResolver;
import org.apache.cayenne.map.ObjEntity;
import org.apache.cayenne.query.Query;

/**
 * Defines API for translation Cayenne queries to JDBC PreparedStatements.
 * 

* For more information see Cayenne User Guide. *

* * @author Andrei Adamchik */ public abstract class QueryTranslator { /** Query being translated. */ protected Query query; /** * JDBC database connection needed to create PreparedStatement. Prior to 1.2 this * property was called "con". */ protected Connection connection; /** * Used mainly for name resolution. * * @deprecated Since 1.2 entityResolver property is used. */ protected QueryEngine engine; /** Adapter helping to do SQL literal conversions, etc. */ protected DbAdapter adapter; /** * Provides access to Cayenne mapping info. * * @since 1.2 */ protected EntityResolver entityResolver; /** * Creates PreparedStatement. logLevel parameter is supplied to allow * control of logging of produced SQL. */ public abstract PreparedStatement createStatement() throws Exception; /** * @deprecated since 1.2 */ public final PreparedStatement createStatement(Level logLevel) throws Exception { return createStatement(); } /** Returns query object being processed. */ public Query getQuery() { return query; } public void setQuery(Query query) { this.query = query; } /** * Returns Connection object used by this translator. * * @since 1.2 */ public Connection getConnection() { return connection; } /** * @since 1.2 */ public void setConnection(Connection connection) { this.connection = connection; } /** * @deprecated Since 1.2 use getConnection(). */ public Connection getCon() { return getConnection(); } /** * @deprecated since 1.2 use setConnection(). */ public void setCon(Connection con) { setConnection(con); } /** * Returns QueryEngine used by this translator. * * @deprecated Since 1.2 use "getEntityResolver()" */ public QueryEngine getEngine() { return engine; } /** * @deprecated Since 1.2 use "setEntityResolver()" */ public void setEngine(QueryEngine engine) { this.engine = engine; } public DbAdapter getAdapter() { return adapter; } public void setAdapter(DbAdapter adapter) { this.adapter = adapter; } /** * Returns an EntityInheritanceTree for the root entity. * * @since 1.1 */ public EntityInheritanceTree getRootInheritanceTree() { return getEntityResolver().lookupInheritanceTree(getRootEntity()); } public ObjEntity getRootEntity() { return query.getMetaData(getEntityResolver()).getObjEntity(); } public DbEntity getRootDbEntity() { return query.getMetaData(getEntityResolver()).getDbEntity(); } /** * @since 1.2 */ public EntityResolver getEntityResolver() { return entityResolver; } /** * @since 1.2 */ public void setEntityResolver(EntityResolver entityResolver) { this.entityResolver = entityResolver; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy