Java Code Examples for org.eclipse.collections.api.list.ImmutableList#collect()
The following examples show how to use
org.eclipse.collections.api.list.ImmutableList#collect() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MsSqlMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaRule> searchRules(final DaSchema schema, Connection conn) throws SQLException { // Do not use ANSI JOIN as it does not work in Sybase 11.x - the SQL below works across all versions String sql = "SELECT rul.name as RULE_NAME\n" + "FROM " + schema.getName() + "..sysobjects rul\n" + " , sys.schemas sch\n" + "WHERE rul.type = 'R'\n" + " and rul.uid = sch.schema_id and sch.name = '" + schema.getSubschemaName() + "' " + "and not exists (\n" + "\t-- Ensure that the entry is not attached to a table; otherwise, it is a regular table constraint, and will already be dropped when the table is dropped\n" + "\tselect 1 from " + schema.getName() + "..sysconstraints c\n" + "\twhere c.constid = rul.id\n" + ")\n"; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler())).toImmutable(); return maps.collect(map -> new DaRuleImpl((String) map.get("RULE_NAME"), schema)); }
Example 2
Source File: HsqlMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) throws SQLException { ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, "select dom.DOMAIN_NAME AS USER_TYPE_NAME\n" + "from INFORMATION_SCHEMA.DOMAINS dom\n" + "WHERE dom.DOMAIN_SCHEMA = ucase('" + schema.getName() + "')\n", new MapListHandler() )).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaUserType>() { @Override public DaUserType valueOf(Map<String, Object> map) { return new DaUserTypeImpl((String) map.get("USER_TYPE_NAME"), schema); } }); }
Example 3
Source File: PostgresqlMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) { String sql = "SELECT t.typname \n" + "FROM pg_type t \n" + "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace \n" + "WHERE (t.typrelid = 0 OR (SELECT c.relkind = 'c' FROM pg_catalog.pg_class c WHERE c.oid = t.typrelid)) \n" + "AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n" + "AND n.nspname IN ('" + schema.getName() + "')"; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler())).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaUserType>() { @Override public DaUserType valueOf(Map<String, Object> map) { return new DaUserTypeImpl((String) map.get("typname"), schema); } }); }
Example 4
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaRule> searchRules(final DaSchema schema, Connection conn) throws SQLException { // Do not use ANSI JOIN as it does not work in Sybase 11.x - the SQL below works across all versions ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, "SELECT rul.name as RULE_NAME\n" + "FROM " + schema.getName() + "..sysobjects rul\n" + " , " + schema.getName() + "..sysusers sch\n" + "WHERE rul.type = 'R'\n" + " and rul.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "' " + "and not exists (\n" + "\t-- Ensure that the entry is not attached to a table; otherwise, it is a regular table constraint, and will already be dropped when the table is dropped\n" + "\tselect 1 from " + schema.getName() + "..sysconstraints c\n" + "\twhere c.constrid = rul.id\n" + ")\n", new MapListHandler() )).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaRule>() { @Override public DaRule valueOf(Map<String, Object> map) { return new DaRuleImpl((String) map.get("RULE_NAME"), schema); } }); }
Example 5
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 6 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) throws SQLException { ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, "SELECT s1.name as USER_TYPE_NAME\n" + "FROM " + schema.getName() + "..systypes s1\n" + " , " + schema.getName() + "..sysusers sch\n" + "WHERE s1.usertype>100 " + "AND s1.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "' " , new MapListHandler() )).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaUserType>() { @Override public DaUserType valueOf(Map<String, Object> map) { return new DaUserTypeImpl((String) map.get("USER_TYPE_NAME"), schema); } }); }
Example 6
Source File: DateFormatterPostParsedSqlTranslator.java From obevo with Apache License 2.0 | 5 votes |
/** * Creates the translator based on the input format strings in JDK format. We take in the strings here so that we * can convert to ThreadLocal underneath the hood. (Joda Time could be an alternative, but the existing unit tests * on this class need to pass). */ public DateFormatterPostParsedSqlTranslator(ImmutableList<String> dateFormatStrings) { this.dateFormats = dateFormatStrings.collect(new Function<String, ThreadLocal<DateFormat>>() { @Override public ThreadLocal<DateFormat> valueOf(final String dateFormat) { return new ThreadLocal<DateFormat>() { @Override protected DateFormat initialValue() { return new SimpleDateFormat(dateFormat); } }; } }); }
Example 7
Source File: OracleMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) { String sql = "SELECT TYPE_NAME " + "FROM ALL_TYPES " + "WHERE OWNER = '" + schema.getName() + "'"; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler())).toImmutable(); return maps.collect(new Function<Map<String, Object>, DaUserType>() { @Override public DaUserType valueOf(Map<String, Object> map) { return new DaUserTypeImpl((String) map.get("TYPE_NAME"), schema); } }); }
Example 8
Source File: MsSqlMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<DaRoutine> searchExtraRoutines(final DaSchema schema, String procedureName, Connection conn) throws SQLException { String nameClause = procedureName != null ? " and ROUTINE_NAME = '" + procedureName + "'\n" : " "; String query = "SELECT" + " ROUTINE_CATALOG," + " ROUTINE_SCHEMA," + " ROUTINE_NAME," + " SPECIFIC_NAME," + " ROUTINE_TYPE," + " OBJECT_DEFINITION(OBJECT_ID(ROUTINE_CATALOG + '.' + ROUTINE_SCHEMA + '.' + ROUTINE_NAME)) AS ROUTINE_DEFINITION" + " FROM INFORMATION_SCHEMA.ROUTINES" + " WHERE ROUTINE_CATALOG = '" + schema.getName() + "'" + " AND ROUTINE_SCHEMA = '" + schema.getSubschemaName() + "'" + nameClause; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, query, new MapListHandler())).toImmutable(); return maps.collect(object -> { DaRoutineType routineType = DaRoutineType.valueOf(((String) object.get("ROUTINE_TYPE")).toLowerCase()); return new DaRoutinePojoImpl( (String) object.get("ROUTINE_NAME"), schema, routineType, (String) object.get("SPECIFIC_NAME"), (String) object.get("ROUTINE_DEFINITION") ); }); }
Example 9
Source File: MsSqlMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<DaUserType> searchUserTypes(final DaSchema schema, Connection conn) throws SQLException { String sql = "SELECT DOMAIN_NAME as USER_TYPE_NAME " + "FROM INFORMATION_SCHEMA.DOMAINS " + "WHERE DOMAIN_CATALOG = '" + schema.getName() + "' " + "AND DOMAIN_SCHEMA = '" + schema.getSubschemaName() + "'"; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler())).toImmutable(); return maps.collect(map -> new DaUserTypeImpl((String) map.get("USER_TYPE_NAME"), schema)); }
Example 10
Source File: Db2MetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<DaRoutine> searchExtraRoutines(final DaSchema schema, String procedureName, Connection conn) throws SQLException { String procedureClause = procedureName == null ? "" : " AND R.ROUTINENAME = '" + procedureName + "'"; final String sql = "SELECT ROUTINENAME, SPECIFICNAME, TEXT FROM SYSCAT.ROUTINES R WHERE R.ROUTINETYPE = 'F'\n" + "AND R.ROUTINESCHEMA = '" + schema.getName() + "'\n" + procedureClause; LOG.debug("Executing function metadata query SQL: {}", sql); ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, sql, new MapListHandler() )).toImmutable(); if (LOG.isDebugEnabled()) { LOG.debug("Results:"); for (Map<String, Object> map : maps) { LOG.debug("ROW: {}", map.toString()); } } return maps.collect(map -> new DaRoutinePojoImpl( (String) map.get("ROUTINENAME"), schema, DaRoutineType.function, (String) map.get("SPECIFICNAME"), clobToString((Clob) map.get("TEXT")) )); }
Example 11
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<ExtraIndexInfo> searchExtraConstraintIndices(DaSchema schema, String tableName, Connection conn) throws SQLException { // Do not use ANSI JOIN as it does not work in Sybase 11.x - the SQL below works across all versions String tableClause = tableName == null ? "" : " AND tab.name = '" + tableName + "'"; ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, "select tab.name TABLE_NAME, ind.name INDEX_NAME, status2 & 8 IS_CONSTRAINT, status2 & 512 IS_CLUSTERED " + "from " + schema.getName() + "..sysindexes ind" + ", " + schema.getName() + "..sysobjects tab " + ", " + schema.getName() + "..sysusers sch " + "where ind.id = tab.id " + "and tab.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n" + tableClause, new MapListHandler() )).toImmutable(); return maps.collect(new Function<Map<String, Object>, ExtraIndexInfo>() { @Override public ExtraIndexInfo valueOf(Map<String, Object> map) { return new ExtraIndexInfo( (String) map.get("TABLE_NAME"), (String) map.get("INDEX_NAME"), (Integer) map.get("IS_CONSTRAINT") != 0, (Integer) map.get("IS_CLUSTERED") != 0 ); } }); }
Example 12
Source File: AbstractEnvironmentEnricher.java From obevo with Apache License 2.0 | 5 votes |
@Override public ImmutableCollection<E> readSystem(final HierarchicalConfiguration sysCfg, final FileObject sourcePath) { final Platform systemDbPlatform = dbPlatformConfiguration.valueOf(sysCfg.getString("type")); // Check for dbEnvironments first for backwards-compatibility ImmutableList<HierarchicalConfiguration> envConfigs = iterConfigMutable(sysCfg, "environments.dbEnvironment"); if (envConfigs.isEmpty()) { envConfigs = iterConfigMutable(sysCfg, "environments.environment"); } ImmutableList<E> envList = envConfigs.collect(new Function<HierarchicalConfiguration, E>() { @Override public E valueOf(HierarchicalConfiguration envCfg) { E dbEnv = AbstractEnvironmentEnricher.this.createNewEnv(); // combining the sys and env configurations before passing to downstream methods so that we can support only having env configs passed in CombinedConfiguration combinedConfiguration = new CombinedConfiguration(new OverrideCombiner()); combinedConfiguration.addConfiguration(envCfg); combinedConfiguration.addConfiguration(sysCfg); combinedConfiguration.setExpressionEngine(sysCfg.getExpressionEngine()); AbstractEnvironmentEnricher.this.enrich(dbEnv, combinedConfiguration, sourcePath, systemDbPlatform); AbstractEnvironmentEnricher.this.createEnv(dbEnv, combinedConfiguration, systemDbPlatform); return dbEnv; } }); CollectionUtil.verifyNoDuplicates(envList, new Function<E, Object>() { @Override public Object valueOf(E e) { return e.getName(); } }, "Invalid configuration from " + sourcePath + "; not expecting duplicate env names"); return envList; }
Example 13
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 4 votes |
@Override public ImmutableCollection<ExtraRerunnableInfo> searchExtraViewInfo(DaSchema schema, String tableName, Connection conn) throws SQLException { String query = String.format("select obj.name name, com.number number, colid2 colid2, colid colid, text text\n" + "from %1$s..syscomments com\n" + ", %1$s..sysobjects obj\n" + " , " + schema.getName() + "..sysusers sch\n" + "where com.id = obj.id\n" + "and com.texttype = 0\n" + "and obj.type in ('V')\n" + "and obj.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n" + "order by com.id, number, colid2, colid\n", schema.getName()); ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, query, new MapListHandler())).toImmutable(); ImmutableList<ExtraRerunnableInfo> viewInfos = maps.collect(new Function<Map<String, Object>, ExtraRerunnableInfo>() { @Override public ExtraRerunnableInfo valueOf(Map<String, Object> object) { return new ExtraRerunnableInfo( (String) object.get("name"), null, (String) object.get("text"), null, ((Integer) object.get("colid2")).intValue(), ((Integer) object.get("colid")).intValue() ); } }); return viewInfos.groupBy(ExtraRerunnableInfo.TO_NAME).multiValuesView().collect(new Function<RichIterable<ExtraRerunnableInfo>, ExtraRerunnableInfo>() { @Override public ExtraRerunnableInfo valueOf(RichIterable<ExtraRerunnableInfo> objectInfos) { MutableList<ExtraRerunnableInfo> sortedInfos = objectInfos.toSortedList(Comparators.fromFunctions(ExtraRerunnableInfo.TO_ORDER2, ExtraRerunnableInfo.TO_ORDER1)); StringBuilder definitionString = sortedInfos.injectInto(new StringBuilder(), new Function2<StringBuilder, ExtraRerunnableInfo, StringBuilder>() { @Override public StringBuilder value(StringBuilder sb, ExtraRerunnableInfo rerunnableInfo) { return sb.append(rerunnableInfo.getDefinition()); } }); return new ExtraRerunnableInfo( sortedInfos.get(0).getName(), null, definitionString.toString() ); } }).toList().toImmutable(); }
Example 14
Source File: SybaseAseMetadataDialect.java From obevo with Apache License 2.0 | 4 votes |
@Override public ImmutableCollection<DaRoutine> searchExtraRoutines(final DaSchema schema, String procedureName, Connection conn) throws SQLException { String nameClause = procedureName != null ? "and obj.name = '" + procedureName + "'\n" : ""; String query = String.format("select obj.name name, obj.type type, com.number number, colid2 colid2, colid colid, text text\n" + "from %1$s..syscomments com\n" + ", %1$s..sysobjects obj\n" + " , " + schema.getName() + "..sysusers sch\n" + "where com.id = obj.id\n" + "and com.texttype = 0\n" + "and obj.uid = sch.uid and sch.name = '" + schema.getSubschemaName() + "'\n" + "and obj.type in ('SF', 'P')\n" + nameClause + "order by com.id, number, colid2, colid\n", schema.getName()); ImmutableList<Map<String, Object>> maps = ListAdapter.adapt(jdbc.query(conn, query, new MapListHandler())).toImmutable(); ImmutableList<ExtraRerunnableInfo> routineInfos = maps.collect(new Function<Map<String, Object>, ExtraRerunnableInfo>() { @Override public ExtraRerunnableInfo valueOf(Map<String, Object> object) { String basename = (String) object.get("name"); int number = ((Integer) object.get("number")).intValue(); String specificName = number > 1 ? basename + ";" + number : basename; return new ExtraRerunnableInfo( basename, specificName, (String) object.get("text"), ((String) object.get("type")).trim(), ((Integer) object.get("colid2")).intValue(), ((Integer) object.get("colid")).intValue() ); } }); return routineInfos.groupBy(ExtraRerunnableInfo.TO_SPECIFIC_NAME).multiValuesView().collect(new Function<RichIterable<ExtraRerunnableInfo>, DaRoutine>() { @Override public DaRoutine valueOf(RichIterable<ExtraRerunnableInfo> objectInfos) { MutableList<ExtraRerunnableInfo> sortedInfos = objectInfos.toSortedList(Comparators.fromFunctions(ExtraRerunnableInfo.TO_ORDER2, ExtraRerunnableInfo.TO_ORDER1)); StringBuilder definitionString = sortedInfos.injectInto(new StringBuilder(), new Function2<StringBuilder, ExtraRerunnableInfo, StringBuilder>() { @Override public StringBuilder value(StringBuilder sb, ExtraRerunnableInfo rerunnableInfo) { return sb.append(rerunnableInfo.getDefinition()); } }); return new DaRoutinePojoImpl( sortedInfos.get(0).getName(), schema, sortedInfos.get(0).getType().equals("P") ? DaRoutineType.procedure : DaRoutineType.function, sortedInfos.get(0).getSpecificName(), definitionString.toString() ); } }).toList().toImmutable(); }