Android Open Source - DKO Sql Context






From Project

Back to project page DKO.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project DKO listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.kered.dko;
/* w w w . j av  a2  s . com*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.kered.dko.Constants.DB_TYPE;
import org.kered.dko.DBQuery.JoinInfo;
import org.kered.dko.TemporaryTableFactory.DummyTableWithName;

class SqlContext {

  private final DBQuery<?> q;

  SqlContext(final DBQuery<?> q) {
    this(q, null);
  }

  public SqlContext(final DBQuery<?> q, final SqlContext parentContext) {
    tableNameMap = q.tableNameMap;
    tableInfos = new ArrayList<TableInfo>(q.tableInfos);
    for (final JoinInfo join : q.joins) tableInfos.add(join.reffedTableInfo);
    for (final JoinInfo join : q.joinsToOne) tableInfos.add(join.reffedTableInfo);
    for (final JoinInfo join : q.joinsToMany) tableInfos.add(join.reffingTableInfo);
    this.parentContext = parentContext;
    dbType = parentContext == null ? q.getDBType() : parentContext.dbType;
    this.q = q;
  }
  
  public SqlContext(DB_TYPE dbType) {
    this.dbType = dbType;
    q = null;
    tableInfos = new ArrayList<TableInfo>();
  }

  Map<String, Set<String>> tableNameMap = null;
  List<TableInfo> tableInfos = null;
  DB_TYPE dbType = null;
  SqlContext parentContext = null;
  Map<Field,String> fieldNameOverrides = null;
  public int maxFields = Integer.MAX_VALUE;

  boolean inInnerQuery() {
    return parentContext != null;
  }

  DBQuery<?> getRootQuery() {
    if (parentContext != null) return parentContext.getRootQuery();
    return q;
  }

  String getFullTableName(final TableInfo ti) {
    if (ti.dummyTable != null) {
      return dbType==Constants.DB_TYPE.SQLSERVER ? "#"+ti.dummyTable.name : ti.dummyTable.name;
    }
    return getFullTableName(ti.tableClass);
  }

  String getFullTableName(final Class<? extends Table> tableClass) {
    final StringBuilder sb = new StringBuilder();
    String schema = Util.getSchemaName(tableClass);
    if (schema != null && !"".equals(schema)) {
      schema = Context.getSchemaToUse(getRootQuery().getDataSource(), schema);
      if (schema != null && !"".equals(schema)) {
        sb.append(schema);
        sb.append(dbType==Constants.DB_TYPE.SQLSERVER ? ".dbo." : ".");
      }
    }
    sb.append(Util.getTableName(tableClass));
    return sb.toString();
  }

  Set<String> getPossibleTableMatches(Class<? extends Table> table) {
    Set<String> names = new HashSet<String>();
    if (q!=null && q.tableInfos!=null) {
      for (TableInfo ti : q.tableInfos) {
        if (table.equals(ti.tableClass)) names.add(ti.tableName);
      }
    }
    if (q!=null && q.joins!=null) {
      for (JoinInfo ji : q.joins) {
        if (table.equals(ji.reffedTableInfo.tableClass)) names.add(ji.reffedTableInfo.tableName);
        if (table.equals(ji.reffingTableInfo.tableClass)) names.add(ji.reffingTableInfo.tableName);
      }
    }
    if (q!=null && q.joinsToOne!=null) {
      for (JoinInfo ji : q.joinsToOne) {
        if (table.equals(ji.reffedTableInfo.tableClass)) names.add(ji.reffedTableInfo.tableName);
        if (table.equals(ji.reffingTableInfo.tableClass)) names.add(ji.reffingTableInfo.tableName);
      }
    }
    if (q!=null && q.joinsToMany!=null) {
      for (JoinInfo ji : q.joinsToMany) {
        if (table.equals(ji.reffedTableInfo.tableClass)) names.add(ji.reffedTableInfo.tableName);
        if (table.equals(ji.reffingTableInfo.tableClass)) names.add(ji.reffingTableInfo.tableName);
      }
    }
    return names;
  }

  public void setFieldNameOverride(Field<?> key, String value) {
    if (fieldNameOverrides==null) fieldNameOverrides = new HashMap<Field,String>();
    fieldNameOverrides.put(key, value);
  }
  
}




Java Source Code List

.HelloWorld.java
org.kered.contactlensfinder.DB.java
org.kered.contactlensfinder.MainActivity.java
org.kered.contactlensfinder.ViewManufacturersActivity.java
org.kered.contactlensfinder.ViewProductsActivity.java
org.kered.contactlensfinder.ViewPropertiesActivity.java
org.kered.dko.AbstractQuery.java
org.kered.dko.Bulk.java
org.kered.dko.CSV.java
org.kered.dko.ClosableIterator.java
org.kered.dko.Condition.java
org.kered.dko.Constants.java
org.kered.dko.Context.java
org.kered.dko.DBQuery.java
org.kered.dko.DBRowIterator.java
org.kered.dko.Diff.java
org.kered.dko.DualIterator.java
org.kered.dko.Expression.java
org.kered.dko.Field.java
org.kered.dko.FilteringQuery.java
org.kered.dko.Function.java
org.kered.dko.InMemoryQuery.java
org.kered.dko.Join.java
org.kered.dko.LazyCacheIterable.java
org.kered.dko.LocalJoin.java
org.kered.dko.M.java
org.kered.dko.Main.java
org.kered.dko.MatryoshkaQuery.java
org.kered.dko.PeekableClosableIterator.java
org.kered.dko.PeekableIterator.java
org.kered.dko.QueryAddField.java
org.kered.dko.QueryFactory.java
org.kered.dko.QuerySnapshot.java
org.kered.dko.Query.java
org.kered.dko.SQLFunction.java
org.kered.dko.SelectAsMapIterable.java
org.kered.dko.SelectFromOAI.java
org.kered.dko.SelectSingleColumn.java
org.kered.dko.SoftJoinUtil.java
org.kered.dko.SoftJoin.java
org.kered.dko.SqlContext.java
org.kered.dko.Statistics.java
org.kered.dko.SubQueryField.java
org.kered.dko.TableInfo.java
org.kered.dko.TableWrapper.java
org.kered.dko.Table.java
org.kered.dko.TemporaryTableFactory.java
org.kered.dko.TmpTableBuilder.java
org.kered.dko.Tuple.java
org.kered.dko.UsageMonitor.java
org.kered.dko.UsageStats.java
org.kered.dko.Util.java
org.kered.dko.ant.ClassGenerator.java
org.kered.dko.ant.CodeGeneratorBase.java
org.kered.dko.ant.CodeGenerator.java
org.kered.dko.ant.DataSourceGenerator.java
org.kered.dko.ant.GsonGenerator.java
org.kered.dko.ant.JoinGenerator.java
org.kered.dko.ant.Main.java
org.kered.dko.ant.SchemaExtractorBase.java
org.kered.dko.ant.SchemaExtractor.java
org.kered.dko.ant.Util.java
org.kered.dko.datasource.CheapConnectionPoolingDataSource.java
org.kered.dko.datasource.ConnectionCountingDataSource.java
org.kered.dko.datasource.JDBCDriverDataSource.java
org.kered.dko.datasource.MatryoshkaDataSource.java
org.kered.dko.datasource.MirroredDataSource.java
org.kered.dko.datasource.ReflectedDataSource.java
org.kered.dko.datasource.SingleConnectionDataSource.java
org.kered.dko.datasource.SingleThreadedDataSource.java
org.kered.dko.datasource.UnClosableConnection.java
org.kered.dko.datasource.Util.java
org.kered.dko.json.CDL.java
org.kered.dko.json.CookieList.java
org.kered.dko.json.Cookie.java
org.kered.dko.json.HTTPTokener.java
org.kered.dko.json.HTTP.java
org.kered.dko.json.JSONArray.java
org.kered.dko.json.JSONException.java
org.kered.dko.json.JSONML.java
org.kered.dko.json.JSONObject.java
org.kered.dko.json.JSONString.java
org.kered.dko.json.JSONStringer.java
org.kered.dko.json.JSONTokener.java
org.kered.dko.json.JSONWriter.java
org.kered.dko.json.Pickle.java
org.kered.dko.json.XMLTokener.java
org.kered.dko.json.XML.java
org.kered.dko.junk.DerbyLoadTestSchema.java
org.kered.dko.junk.OracleCreateTestUser.java
org.kered.dko.junk.OracleLoadTestSchema.java
org.kered.dko.persistence.Util.java
org.kered.dko.util.DumpDatabase.java
sakila.Example0.java
sakila.Example1.java
sakila.Example2.java
sakila.Util.java