TODO: there may be several entities per table!!!
760854
public EntityConfig getEntityConfigByTableName(String tableName) {
        for (EntityConfig entityConfig : entityConfigs) {
            if (tableName.equalsIgnoreCase(entityConfig.getTableName())) {
                return entityConfig;
            }
        }
        return null;
    }
1181549
private static Iterable<String> getAssociationTables(EntityClass entityClass) {
        Iterable<Settable> association = filter(entityClass.getElements(),
                and(or(has(ManyToMany.class), has(ElementCollection.class)), has(JoinTable.class)));
        return transform(association, new Function<Settable, String>() {
            @Override
            public String apply(Settable input) {
                JoinTable annotation = input.getAnnotation(JoinTable.class);
                return annotation.name();
            }
        });
    }
1223917
public void putEntity(Entity entity) {
        Assert.isTrue(entity.hasTableName(), "Expecting a table name for the entity: " + entity.getName());
        Assert.isTrue(!hasEntityBySchemaAndTableName(entity.getTable().getSchemaName(), entity.getTable().getName()), "Entity was already added!: " + entity.getTableName());
        currentEntitiesByTableName.put(entity.getTable().getName().toUpperCase(), entity);
        currentEntitiesBySchemaAndTableName.put(entity.getTable().asKeyForMap(), entity);
    }
1087989
private void prepareColumn(ThriftRow tr, EntityMetadata m, Object value, byte[] name, long timestamp, int ttl)
    {
        if (value != null)
        {
            if (m.isCounterColumnType())
            {
                CounterColumn counterColumn = prepareCounterColumn((String) value, name);
                tr.addCounterColumn(counterColumn);
            }
            else
            {
                Column column = prepareColumn((byte[]) value, name, timestamp, ttl);
                tr.addColumn(column);
            }
        }
    }
640967
private void validateEntity(final DbEntity entity) throws DatabaseEngineException {
        if (entity.getName() == null || entity.getName().length() == 0) {
            throw new DatabaseEngineException("You have to define the entity name");
        }

        final int maxIdentSize = properties.getMaxIdentifierSize();
        if (entity.getName().length() > maxIdentSize) {
            throw new DatabaseEngineException(String.format("Entity '%s' exceeds the maximum number of characters (%d)", entity.getName(), maxIdentSize));
        }

        if (entity.getColumns().isEmpty()) {
            throw new DatabaseEngineException("You have to specify at least one column");
        }

        int numberOfAutoIncs = 0;
        for (DbColumn c : entity.getColumns()) {
            if (c.getName() == null || c.getName().length() == 0) {
                throw new DatabaseEngineException(String.format("Column in entity '%s' must have a name", entity.getName()));
            }

            if (c.getName().length() > maxIdentSize) {
                throw new DatabaseEngineException(String.format("Column '%s' in entity '%s' exceeds the maximum number of characters (%d)", c.getName(), entity.getName(), maxIdentSize));
            }

            if (c.isAutoInc()) {
                numberOfAutoIncs++;
            }
        }

        if (numberOfAutoIncs > 1) {
            throw new DatabaseEngineException("You can only define one auto incremented column");
        }

        // Index validation

        List<DbIndex> indexes = entity.getIndexes();
        if (!indexes.isEmpty()) {
            for (DbIndex index : indexes) {
                if (index.getColumns().isEmpty()) {
                    throw new DatabaseEngineException(String.format("You have to specify at least one column to create an index in entity '%s'", entity.getName()));
                }

                for (String column : index.getColumns()) {
                    if (column == null || column.length() == 0) {
                        throw new DatabaseEngineException(String.format("Column indexes must have a name in entity '%s'", entity.getName()));
                    }
                }
            }
        }

        // FK validation

        List<DbFk> fks = entity.getFks();
        if (!fks.isEmpty()) {
            for (DbFk fk : fks) {
                if (fk.getForeignTable() == null || fk.getForeignTable().length() == 0) {
                    throw new DatabaseEngineException(String.format("You have to specify the table when creating a Foreign Key in entity '%s'", entity.getName()));
                }

                if (fk.getLocalColumns().isEmpty()) {
                    throw new DatabaseEngineException(String.format("You must specify at least one local column when defining a Foreign Key in '%s'", entity.getName()));
                }

                if (fk.getForeignColumns().isEmpty()) {
                    throw new DatabaseEngineException(String.format("You must specify at least one foreign column when defining a Foreign Key in '%s'", entity.getName()));
                }

                if (fk.getLocalColumns().size() != fk.getForeignColumns().size()) {
                    throw new DatabaseEngineException(String.format("Number of local columns does not match foreign ones in entity '%s'", entity.getName()));
                }
            }
        }
    }
1027107
def is_sub_to_all(self, *super_entities):
        
        if super_entities:
            if len(super_entities) == 1:
                # Optimize for the case of just one super entity since this is a much less intensive query
                has_subset = EntityRelationship.objects.filter(
                    super_entity=super_entities[0]).values_list('sub_entity', flat=True)
            else:
                # Get a list of entities that have super entities with all types
                has_subset = EntityRelationship.objects.filter(
                    super_entity__in=super_entities).values('sub_entity').annotate(Count('super_entity')).filter(
                    super_entity__count=len(set(super_entities))).values_list('sub_entity', flat=True)

            return self.filter(id__in=has_subset)
        else:
            return self
813432
def for_(self, table):
        
        self.args = [param.for_(table) for param in self.args]
482506
@Override
    public List<Object> findByRelation(String colName, Object colValue, Class entityClazz)
    {

        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz);
        Object[] ids = findIdsByColumn(entityMetadata.getTableName(), colName, colValue);
        List<Object> resultSet = new ArrayList<Object>();
        if (ids != null)
        {
            // just to insure uniqueness.

            for (Object id : new HashSet(Arrays.asList(ids)))
            {
                resultSet.add(find(entityClazz, id));
            }
        }

        return resultSet;
    }
734282
function unexpandSubentity(subEntity) {
  if (_.isArray(subEntity)) {
    _.each(subEntity, (entity, index) => {
      subEntity[index] = unexpandSubentity(entity);
    });
  } else {
    _.each(subEntity, (val, propertyName) => {
      if (_.isObject(val) && val.id) {
        subEntity.links = subEntity.links || {};
        subEntity.links[propertyName] = val.id;
        delete subEntity[propertyName];
      }
    });
  }

  return subEntity;
}
93455
private void checkOSMTables(Connection connection, boolean isH2, TableLocation requestedTable, String osmTableName) throws SQLException {
        String[] omsTables = new String[]{OSMTablesFactory.TAG, OSMTablesFactory.NODE, OSMTablesFactory.NODE_TAG, OSMTablesFactory.WAY, OSMTablesFactory.WAY_NODE, 
            OSMTablesFactory.WAY_TAG, OSMTablesFactory.RELATION, OSMTablesFactory.RELATION_TAG, OSMTablesFactory.NODE_MEMBER, OSMTablesFactory.WAY_MEMBER, OSMTablesFactory.RELATION_MEMBER};
        for (String omsTableSuffix : omsTables) {
            String osmTable = TableUtilities.caseIdentifier(requestedTable, osmTableName + omsTableSuffix, isH2);
            if (JDBCUtilities.tableExists(connection, osmTable)) {
                throw new SQLException("The table " + osmTable + " already exists.");
            }
        }
    }
905821
public Multimap<String, String> listCorpusAlias(File databaseProperties)
  {
    Multimap<String, String> result = TreeMultimap.create();

    DataSource origDataSource = getDataSource().getInnerDataSource();
    try
    {
      if (databaseProperties != null)
      {
        getDataSource().setInnerDataSource(createDataSource(databaseProperties));
      }
      result = getJdbcTemplate().query(
        "SELECT a.alias AS alias, c.name AS corpus\n"
        + "FROM corpus_alias AS a, corpus AS c\n" + "WHERE\n"
        + " a.corpus_ref = c.id",
        new ResultSetExtractor<Multimap<String, String>>()
        {

          @Override
          public Multimap<String, String> extractData(ResultSet rs) throws
          SQLException,
          DataAccessException
          {
            Multimap<String, String> data = TreeMultimap.create();
            while (rs.next())
            {
              // alias -> corpus name
              data.put(rs.getString(1), rs.getString(2));
            }
            return data;
          }
        });

    }
    catch (IOException | URISyntaxException | DataAccessException ex)
    {
      if (databaseProperties == null)
      {
        log.error(
          "Could not query corpus list", ex);
      }
      else
      {
        log.error(
          "Could not query corpus list for the file " + databaseProperties.
          getAbsolutePath(), ex);
      }
    }
    finally
    {
      getDataSource().setInnerDataSource(origDataSource);
    }

    return result;
  }
21132
public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName,
            Object columnValue, Class entityClazz)
    {
        // TODO Auto-generated method stub
        return null;
    }
956430
@Override
    public Object[] findIdsByColumn(String schemaName, String tableName, String pKeyName, String columnName,
            Object columnValue, Class entityClazz)
    {
        EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz);

        byte[] valueInBytes = HBaseUtils.getBytes(columnValue);
        Filter f = new SingleColumnValueFilter(Bytes.toBytes(tableName), Bytes.toBytes(columnName), CompareOp.EQUAL,
                valueInBytes);
        KeyOnlyFilter keyFilter = new KeyOnlyFilter();
        FilterList filterList = new FilterList(f, keyFilter);
        try
        {
            return handler.scanRowyKeys(filterList, schemaName, tableName, columnName + "_" + columnValue, m
                    .getIdAttribute().getBindableJavaType());
        }
        catch (IOException e)
        {
            log.error("Error while executing findIdsByColumn(), Caused by: .", e);
            throw new KunderaException(e);
        }
    }
1101042
function _columns() {
    var distinct = false;
    if (this.onlyUnions()) {
      return '';
    }
    var columns = this.grouped.columns || [];
    var i = -1,
        sql = [];
    if (columns) {
      while (++i < columns.length) {
        var stmt = columns[i];
        if (stmt.distinct) {
          distinct = true;
        }
        if (stmt.type === 'aggregate') {
          sql.push(this.aggregate(stmt));
        } else if (stmt.value && stmt.value.length > 0) {
          sql.push(this.formatter.columnize(stmt.value));
        }
      }
    }
    if (sql.length === 0) {
      sql = ['*'];
    }
    return 'select ' + (distinct ? 'distinct ' : '') + sql.join(', ') + (this.tableName ? ' from ' + this.tableName : '');
  }
428988
public List<Entity> findAll(String tableName) throws SQLException {
		return findAll(Entity.create(tableName));
	}
957205
public int update(List<ENTITY> entities) {

        if (entities == null || entities.size() == 0) {
            recordLog(" param entity is null!");
            return 0;
        }

        final List<Query> queries = queryGenerator.getUpdateQuery(entities);
        String sql = queries.get(0).getSql();
        jdbcTemplate.batchUpdate(sql, new BatchPreparedStatementSetter() {

            public void setValues(PreparedStatement stmt, int index) throws SQLException {
                int i = 1;
                List<Object> params = queries.get(index).getParams();
                for (Object o : params) {
                    stmt.setObject(i++, o);
                }
            }

            public int getBatchSize() {
                return queries.size();
            }
        });

        return entities.size();
    }
1334379
@Override
    public synchronized void updateEntity(DbEntity entity) throws DatabaseEngineException {
        super.updateEntity(entity);
        try (Statement reorg = conn.createStatement()) {
            reorg.executeUpdate(reorg(entity.getName()));
        } catch (final SQLException e) {
            throw new DatabaseEngineException("Error reorganizing table '" + entity.getName() + "'", e);
        }
    }