/*** * Override to register factory services used by the host. */ protected void registerPostgresSchema(PostgresSchemaManager sm) { sm.addFactory(CheckpointFactoryService.SELF_LINK, CheckpointService.class); sm.addTable(td -> { td.useStatefulService(AuthCredentialsService.class); td.setIndexType("privateKey", "hash"); td.setIndexType("publicKey", "hash"); }); sm.addFactory(RoleService.class); sm.addFactory(TenantService.class); sm.addFactory(UserService.class); sm.addFactory(UserGroupService.class); sm.addFactory(ResourceGroupService.class); sm.addFactory(TransactionFactoryService.SELF_LINK, TransactionService.class); }
public PostgresServiceDocumentDao(ServiceHost host, Service service, DataSource ds) { this.host = host; this.service = service; this.ds = ds; this.schemaManager = new PostgresSchemaManager(host); registerMBeans(); }
protected boolean validateLiquibaseSnapshot(PostgresSchemaManager schemaManager) throws Exception { return PostgresLiquibaseUtils.validateSnapshot(schemaManager.getSnapshot(), this.latestSnapshotResourcePath, true); }
/** * Performs SQL initialization for the given document type, e.g. creating a dedicated table for * it, etc. * * Expected to be called once per document type upon host startup. */ public void initForDocument(String factoryLink, Class<? extends ServiceDocument> documentType, ServiceDocumentDescription sdd) { this.schemaManager.addFactory(factoryLink, documentType, sdd); TableDescription desc = this.schemaManager.getTableDescriptionForFactoryLink(factoryLink); if (desc != null) { ensureTableExists(desc); } }
try { if (serviceMetadata.factoryCreator != null) { sm.addFactory((StatefulService) serviceMetadata.factoryCreator.get() .createServiceInstance()); } else { sm.addFactory( (Class<? extends StatefulService>) serviceMetadata.serviceClass); sm.addCustomFactory((Class<? extends FactoryService>) serviceMetadata.serviceClass);
@Override protected void registerPostgresSchema(PostgresSchemaManager sm) { super.registerPostgresSchema(sm); sm.addFactory(TestService.class); sm.addFactory(TestPeriodicService.class); sm.addFactory(TestImmutableService.class); }
public void addCustomFactory(Class<? extends FactoryService> factoryType) { addTable(td -> { td.useFactoryService(factoryType); }); }
private Set<String> getKindScope(QuerySpecification qs) { Set<String> kindScope = new HashSet<>(4); findKindScopeFromQuery(qs.query, kindScope); if (kindScope.isEmpty()) { findFactoryScopeFromQuery(qs.query, kindScope); } if (kindScope.isEmpty()) { logger.fine(() -> String.format("Missing kind scope in query: %s", Utils.toJsonHtml(qs))); // Returning all scopes to allow do a UNION of all tables // Adding to existing kindScope mutable set to avoid Kryo cloning issues kindScope.addAll(this.schemaManager.getServiceDocuments()); } if (kindScope.isEmpty()) { throw new IllegalArgumentException("Cannot create SQL query without a kind scope"); } return kindScope; }
/** * Traverses the given query and find documentSelfLink constraints from which the factory query * scope is deducted. * * Takes all links into account no matter if they MUST_NOT_OCCUR - no need for such optimization * for now as our support for multiple kind scope will cope with that. */ private void findFactoryScopeFromQuery(Query query, Set<String> result) { if (query.booleanClauses != null) { for (Query innerQuery : query.booleanClauses) { findFactoryScopeFromQuery(innerQuery, result); } return; } if (query.term != null && ServiceDocument.FIELD_NAME_SELF_LINK.equals(query.term.propertyName) && !UriUtils.URI_WILDCARD_CHAR.equals(query.term.matchValue)) { String factoryLink = UriUtils.getParentPath(query.term.matchValue); if (factoryLink != null && !factoryLink.isEmpty() && !UriUtils.URI_PATH_CHAR.equals(factoryLink) && !factoryLink.contains(UriUtils.URI_WILDCARD_CHAR)) { String documentKind = this.schemaManager.getDocumentKindForFactoryLink(factoryLink); if (documentKind != null) { result.add(documentKind); } } } }
cd.table = this; cd.propertyDescription = pd; cd.columnType = getColumnType(pd); cd.parent = parent; if (parent != null) {
stateType = tableDescription.getStateType(); } else { stateType = this.schemaManager.getStateTypeForDocumentKind(visitor.documentKind); if (stateType == null) {
public void addFactory(StatefulService service) { addTable(td -> { td.useStatefulService(service); }); }
public void addFactory(Class<? extends StatefulService> serviceType) { addTable(td -> { td.useStatefulService(serviceType); }); }
public void addTable(Consumer<TableDescription> handler) { TableDescription td = new TableDescription(this.host); handler.accept(td); addTable(td); }
public void addFactory(String factoryLink, StatefulService childService) { addTable(td -> { td.setFactoryLink(factoryLink); td.useStatefulService(childService); }); }
public void addFactory(String factoryLink, Class<? extends StatefulService> serviceType) { addTable(td -> { td.setFactoryLink(factoryLink); td.useStatefulService(serviceType); }); }
void addFactory(String factoryLink, Class<? extends ServiceDocument> stateType, ServiceDocumentDescription sdd) { addTable(td -> { td.setFactoryLink(factoryLink); td.setStateType(stateType); td.setServiceDocumentDescription(sdd); }); }