Get the relations to the base table and related table

@param baseTable
base table name
@param relatedTable
related table name
@return extended relations
@throws SQLException
upon failure
@since 3.2.0
551999
public List<ExtendedRelation> getRelations(String baseTable,
			String relatedTable) throws SQLException {
		return getRelations(baseTable, null, relatedTable, null, null, null);
	}
941640
public Map<String, Object> getRelations()
    {
        return relations != null ? Collections.unmodifiableMap(relations) : null;
    }
176573
public Touple<SQLProperty, String, SQLiteEntity, SQLRelationType> findRelationByParentProperty(
			String parentFieldName) {
		for (Touple<SQLProperty, String, SQLiteEntity, SQLRelationType> item : relations) {
			if (item.value0.getName().equals(parentFieldName)) {
				return item;
			}
		}

		return null;
	}
572757
@Override
    public <E> List<E> getColumnsById(String schemaName, String joinTableName, String joinColumnName,
            String inverseJoinColumnName, Object parentId, Class columnJavaType)
    {
        List<Object> foreignKeys = new ArrayList<Object>();

        if (getCqlVersion().equalsIgnoreCase(CassandraConstants.CQL_VERSION_3_0))
        {
            foreignKeys = getColumnsByIdUsingCql(schemaName, joinTableName, joinColumnName, inverseJoinColumnName,
                    parentId, columnJavaType);
        }
        else
        {
            Selector selector = clientFactory.getSelector(pool);

            List<Column> columns = selector.getColumnsFromRow(joinTableName,
                    Bytes.fromByteArray(PropertyAccessorHelper.getBytes(parentId)),
                    Selector.newColumnsPredicateAll(true, 10), getConsistencyLevel());

            foreignKeys = dataHandler.getForeignKeysFromJoinTable(inverseJoinColumnName, columns, columnJavaType);

            if (log.isInfoEnabled())
            {
                log.info("Returning number of keys from join table", foreignKeys != null ? foreignKeys.size() : null);
            }
        }
        return (List<E>) foreignKeys;
    }
379710
private Connection getConnection() throws JspException, SQLException {
	// Fix: Add all other mechanisms
	Connection conn = null;
	isPartOfTransaction = false;

        TransactionTagSupport parent = (TransactionTagSupport)
	    findAncestorWithClass(this, TransactionTagSupport.class);
	if (parent != null) {
            if (dataSourceSpecified) {
                throw new JspTagException(
                    Resources.getMessage("ERROR_NESTED_DATASOURCE"));
            }
	    conn = parent.getSharedConnection();
            isPartOfTransaction = true;
	} else {
	    if ((rawDataSource == null) && dataSourceSpecified) {
		throw new JspException(
		    Resources.getMessage("SQL_DATASOURCE_NULL"));
	    }
	    DataSource dataSource = DataSourceUtil.getDataSource(rawDataSource,
								 pageContext);
            try {
                conn = dataSource.getConnection();
            } catch (Exception ex) {
                throw new JspException(
                    Resources.getMessage("DATASOURCE_INVALID",
					 ex.toString()));
            }
	}

	return conn;
    }
548537
private static void getForeignKeys(DatabaseMetaData md, DatabaseRelationDefinition relation, DBMetadata metadata) throws SQLException {

		QuotedIDFactory idfac = metadata.getQuotedIDFactory();

		RelationID relationId = relation.getID();
		try (ResultSet rs = md.getImportedKeys(null, relationId.getSchemaName(), relationId.getTableName())) {
            extractForeignKeys(relation, metadata, idfac, rs);
        }
        catch (Exception ex) {
            try (ResultSet rs = md.getImportedKeys(relationId.getSchemaName(),null, relationId.getTableName())) {
                extractForeignKeys(relation, metadata, idfac, rs);
            }
        }
	}
1210855
public List<Long> getMappingsForRelated(String tableName, long relatedId) {

		List<Long> baseIds = new ArrayList<>();

		UserMappingDao userMappingDao = getMappingDao(tableName);
		UserCustomResultSet resultSet = userMappingDao
				.queryByRelatedId(relatedId);
		try {
			while (resultSet.moveToNext()) {
				UserMappingRow row = userMappingDao.getRow(resultSet);
				baseIds.add(row.getBaseId());
			}
		} finally {
			resultSet.close();
		}

		return baseIds;
	}
615255
private Set<Resource> fetchRelationFromEntity(IncludeRequest request, List<Resource> sourceResources, ResourceField
			relationshipField, boolean allowLookup, boolean fetchRelatedEntity, boolean mustInclude) {
		Set<Resource> loadedResources = new HashSet<>();
		for (Resource sourceResource : sourceResources) {
			ResourceIdentifier id = sourceResource.toIdentifier();

			Object sourceEntity = request.getEntity(id);
			if (sourceEntity != null && !(sourceEntity instanceof Resource)) {

				Object relatedEntity = null;
				if (fetchRelatedEntity) {
					relatedEntity = relationshipField.getAccessor().getValue(sourceEntity);
					if (!allowLookup && Iterable.class.isAssignableFrom(relationshipField.getType()) && relatedEntity == null) {
						// note that single-valued relations are allowed to be null
						throw new InternalServerErrorException(
								id + " relationship field collection '" + relationshipField.getJsonName()
										+ "' can not be null. Either set the relationship as an empty "
										+ Iterable.class.getCanonicalName() + " or use LookupIncludeBehavior.AUTOMATICALLY_ALWAYS");
					}
				}

				// attempt to work with full relationship and fallback to relationshipId where possible
				if (relatedEntity != null) {
					List<Resource> relatedResources =
							request.setupRelation(sourceResource, relationshipField, relatedEntity);
					loadedResources.addAll(relatedResources);
				} else if (relationshipField.hasIdField()) {
					Object relatedEntityID = relationshipField.getIdAccessor().getValue(sourceEntity);
					request.setupRelationId(sourceResource, relationshipField, relatedEntityID);
					if (fetchRelatedEntity && relatedEntityID != null && !allowLookup && mustInclude) {
						throw new IllegalStateException("inconsistent relationship '" + relationshipField.getUnderlyingName()
								+ "' for " + id + ", id "
								+ "set to " + relatedEntityID + ", but related object is null and lookup disabled");
					}
				}
			}
		}
		return loadedResources;
	}
378632
public String getRelationshipName()
    {
        String ret;
        if (tableAB == null /* && multipleRelationsBetweenTables */)
        {
            ret = concatenateColumnNames(this);
            ret = ret.substring(1); // remove leading _.
        }
        else // Many-to-Many relationship
        {
            ForeignKey[] fks = tableAB.getForeignKeys().values().toArray(new ForeignKey[2]);
            ret = ForeignKey.concatenateColumnNames(fks[1]).substring(1);
        }

        String multiplicity = getTableBMultiplicity();
        if (!multiplicity.equals("one"))
            ret = StringUtility.englishPluralize(ret);
        return ret;
    }
531970
public function getRelationTable()
    {
        if (is_null($this->relationTable)) {
            $parentTable = $this->getParentTableName();
            $table = $this->getEntityDescriptor()->getTableName();
            $names = [$parentTable, $table];
            asort($names);
            $first = array_shift($names);
            $tableName = $this->normalizeFieldName($first);
            array_unshift($names, $tableName);
            $this->relationTable = implode('_', $names);
        }
        return $this->relationTable;
    }
649894
private function _getJunctionTableColumns($relationName, $model)
    {
        $junctionTableColumns = [];
        if (array_key_exists($relationName, $this->_relationsExtraColumns)) {
            if (is_callable($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName]($model);
            } elseif (is_array($this->_relationsExtraColumns[$relationName])) {
                $junctionTableColumns = $this->_relationsExtraColumns[$relationName];
            }
            if (!is_array($junctionTableColumns)) {
                throw new RuntimeException(
                    'Junction table columns definition must return an array, got ' . gettype($junctionTableColumns)
                );
            }
        }
        return $junctionTableColumns;
    }
189732
public List<Relationship> getRelatedRelationships() {
        final List<Relationship> relatedRelationships = new LinkedList<Relationship>();
        for (final Relationship r : relationships) {
            if (r.getType() == RelationshipType.REFER_TO) {
                relatedRelationships.add(r);
            }
        }
        return relatedRelationships;
    }
147815
public static Set<String> getColumnNames(DriverTypeEnum.ConnectionProperties theConnectionProperties, String theTableName) throws SQLException {
		DataSource dataSource = Objects.requireNonNull(theConnectionProperties.getDataSource());
		try (Connection connection = dataSource.getConnection()) {
			return theConnectionProperties.getTxTemplate().execute(t -> {
				DatabaseMetaData metadata;
				try {
					metadata = connection.getMetaData();
					ResultSet indexes = metadata.getColumns(connection.getCatalog(), connection.getSchema(), massageIdentifier(metadata, theTableName), null);

					Set<String> columnNames = new HashSet<>();
					while (indexes.next()) {
						String tableName = toUpperCase(indexes.getString("TABLE_NAME"), Locale.US);
						if (!theTableName.equalsIgnoreCase(tableName)) {
							continue;
						}

						String columnName = indexes.getString("COLUMN_NAME");
						columnName = toUpperCase(columnName, Locale.US);
						columnNames.add(columnName);
					}

					return columnNames;
				} catch (SQLException e) {
					throw new InternalErrorException(e);
				}
			});
		}
	}
558831
def get_relations(self, cursor, table_name):
        
        cursor.execute(self._get_relations_query, {
            'schema': self.connection.schema_name,
            'table': table_name
        })
        relations = {}
        for row in cursor.fetchall():
            relations[row[1]] = (row[2], row[0])

        return relations
1198233
public List<Connection> getConnections(final ConnectionMode connectionMode, final String dataSourceName, final int connectionSize) throws SQLException {
        if (stateHandler.isInTransaction()) {
            return getConnectionsWithTransaction(connectionMode, dataSourceName, connectionSize);
        } else {
            return getConnectionsWithoutTransaction(connectionMode, dataSourceName, connectionSize);
        }
    }
753819
public function from($table, ...$tables)
    {
        array_unshift($tables, $table);

        foreach ($tables as $table) {
            list($tableAlias, $tableName) = $this->dialect()->parseTable($table);

            if ($tableName instanceof SelectQuery) {
                if (!$tableAlias) {
                    throw new SqlException('FROM derived table should have an alias name.');
                }

                $tableKey = $tableAlias;
            } else {
                $tableKey = $tableAlias ?: $tableName;

                $tableName = $this->dialect()->quoteTable($tableName);
            }

            if ($tableAlias) {
                $tableAlias = $this->dialect()->quoteName($tableAlias);
            }

            $this->addFrom($tableKey, $tableName, $tableAlias);
        }

        return $this;
    }
1331979
private void createStyleRelationship(String mappingTableName,
			String featureTable, String baseTable, String relatedTable) {

		if (!hasStyleRelationship(mappingTableName, baseTable, relatedTable)) {

			// Create the extension
			getOrCreate(featureTable);

			if (baseTable.equals(ContentsId.TABLE_NAME)) {
				if (!contentsId.has()) {
					contentsId.getOrCreateExtension();
				}
			}

			StyleMappingTable mappingTable = new StyleMappingTable(
					mappingTableName);

			if (relatedTable.equals(StyleTable.TABLE_NAME)) {
				relatedTables.addAttributesRelationship(baseTable,
						new StyleTable(), mappingTable);
			} else {
				relatedTables.addMediaRelationship(baseTable, new IconTable(),
						mappingTable);
			}
		}

	}