@Test void getJunctionTableSelect() { EntityType entityType = when(mock(EntityType.class).getId()).thenReturn("entity").getMock(); when(entityType.getId()).thenReturn("entityTypeId"); Attribute idAttr = when(mock(Attribute.class).getName()).thenReturn("idAttr").getMock(); when(idAttr.getIdentifier()).thenReturn("idAttrId"); Attribute attr = when(mock(Attribute.class).getName()).thenReturn("attr").getMock(); when(attr.getIdentifier()).thenReturn("attrId"); when(attr.getDataType()).thenReturn(MREF); when(entityType.getIdAttribute()).thenReturn(idAttr); assertEquals( "SELECT \"idAttr\",\"order\",\"attr\" FROM \"entityTypeId#c34894ba_attr\" WHERE \"idAttr\" in (?, ?, ?) ORDER BY \"idAttr\",\"order\"", getSqlJunctionTableSelect(entityType, attr, 3)); }
static String getSqlJunctionTableSelect(EntityType entityType, Attribute attr, int numOfIds) { String idColName = getColumnName(entityType.getIdAttribute()); String refIdColName = getColumnName(attr); return "SELECT " + idColName + "," + getJunctionTableOrderColumnName() + "," + refIdColName + " FROM " + getJunctionTableName(entityType, attr) + " WHERE " + idColName + " in (" + range(0, numOfIds).mapToObj(x -> "?").collect(joining(", ")) + ") ORDER BY " + idColName + "," + getJunctionTableOrderColumnName(); }
PostgreSqlQueryGenerator { static String getSqlJunctionTableSelect(EntityType entityType, Attribute attr, int numOfIds) { String idColName = getColumnName(entityType.getIdAttribute()); String refIdColName = getColumnName(attr); return "SELECT " + idColName + "," + getJunctionTableOrderColumnName() + "," + refIdColName + " FROM " + getJunctionTableName(entityType, attr) + " WHERE " + idColName + " in (" + range(0, numOfIds).mapToObj(x -> "?").collect(joining(", ")) + ") ORDER BY " + idColName + "," + getJunctionTableOrderColumnName(); } }
PostgreSqlQueryGenerator { static String getSqlJunctionTableSelect(EntityType entityType, Attribute attr, int numOfIds) { String idColName = getColumnName(entityType.getIdAttribute()); String refIdColName = getColumnName(attr); return "SELECT " + idColName + "," + getJunctionTableOrderColumnName() + "," + refIdColName + " FROM " + getJunctionTableName(entityType, attr) + " WHERE " + idColName + " in (" + range(0, numOfIds).mapToObj(x -> "?").collect(joining(", ")) + ") ORDER BY " + idColName + "," + getJunctionTableOrderColumnName(); } private  PostgreSqlQueryGenerator(); }
PostgreSqlQueryGenerator { static String getSqlJunctionTableSelect(EntityType entityType, Attribute attr, int numOfIds) { String idColName = getColumnName(entityType.getIdAttribute()); String refIdColName = getColumnName(attr); return "SELECT " + idColName + "," + getJunctionTableOrderColumnName() + "," + refIdColName + " FROM " + getJunctionTableName(entityType, attr) + " WHERE " + idColName + " in (" + range(0, numOfIds).mapToObj(x -> "?").collect(joining(", ")) + ") ORDER BY " + idColName + "," + getJunctionTableOrderColumnName(); } private  PostgreSqlQueryGenerator();  }
PostgreSqlQueryGenerator { static String getSqlJunctionTableSelect(EntityType entityType, Attribute attr, int numOfIds) { String idColName = getColumnName(entityType.getIdAttribute()); String refIdColName = getColumnName(attr); return "SELECT " + idColName + "," + getJunctionTableOrderColumnName() + "," + refIdColName + " FROM " + getJunctionTableName(entityType, attr) + " WHERE " + idColName + " in (" + range(0, numOfIds).mapToObj(x -> "?").collect(joining(", ")) + ") ORDER BY " + idColName + "," + getJunctionTableOrderColumnName(); } private  PostgreSqlQueryGenerator();   }