/src/main/org/mongodb/driver/ts/DB.java

https://github.com/Fancy/mongo-java-driver · Java · 149 lines · 24 code · 21 blank · 104 comment · 0 complexity · d7ccff42949da4a7bd233de479438953 MD5 · raw file

  1. /**
  2. * See the NOTICE.txt file distributed with this work for
  3. * information regarding copyright ownership.
  4. *
  5. * The authors license this file to you under the
  6. * Apache License, Version 2.0 (the "License"); you may not use
  7. * this file except in compliance with the License. You may
  8. * obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. package org.mongodb.driver.ts;
  20. import org.mongodb.driver.admin.DBAdmin;
  21. import org.mongodb.driver.ts.options.DBOptions;
  22. import org.mongodb.driver.ts.options.DBCollectionOptions;
  23. import org.mongodb.driver.ts.commands.DBCommand;
  24. import org.mongodb.driver.MongoDBException;
  25. import org.mongodb.driver.MongoDBIOException;
  26. import java.util.List;
  27. /**
  28. * A Mongo database instance.
  29. *
  30. */
  31. public interface DB {
  32. /**
  33. * Executes a query on this database.
  34. *
  35. * @param query MQL query string
  36. * @return cursor with result set
  37. * @throws MongoDBException if something goes awry
  38. * @throws MongoDBIOException on IO error with database
  39. */
  40. public DBCursor executeQuery(String query) throws MongoDBException, MongoDBIOException;
  41. /**
  42. * Executes a command on the database
  43. *
  44. * @param command to execute
  45. * @return boolean if successful. Command object has results
  46. *
  47. * @throws MongoDBException if something goes awry
  48. * @throws MongoDBIOException on IO error with database
  49. */
  50. public boolean executeCommand(DBCommand command) throws MongoDBException;
  51. /**
  52. * Returns a list of the names of the collections in this database
  53. *
  54. * @return List of collection names
  55. * @throws MongoDBException on error
  56. * @throws MongoDBIOException on IO error with database
  57. */
  58. public List<String> getCollectionNames() throws MongoDBException, MongoDBIOException;
  59. /**
  60. * Creates a new collection collection. Like getCollection() relies upon the
  61. * strict mode for creation
  62. *
  63. * @param name name of collection to create
  64. * @return collection
  65. * @throws MongoDBException if collection doesn't exist and in strict mode, or if
  66. * there's a problem creating the collection
  67. * @throws MongoDBIOException on IO error with database
  68. */
  69. public DBCollection createCollection(String name) throws MongoDBException, MongoDBIOException;
  70. /**
  71. * Creates a collection with optional options. Note that if options are passed in and not in strict
  72. * mode, driver doesn't currently guarantee the options will be respected.
  73. *
  74. * @param name name of collection to create
  75. * @param options optinoal options for creation (e.g. CappedCollection)
  76. * @return collection
  77. * @throws MongoDBException if collection exists and in strict mode or an error creating collection
  78. * @throws MongoDBIOException on IO error with database
  79. */
  80. public DBCollection createCollection(String name, DBCollectionOptions options) throws MongoDBException, MongoDBIOException;
  81. /**
  82. * Gets a DBCollection object representing the specified collection in the database.
  83. * This collection object can be used for subsequent operations. Note that this
  84. * will create the collection if it doesn't exist. If you wish to be strict,
  85. * use getCollection(name, option) to enforce the requirement that the collection
  86. * must exist.
  87. *
  88. * @param name the name of collection to get
  89. * @return collection object for subsequent operations, or null if it doesn't exist.
  90. * @throws MongoDBException on error
  91. * @throws MongoDBIOException on IO error with database
  92. */
  93. public DBCollection getCollection(String name) throws MongoDBException, MongoDBIOException;
  94. /**
  95. * Drops a collection, the collections object, and the colletions indexes
  96. *
  97. * @param name Name of collection to drop
  98. * @return true if successful, false otherwise
  99. * @throws MongoDBException if error
  100. * @throws MongoDBIOException on IO error with database
  101. */
  102. public boolean dropCollection(String name) throws MongoDBException, MongoDBIOException;
  103. /**
  104. * Returns the name of this database
  105. *
  106. * @return name of database
  107. */
  108. public String getName();
  109. /**
  110. * Return the admin interface for this DB
  111. * @return admin object for this database
  112. */
  113. public DBAdmin getAdmin();
  114. /**
  115. * Returns the options for this database. E.g. require collections exist
  116. * @return current options settings for this database
  117. */
  118. public DBOptions getDBOptions();
  119. /**
  120. * Sets the options for this database
  121. *
  122. * @param dbOptions options to set for DB
  123. */
  124. public void setDBOptions(DBOptions dbOptions);
  125. public void resetDBOptions();
  126. public void close() throws Exception;
  127. public Doc eval(String function, Object... args) throws MongoDBException;
  128. }