public abstract class AbstractRepository extends Object implements Repository
This is a base adapter for wrapped repository, the underlying repository will be instantiated in
the constructor..
| Constructor and Description |
|---|
AbstractRepository(String name)
Constructs a repository with the specified name.
|
| Modifier and Type | Method and Description |
|---|---|
String |
add(JSONObject jsonObject)
Adds the specified json object.
|
Transaction |
beginTransaction()
Begins a transaction against the repository.
|
long |
count()
Gets the count of all json objects.
|
long |
count(Query query)
Gets the count of json objects by the specified query.
|
Map<String,JSONObject> |
get(Iterable<String> ids)
Gets json objects by the specified ids.
|
JSONObject |
get(Query query)
Gets json objects by the specified query.
|
JSONObject |
get(String id)
Gets a json object by the specified id.
|
String |
getName()
Gets the name of this repository.
|
List<JSONObject> |
getRandomly(int fetchSize)
Gets a list of json objects randomly with the specified fetch size.
|
protected Repository |
getUnderlyingRepository()
Gets the underlying repository.
|
boolean |
has(String id)
Determines a json object specified by the given id exists in this repository.
|
boolean |
hasTransactionBegun()
Whether the repository within a transaction.
|
boolean |
isWritable()
Whether the repository is writable.
|
void |
remove(Query query)
Removes json objects by the specified query.
|
void |
remove(String id)
Removes a json object by the specified id.
|
List<JSONObject> |
select(String statement,
Object... params)
Gets json objects by the specified query statement.
|
void |
setDebug(boolean debugEnabled)
Sets whether the repository is debug to show SQL with the specified flag.
|
void |
setWritable(boolean writable)
Sets whether the repository is writable with the specified flag.
|
void |
update(String id,
JSONObject jsonObject,
String... propertyNames)
Updates a certain json object specified by the given id with the specified new json object and property names.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitgetFirst, getListpublic AbstractRepository(String name)
name - the specified namepublic String add(JSONObject jsonObject) throws RepositoryException
Repositoryadd in interface RepositoryjsonObject - the specified json objectRepositoryException - repository exceptionpublic void update(String id, JSONObject jsonObject, String... propertyNames) throws RepositoryException
Repositoryupdate in interface Repositoryid - the specified idjsonObject - the specified new json objectpropertyNames - the specified property names to update, update all properties if not specifiedRepositoryException - repository exceptionpublic void remove(String id) throws RepositoryException
Repositoryremove in interface Repositoryid - the specified idRepositoryException - repository exceptionpublic void remove(Query query) throws RepositoryException
Repositoryremove in interface Repositoryquery - the specified queryRepositoryException - repository exceptionpublic JSONObject get(String id) throws RepositoryException
Repositoryget in interface Repositoryid - the specified idnull if not foundRepositoryException - repository exceptionpublic Map<String,JSONObject> get(Iterable<String> ids) throws RepositoryException
Repositoryget in interface Repositoryids - the specified idsRepositoryException - repository exceptionpublic boolean has(String id) throws RepositoryException
Repositoryhas in interface Repositoryid - the given idtrue if it exists, otherwise falseRepositoryException - repository exceptionpublic JSONObject get(Query query) throws RepositoryException
Repository
-1 or null) by caller (as the argument
Query.setPageCount(int)), the value will be used in the returned value. In other words, the page count result
will not be calculated by this interface, otherwise, the returned value pagination.paginationPageCount and
pagination.paginationRecordCount will be calculated with query condition.
Note: The order of elements of the returned result list is decided by datastore implementation, excepts
Query.addSort(java.lang.String, org.b3log.latke.repository.SortDirection) be invoked.
get in interface Repositoryquery - the specified query
{
"pagination": {
"paginationPageCount": 10, // May be specified by the specified query.pageCount
"paginationRecordCount": "100" // If query.pageCount has been specified with not -1 or null, this value will
be 0 also
},
"rslts": [{
"oId": "...."
}, ....]
}
RepositoryException - repository exceptionpublic List<JSONObject> select(String statement, Object... params) throws RepositoryException
Repositoryselect in interface Repositorystatement - the specified query statementparams - the specified parametersRepositoryException - repository exceptionpublic List<JSONObject> getRandomly(int fetchSize) throws RepositoryException
RepositorygetRandomly in interface RepositoryfetchSize - the specified fetch sizeRepositoryException - repository exceptionpublic long count()
throws RepositoryException
Repositorycount in interface Repository-1 if not availableRepositoryException - repository exceptionpublic long count(Query query) throws RepositoryException
Repositorycount in interface Repositoryquery - the specified query-1 if not availableRepositoryException - repository exceptionpublic Transaction beginTransaction()
Repository
Callers are responsible for explicitly calling Transaction.commit() or
Transaction.rollback() when they no longer need the Transaction. The Transaction
returned by this call will be considered the current transaction until one of the following happens:
Transaction returned by this methodTransaction will no longer be the current
transaction.
Transaction returned by this methodTransaction will no longer be the current
transaction.
beginTransaction in interface Repositorypublic boolean hasTransactionBegun()
RepositoryhasTransactionBegun in interface Repositorytrue if the repository within a transaction, returns false otherwisepublic String getName()
RepositorygetName in interface Repositorypublic boolean isWritable()
RepositoryisWritable in interface Repositorytrue if it is writable, returns false otherwisepublic void setWritable(boolean writable)
RepositorysetWritable in interface Repositorywritable - the specified flag, true for writable, false otherwisepublic void setDebug(boolean debugEnabled)
RepositorysetDebug in interface RepositorydebugEnabled - the specified flag, true for enabled, false otherwiseprotected Repository getUnderlyingRepository()
Copyright © 2009–2019 B3log. All rights reserved.