private static ColumnDescription getColumnDescription(TableDescription td, String propertyName) { ColumnDescription cd = td.getColumnDescription(propertyName); if (cd != null) { return cd; } int i = propertyName.length() - 1; while ((i = propertyName.lastIndexOf('.', i)) != -1) { propertyName = propertyName.substring(0, i); cd = td.getColumnDescription(propertyName); if (cd != null) { return cd; } i--; } return null; }
private String addTable(TableDescription td) { JsonObject table = new JsonObject(); table.addProperty("name", td.getTableName()); String tableId = addSnapshotId(table, LIQUIBASE_STRUCTURE_CORE_TABLE, td.getTableName()); columnIds.put("data", dataColumnId); td.getColumns().stream() .filter(ColumnDescription::isNativeColumn) .forEach(column -> addColumnIndex(td, tableId, column, columnIds, indexIds, null)); .get(ServiceDocument.FIELD_NAME_SELF_LINK.toLowerCase()); td.getColumns().stream() .filter(cd -> !cd.isNativeColumn() && cd.getDataColumnLevel() == 0) .forEach(column -> addColumnIndex(td, tableId, column, columnIds, indexIds, documentSelfLinkColumnId)); String primaryKeyIndexName = td.getTableName() + "_pkey";
&& !term.matchValue.startsWith(td.getFactoryLink())) { result = false; } else if (term.propertyName.equals(ServiceDocument.FIELD_NAME_KIND)) { result = term.matchValue.equals(td.getDocumentKind()); result = true; } else { if (term.matchValue.length() <= td.getFactoryLinkWithTrailingSlash().length()) { result = td.getFactoryLinkWithTrailingSlash().startsWith(term.matchValue); } else if (!term.matchValue.startsWith(td.getFactoryLink())) { result = false;
td.getTableName(), where); } else { sql = String.format("SELECT %s FROM %s WHERE %s %s LIMIT %s", fields, td.getTableName(), where, orderBy, hitCount); if (offset > 0) { sql += String.format(" OFFSET %d", offset); fields, td.getTableName(), where); }) .filter(Objects::nonNull)
fields, tables.iterator().next().getTableName(), where, groupBy, orderBy, groupLimit + 1); if (groupOffset > 0) { fields, td.getTableName(), where); }) .filter(Objects::nonNull)
case PODO: pd.fieldDescriptions .forEach((key, value) -> handleProperty(cd, absolutePropertyName, key, value)); break; case COLLECTION: handleProperty(cd, absolutePropertyName, QuerySpecification.COLLECTION_FIELD_SUFFIX, pd.elementDescription); break;
td.getTableName(), where); }) .filter(Objects::nonNull) td.getTableName(), where);
tableDescription.getTableName());
private int applyDocumentExpirationPolicyForTable(TableDescription tableDescription, long now, long deadline, int limit) throws Exception { int expired = 0; String tableName = tableDescription.getTableName(); String sql = String.format("SELECT data,documentexpirationtimemicros FROM %s WHERE documentexpirationtimemicros BETWEEN 1 AND ? ORDER BY documentexpirationtimemicros LIMIT ?", tableName);
stateType = tableDescription.getStateType(); } else { stateType = this.schemaManager.getStateTypeForDocumentKind(visitor.documentKind);
String tableName = desc.getTableName();
private static String convertToPostgresSortField(QueryTask.QueryTerm sortTerm, boolean includeSortOrder, TableDescription td) { validateSortTerm(sortTerm); ColumnDescription cd = td.getColumnDescription(sortTerm.propertyName); if (sortTerm.sortOrder == null) { sortTerm.sortOrder = QueryTask.QuerySpecification.SortOrder.ASC; } String sortField; switch (sortTerm.propertyType) { case BOOLEAN: case DOUBLE: case LONG: sortField = wrapNativeField(sortTerm.propertyName, cd); break; default: sortField = wrapStringField(sortTerm.propertyName, cd); if (isCaseInsensitive(cd)) { sortField = String.format("LOWER(%s)", sortField); } } if (includeSortOrder) { boolean ascending = sortTerm.sortOrder == QueryTask.QuerySpecification.SortOrder.ASC; sortField += ascending ? " ASC" : " DESC"; } return sortField; }
public TableDescription useFactoryService(Class<? extends FactoryService> factoryType) { if (getFactoryLink() == null) { String factoryLink = getSelfLinkFieldValue(factoryType); if (factoryLink == null) { throw new IllegalArgumentException(String.format( "Failed to add factory %s, missing SELF_LINK field", factoryType.getCanonicalName())); } setFactoryLink(factoryLink); } try { FactoryService factoryService = factoryType.newInstance(); useFactoryService(factoryService); return this; } catch (Throwable e) { throw new IllegalArgumentException(String.format( "Failed to add factory %s", factoryType.getCanonicalName()), e); } }
public ServiceDocumentQueryResult queryBySelfLinkPrefix(Operation op, String selfLinkPrefix, EnumSet<QueryOption> options) throws Exception { TableDescription td = this.schemaManager .getTableDescriptionForFactoryLink(UriUtils.normalizeUriPath(selfLinkPrefix)); if (td == null) { // this might be a non-persisted service, return null so that in-memory services are // queried instead logger.fine(() -> String.format( "Cannot determine document kind for factory %s", selfLinkPrefix)); return null; } final int resultLimit = Integer.MAX_VALUE; final String tq = SQL_TRUE; QuerySpecification qs = new QuerySpecification(); qs.context.kindScope = Collections.singleton(td.getDocumentKind()); qs.context.nativeQuery = tq; Set<TableDescription> tables = Collections.singleton(td); return queryIndex(op, tables, tq, null, options, qs, resultLimit, 0, null, null); }
public TableDescription useStatefulService(StatefulService service) { if (service.getHost() == null) { service.setHost(this.host); } if (getFactoryLink() == null) { Class<? extends StatefulService> serviceType = service.getClass(); String factoryLink = getFactoryLinkFieldValue(serviceType); if (factoryLink == null) { throw new IllegalArgumentException( "Failed to add factory, missing FACTORY_LINK field"); } setFactoryLink(factoryLink); } setStateType(service.getStateType()); setServiceDocumentDescription(service.getDocumentTemplate().documentDescription); return this; }
public TableDescription useFactoryService(FactoryService factoryService) { if (factoryService.getHost() == null) { factoryService.setHost(this.host); } try { if (getFactoryLink() == null) { setFactoryLink(factoryService.getSelfLink()); } StatefulService childService = (StatefulService) factoryService.createServiceInstance(); useStatefulService(childService); return this; } catch (Throwable e) { throw new IllegalArgumentException(String.format( "Failed to add factory %s", factoryService.getClass().getCanonicalName()), e); } }
String getTableNameForFactoryLink(String factoryLink) { TableDescription td; if ((td = this.tableDescPerFactoryLink.get(factoryLink)) != null) { return td.getTableName(); } return null; }
public TableDescription setServiceDocumentDescription(ServiceDocumentDescription sdd) { this.sdd = sdd; buildColumns(); return this; }
private void addIndex(TableDescription td, String tableId, ColumnDescription columnDescription, String indexNameSuffix, Map<String, String> indexIds, List<String> columnIds) { // Postgres names are maxed at 63 bytes, as long as we use ascii we should have no more than // 63 characters String indexName = toHashedName( td.getTableName() + "_idx_" + indexNameSuffix, 63); String indexId = addIndex(tableId, indexName, false, columnIds); indexIds.put(indexName, indexId); this.columnDescriptionPerIndexId.put(indexName, columnDescription); }
Class<? extends ServiceDocument> getStateTypeForDocumentKind(String documentKind) { TableDescription td; if ((td = this.tableDescPerDocumentKind.get(documentKind)) != null) { return td.getStateType(); } return null; }