发布时间:2025-12-09 12:00:23 浏览次数:2
import com.strategicgains.syntaxe.ValidationEngine; //导入依赖的package包/类/** * Creates a Document, ensuring that all business rules are met. * * @param database Database to insert the document into. * @param table Table to insert the document into. * @param json String of the JSON to insert. * @return The created document. * @throws IndexParseException If the document contains a field that should * be indexable, but isn't for some reason (probably the wrong datatype). */public Document create(String database, String table, String json) throws IndexParseException{ verifyTable(database, table); Document doc = new Document(); doc.setTable(database, table); doc.setObjectAsString(json); doc.setUuid(UUID.randomUUID());//TODO: is this right? -- https://github.com/PearsonEducation/Docussandra/issues/4 ValidationEngine.validateAndThrow(doc); try { Document created = docRepo.create(doc); notifyAllPlugins(NotifierPlugin.MutateType.CREATE, created); return created; } catch (RuntimeException e)//the framework does not allow us to throw the IndexParseException directly from the repository layer { if (e.getCause() != null && e.getCause() instanceof IndexParseException) { throw (IndexParseException) e.getCause(); } else { throw e; } }} import com.strategicgains.syntaxe.ValidationEngine; //导入依赖的package包/类/** * Creates an index. Index will be created synchronously, but it will be * populated asynchronously, and it will not be "active" (meaning it can't * be used for querying) until indexing is complete. Inactive indexes will * still be populated by NEW records that are being inserted. * * @param index Index to create. * @return An IndexCreatedEvent that contains the index and some metadata * about it's creation status. */public IndexCreatedEvent create(Index index){ verifyTable(index.getDatabaseName(), index.getTableName()); ValidationEngine.validateAndThrow(index); index.setActive(false);//we default to not active when being created; we don't allow the user to change this; only the app can change this logger.debug("Creating index: " + index.toString()); Index created = indexesRepo.create(index); long dataSize = tablesRepo.countTableSize(index.getDatabaseName(), index.getTableName()); Date now = new Date(); UUID uuid = UUID.randomUUID();//TODO: is this right? IndexCreatedEvent toReturn = new IndexCreatedEvent(uuid, now, now, created, dataSize, 0l); statusRepo.create(toReturn); toReturn.calculateValues(); DomainEvents.publish(toReturn); return toReturn;} import com.strategicgains.syntaxe.ValidationEngine; //导入依赖的package包/类public User create(Request request, Response response) { User user = request.getBodyAs(User.class, "User details not provided"); ValidationEngine.validateAndThrow(user); userBo.store(user); // Construct the response for create... response.setResponseCreated(); TokenResolver resolver = HyperExpress.bind(Constants.Url.USER_UUID, user.getUuid()); // Include the Location header... String locationPattern = request.getNamedUrl(HttpMethod.GET, Constants.Routes.USER_READ_ROUTE); response.addLocationHeader(LOCATION_BUILDER.build(locationPattern, resolver)); // Return the newly-created item... return user;}