public class DB
extends java.lang.Object
implements com.codahale.metrics.MetricSet
| Modifier and Type | Field and Description |
|---|---|
java.lang.String |
selectPostTermsSQL |
long |
siteId
The site id.
|
| Constructor and Description |
|---|
DB(org.attribyte.sql.ConnectionSupplier connectionSupplier,
long siteId,
java.util.Set<java.lang.String> cachedTaxonomies,
java.time.Duration taxonomyCacheTimeout,
java.time.Duration userCacheTimeout)
Creates a database with the default metric source.
|
DB(org.attribyte.sql.ConnectionSupplier connectionSupplier,
long siteId,
java.util.Set<java.lang.String> cachedTaxonomies,
java.time.Duration taxonomyCacheTimeout,
java.time.Duration userCacheTimeout,
MetricSource metricSource)
Creates a database.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clearPostMeta(long postId)
Clears all metadata for a post.
|
void |
clearPostTerm(long postId,
long taxonomyTermId)
Clears a single taxonomy term associated with a post.
|
void |
clearPostTerms(long postId)
Clears all terms associated with a post.
|
void |
clearPostTerms(long postId,
java.lang.String taxonomy)
Clears all terms associated with a post with a specified taxonomy.
|
TaxonomyTerm |
createTaxonomyTerm(java.lang.String taxonomy,
java.lang.String name,
java.lang.String slug,
java.lang.String description)
Creates a taxonomy term.
|
Term |
createTerm(java.lang.String name,
java.lang.String slug)
Creates a term.
|
User |
createUser(User user,
java.lang.String userPass)
Creates a user.
|
void |
deleteChildren(long parentId)
Deletes all children.
|
void |
deletePost(long postId)
Deletes a post with a specified id, including all associated metadata.
|
java.util.Map<java.lang.String,com.codahale.metrics.Metric> |
getMetrics() |
Post |
insertPost(Post post,
java.util.TimeZone tz)
Inserts a post.
|
Post.Builder |
resolve(Post.Builder post)
Resolves user, author, terms and meta for a post.
|
TaxonomyTerm |
resolveTaxonomyTerm(long id)
Resolves a taxonomy term by id.
|
TaxonomyTerm |
resolveTaxonomyTerm(java.lang.String taxonomy,
java.lang.String name)
Resolves a taxonomy term, creating if required.
|
User |
resolveUser(long userId)
Resolves a user by id, possibly with the internal cache.
|
User |
resolveUser(java.lang.String username)
Resolves a user by username, possibly with the internal cache.
|
java.util.List<Post> |
selectAuthorPosts(long userId,
Post.Sort sort,
Paging paging,
boolean withResolve)
Selects a page of posts for an author.
|
java.util.List<Post> |
selectChildren(long parentId,
boolean withResolve)
Gets all children for a post.
|
java.util.List<Post> |
selectModifiedPosts(Post.Type type,
long startTimestamp,
long startId,
int limit,
boolean withResolve)
Selects recently modified posts, in ascending order after a specified timestamp and id.
|
java.lang.String |
selectOption(java.lang.String optionName)
Gets a configuration option.
|
java.lang.String |
selectOption(java.lang.String optionName,
java.lang.String defaultValue)
Gets a configuration option with a default value.
|
Post.Builder |
selectPost(long postId)
Selects a post by id.
|
java.util.List<java.lang.Long> |
selectPostIds(Post.Type type,
Post.Status status,
java.util.Collection<TaxonomyTerm> terms,
Post.Sort sort,
Paging paging)
Selects a page of posts with a specified type.
|
java.util.List<Meta> |
selectPostMeta(long postId)
Selects metadata for a post.
|
java.util.List<Post> |
selectPosts(Post.Type type,
Post.Status status,
Post.Sort sort,
Paging paging,
boolean withResolve)
Selects a page of posts with a specified type.
|
java.util.List<Post> |
selectPosts(java.lang.String slug,
boolean withResolve)
Selects all posts with a "slug".
|
java.util.List<TaxonomyTerm> |
selectPostTerms(long postId)
Selects all terms associated with a post for any taxonomy.
|
java.util.List<TaxonomyTerm> |
selectPostTerms(long postId,
java.lang.String taxonomy)
Selects all terms associated with a post.
|
java.util.List<Blog> |
selectPublicBlogs()
Selects all public, enabled blogs.
|
Site |
selectSite()
Selects the site metadata from the options table.
|
TaxonomyTerm |
selectTaxonomyTerm(java.lang.String taxonomy,
java.lang.String name)
Selects a taxonomy term.
|
Term |
selectTerm(long id)
Selects a term by id.
|
java.util.Set<java.lang.Long> |
selectTermIds(java.lang.String name)
Selects the term ids for all with the specified name.
|
User |
selectUser(long userId)
Selects a user from the database.
|
User |
selectUser(java.lang.String username)
Selects a user by username.
|
void |
setPostMeta(long postId,
java.util.List<Meta> postMeta)
Sets metadata for a post.
|
java.util.List<TaxonomyTerm> |
setPostTerms(long postId,
java.lang.String taxonomy,
java.util.List<java.lang.String> terms)
Sets terms associated with a post, replacing any existing terms with the specified taxonomy.
|
Post |
updatePost(Post post,
java.util.TimeZone tz)
Updates a post.
|
java.util.List<Meta> |
userMetadata(long userId)
Selects metadata for a user.
|
public final java.lang.String selectPostTermsSQL
public final long siteId
public DB(org.attribyte.sql.ConnectionSupplier connectionSupplier,
long siteId,
java.util.Set<java.lang.String> cachedTaxonomies,
java.time.Duration taxonomyCacheTimeout,
java.time.Duration userCacheTimeout)
connectionSupplier - Supplies connections to the underlying database.siteId - The site id.cachedTaxonomies - Enable caches for these taxonomies.taxonomyCacheTimeout - The expiration for taxonomy caches. If 0, caching is disabled.userCacheTimeout - The expiration for user caches. If 0, caching is disabled.public DB(org.attribyte.sql.ConnectionSupplier connectionSupplier,
long siteId,
java.util.Set<java.lang.String> cachedTaxonomies,
java.time.Duration taxonomyCacheTimeout,
java.time.Duration userCacheTimeout,
MetricSource metricSource)
connectionSupplier - Supplies connections to the underlying database.siteId - The site id.cachedTaxonomies - Enable caches for these taxonomies.taxonomyCacheTimeout - The expiration for taxonomy caches. If 0, caching is disabled.userCacheTimeout - The expiration for user caches. If 0, caching is disabled.metricSource - A metric source.public User createUser(User user, java.lang.String userPass) throws java.sql.SQLException
user - The user.userPass - The user_pass string to use (probably the hash of a default username/password).java.sql.SQLException - on database error.public User selectUser(java.lang.String username) throws java.sql.SQLException
The user table is keyed to allow multiple users with the same username. This method will return the first matching user.
username - The username.null if not found.java.sql.SQLException - on database error.public User selectUser(long userId) throws java.sql.SQLException
userId - The user id.null if not found.java.sql.SQLException - on database error.public User resolveUser(long userId) throws java.sql.SQLException
userId - The user id.null, if not found.java.sql.SQLException - on database error.public User resolveUser(java.lang.String username) throws java.sql.SQLException
username - The username.null, if not found.java.sql.SQLException - on database error.public java.util.List<Meta> userMetadata(long userId) throws java.sql.SQLException
userId - The user id.java.sql.SQLException - on database error.public void deletePost(long postId)
throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public java.util.List<Post> selectAuthorPosts(long userId, Post.Sort sort, Paging paging, boolean withResolve) throws java.sql.SQLException
userId - The user id for the author.sort - The sort direction.paging - The paging.withResolve - Should associated users, etc be resolved?java.sql.SQLException - on database error.public java.util.List<Post> selectModifiedPosts(Post.Type type, long startTimestamp, long startId, int limit, boolean withResolve) throws java.sql.SQLException
type - The post type. May be null for all types.startTimestamp - The timestamp after which posts were modified.startId - The start id. Posts that have timestamp that match startTimestamp exactly must if ids greater.limit - The maximum number of posts returned.withResolve - Should associated users, etc be resolved?java.sql.SQLException - on database error.public java.util.List<Post> selectPosts(Post.Type type, Post.Status status, Post.Sort sort, Paging paging, boolean withResolve) throws java.sql.SQLException
type - The post type.status - The required post status.sort - The page sort.paging - The page range and interval.withResolve - Should associated users, etc be resolved?java.sql.SQLException - on database error.public java.util.List<java.lang.Long> selectPostIds(Post.Type type, Post.Status status, java.util.Collection<TaxonomyTerm> terms, Post.Sort sort, Paging paging) throws java.sql.SQLException
type - The post type.status - The required post status.terms - A collection of terms attached to the posts.sort - The page sort.paging - The page range and interval.java.sql.SQLException - on database error.public void deleteChildren(long parentId)
throws java.sql.SQLException
parentId - The parent post id.java.sql.SQLException - on database error.public java.util.List<Post> selectChildren(long parentId, boolean withResolve) throws java.sql.SQLException
parentId - The parent post id.withResolve - Should associated users, etc be resolved?java.sql.SQLException - on database error.public java.util.List<Post> selectPosts(java.lang.String slug, boolean withResolve) throws java.sql.SQLException
Ideally there should be just one, but this is not guaranteed by the database.
slug - The slug.withResolve - Should associated users, etc be resolved?java.sql.SQLException - on database error.public Post.Builder resolve(Post.Builder post) throws java.sql.SQLException
post - The post builder.java.sql.SQLException - on database error.public Post.Builder selectPost(long postId) throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public Post updatePost(Post post, java.util.TimeZone tz) throws java.sql.SQLException
post - The post to update. The id must be set.tz - The local time zone.java.sql.SQLException - on database error or missing post id.public Post insertPost(Post post, java.util.TimeZone tz) throws java.sql.SQLException
If the post has a non-zero id, it will be inserted with this id,
otherwise an id will be generated.
post - The post.tz - The local time zone for the post.java.sql.SQLException - on database error or post with duplicate id.public void clearPostMeta(long postId)
throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public java.util.List<Meta> selectPostMeta(long postId) throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public void setPostMeta(long postId,
java.util.List<Meta> postMeta)
throws java.sql.SQLException
Clears existing metadata.
postId - The post id.postMeta - The metadata.java.sql.SQLException - on database error.public java.util.Set<java.lang.Long> selectTermIds(java.lang.String name)
throws java.sql.SQLException
name - The term name.java.sql.SQLException - on database error.public Term createTerm(java.lang.String name, java.lang.String slug) throws java.sql.SQLException
name - The term name.slug - The term slug.java.sql.SQLException - on database error.public Term selectTerm(long id) throws java.sql.SQLException
id - The id.null if none.java.sql.SQLException - on database error.public TaxonomyTerm selectTaxonomyTerm(java.lang.String taxonomy, java.lang.String name) throws java.sql.SQLException
taxonomy - The taxonomy name.name - The term name.null if none.java.sql.SQLException - on database error.public TaxonomyTerm createTaxonomyTerm(java.lang.String taxonomy, java.lang.String name, java.lang.String slug, java.lang.String description) throws java.sql.SQLException
taxonomy - The taxonomy.name - The term name.slug - The term slug.description - The taxonomy term description.java.sql.SQLException - on database error.public TaxonomyTerm resolveTaxonomyTerm(java.lang.String taxonomy, java.lang.String name) throws java.sql.SQLException
If taxonomy term cache is configured for this taxonomy, it is used for resolution.
taxonomy - The taxonomy.name - The term name.java.sql.SQLException - on database error.public TaxonomyTerm resolveTaxonomyTerm(long id) throws java.sql.SQLException
Uses configured caches.
id - The taxonomy term id.null if not found.java.sql.SQLException - on database error.public void clearPostTerm(long postId,
long taxonomyTermId)
throws java.sql.SQLException
postId - The post id.taxonomyTermId - The taxonomy term id.java.sql.SQLException - on database error.public void clearPostTerms(long postId)
throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public void clearPostTerms(long postId,
java.lang.String taxonomy)
throws java.sql.SQLException
postId - The post id.taxonomy - The taxonomy.java.sql.SQLException - on database error.public java.util.List<TaxonomyTerm> setPostTerms(long postId, java.lang.String taxonomy, java.util.List<java.lang.String> terms) throws java.sql.SQLException
Uses cache, if configured, to resolve.
postId - The post id.taxonomy - The taxonomy.terms - A list of term names.java.sql.SQLException - on database error.public java.util.List<TaxonomyTerm> selectPostTerms(long postId) throws java.sql.SQLException
postId - The post id.java.sql.SQLException - on database error.public java.util.List<TaxonomyTerm> selectPostTerms(long postId, java.lang.String taxonomy) throws java.sql.SQLException
postId - The post id.taxonomy - The taxonomy. If null, any taxonomy is accepted.java.sql.SQLException - on database error.public java.lang.String selectOption(java.lang.String optionName)
throws java.sql.SQLException
optionName - The option name.null if not found.java.sql.SQLException - on database error.public java.lang.String selectOption(java.lang.String optionName,
java.lang.String defaultValue)
throws java.sql.SQLException
optionName - The option name.defaultValue - A default value if no option is set.java.sql.SQLException - on database error.public Site selectSite() throws java.sql.SQLException
java.sql.SQLException - on database error.public java.util.List<Blog> selectPublicBlogs() throws java.sql.SQLException
java.sql.SQLException - on database error.public java.util.Map<java.lang.String,com.codahale.metrics.Metric> getMetrics()
getMetrics in interface com.codahale.metrics.MetricSet