Class SqlDao
- java.lang.Object
-
- ca.stellardrift.permissionsex.datastore.sql.SqlDao
-
- All Implemented Interfaces:
AutoCloseable
public abstract class SqlDao extends Object implements AutoCloseable
Abstraction to communicate with the SQL database. Instances are not thread-safe -- it's best to create a new one for each operation on a single thread
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedSqlDao(SqlDataStore ds)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddParent(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, SqlSubjectRef<?> parent)ca.stellardrift.permissionsex.datastore.sql.SqlSegmentaddSegment(SqlSubjectRef<?> ref)voidallocateSegment(SqlSubjectRef<?> subject, ca.stellardrift.permissionsex.datastore.sql.SqlSegment val)voidallocateSubjectRef(SqlSubjectRef<?> ref)voidclearOption(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String option)voidclearPermission(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String permission)voidclose()voiddeleteTable(String table)protected <T> TexecuteInTransaction(org.spongepowered.configurate.util.CheckedSupplier<T,SQLException> func)Set<String>getAllIdentifiers(String type)Set<String>getAllRankLadderNames()Iterable<SqlSubjectRef<?>>getAllSubjectRefs()ConnectiongetConnection()SqlContextInheritancegetContextInheritance()SqlDataStoregetDataStore()protected StringgetDeleteContextInheritanceQuery()protected StringgetDeleteContextQuery()protected StringgetDeleteGlobalParameterQuery()protected StringgetDeleteInheritanceParentQuery()protected StringgetDeleteInheritanceQuery()protected StringgetDeleteOptionKeyQuery()protected StringgetDeleteOptionsQuery()protected StringgetDeletePermissionKeyQuery()protected StringgetDeletePermissionsQuery()protected StringgetDeleteRankLadderQuery()protected StringgetDeleteSegmentIdQuery()protected StringgetDeleteSubjectIdQuery()protected StringgetDeleteSubjectTypeNameQuery()protected StringgetGetSubjectRefIdQuery()protected StringgetGetSubjectRefTypeNameQuery()Optional<String>getGlobalParameter(String key)intgetIdAllocating(SqlSubjectRef<?> ref)protected StringgetInsertContextInheritanceQuery()protected StringgetInsertContextQuery()protected abstract StringgetInsertGlobalParameterQueryUpdating()protected StringgetInsertInheritanceQuery()protected abstract StringgetInsertOptionUpdatingQuery()protected abstract StringgetInsertPermissionUpdatingQuery()protected StringgetInsertRankLadderQuery()protected StringgetInsertSegmentQuery()protected StringgetInsertSubjectTypeNameQuery()SqlSubjectRef<?>getOrCreateSubjectRef(String type, String name)ca.stellardrift.permissionsex.rank.RankLaddergetRankLadder(String name)Set<String>getRegisteredTypes()protected StringgetRenameTableQuery()intgetSchemaVersion()Get the schema version.List<ca.stellardrift.permissionsex.datastore.sql.SqlSegment>getSegments(SqlSubjectRef<?> ref)protected StringgetSelectAllContextKeysUniqueQuery()protected StringgetSelectAllRankLadderNamesQuery()protected StringgetSelectAllSubjectsQuery()protected StringgetSelectContextInheritanceQuery()protected StringgetSelectContextsSegmentQuery()protected StringgetSelectGlobalParameterQuery()protected StringgetSelectInheritanceSegmentQuery()protected StringgetSelectOptionsSegmentQuery()protected StringgetSelectPermissionsSegmentQuery()protected StringgetSelectRankLadderQuery()protected StringgetSelectSegmentsSubjectQuery()protected StringgetSelectSubjectIdentifiersQuery()protected StringgetSelectSubjectTypesQuery()Optional<SqlSubjectRef<?>>getSubjectRef(int id)Optional<SqlSubjectRef<?>>getSubjectRef(String type, String name)protected StringgetTestRankLadderExistsQuery()protected StringgetUpdatePermissionDefaultQuery()Set<String>getUsedContextKeys()booleanhasEntriesForRankLadder(String name)voidinitializeTables()LegacyDaolegacy()PreparedStatementprepareStatement(String query)protected PreparedStatementprepareStatement(String query, int params)voidremoveParent(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, SqlSubjectRef<?> parent)booleanremoveSegment(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment)booleanremoveSubject(SqlSubjectRef<?> ref)booleanremoveSubject(String type, String name)voidrenameTable(String oldName, String newName)voidsetContextInheritance(ca.stellardrift.permissionsex.context.ContextValue<?> child, @Nullable org.pcollections.PVector<ca.stellardrift.permissionsex.context.ContextValue<?>> parents)voidsetContexts(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, org.pcollections.PSet<ca.stellardrift.permissionsex.context.ContextValue<?>> contexts)voidsetDefaultValue(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Integer permissionDefault)voidsetGlobalParameter(String key, @Nullable String value)voidsetOption(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String key, String value)voidsetOptions(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, @Nullable Map<String,String> options)voidsetParents(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Iterable<SqlSubjectRef<?>> parents)voidsetPermission(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String permission, int value)voidsetPermissions(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Map<String,Integer> permissions)voidsetRankLadder(String name, @Nullable ca.stellardrift.permissionsex.rank.RankLadder ladder)voidsetSchemaVersion(int version)voidupdateFullSegment(SqlSubjectRef<?> ref, ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment)
-
-
-
Constructor Detail
-
SqlDao
protected SqlDao(SqlDataStore ds) throws SQLException
- Throws:
SQLException
-
-
Method Detail
-
getSelectGlobalParameterQuery
protected String getSelectGlobalParameterQuery()
-
getInsertGlobalParameterQueryUpdating
protected abstract String getInsertGlobalParameterQueryUpdating()
-
getDeleteGlobalParameterQuery
protected String getDeleteGlobalParameterQuery()
-
getGetSubjectRefIdQuery
protected String getGetSubjectRefIdQuery()
-
getGetSubjectRefTypeNameQuery
protected String getGetSubjectRefTypeNameQuery()
-
getDeleteSubjectIdQuery
protected String getDeleteSubjectIdQuery()
-
getDeleteSubjectTypeNameQuery
protected String getDeleteSubjectTypeNameQuery()
-
getInsertSubjectTypeNameQuery
protected String getInsertSubjectTypeNameQuery()
-
getSelectContextsSegmentQuery
protected String getSelectContextsSegmentQuery()
-
getSelectSegmentsSubjectQuery
protected String getSelectSegmentsSubjectQuery()
-
getSelectPermissionsSegmentQuery
protected String getSelectPermissionsSegmentQuery()
-
getSelectOptionsSegmentQuery
protected String getSelectOptionsSegmentQuery()
-
getSelectInheritanceSegmentQuery
protected String getSelectInheritanceSegmentQuery()
-
getInsertSegmentQuery
protected String getInsertSegmentQuery()
-
getDeleteSegmentIdQuery
protected String getDeleteSegmentIdQuery()
-
getSelectSubjectIdentifiersQuery
protected String getSelectSubjectIdentifiersQuery()
-
getSelectSubjectTypesQuery
protected String getSelectSubjectTypesQuery()
-
getDeleteOptionKeyQuery
protected String getDeleteOptionKeyQuery()
-
getDeleteOptionsQuery
protected String getDeleteOptionsQuery()
-
getInsertOptionUpdatingQuery
protected abstract String getInsertOptionUpdatingQuery()
-
getInsertPermissionUpdatingQuery
protected abstract String getInsertPermissionUpdatingQuery()
-
getDeletePermissionKeyQuery
protected String getDeletePermissionKeyQuery()
-
getDeletePermissionsQuery
protected String getDeletePermissionsQuery()
-
getUpdatePermissionDefaultQuery
protected String getUpdatePermissionDefaultQuery()
-
getInsertInheritanceQuery
protected String getInsertInheritanceQuery()
-
getDeleteInheritanceParentQuery
protected String getDeleteInheritanceParentQuery()
-
getDeleteInheritanceQuery
protected String getDeleteInheritanceQuery()
-
getInsertContextQuery
protected String getInsertContextQuery()
-
getDeleteContextQuery
protected String getDeleteContextQuery()
-
getSelectContextInheritanceQuery
protected String getSelectContextInheritanceQuery()
-
getInsertContextInheritanceQuery
protected String getInsertContextInheritanceQuery()
-
getDeleteContextInheritanceQuery
protected String getDeleteContextInheritanceQuery()
-
getSelectRankLadderQuery
protected String getSelectRankLadderQuery()
-
getTestRankLadderExistsQuery
protected String getTestRankLadderExistsQuery()
-
getInsertRankLadderQuery
protected String getInsertRankLadderQuery()
-
getDeleteRankLadderQuery
protected String getDeleteRankLadderQuery()
-
getSelectAllRankLadderNamesQuery
protected String getSelectAllRankLadderNamesQuery()
-
getSelectAllSubjectsQuery
protected String getSelectAllSubjectsQuery()
-
getRenameTableQuery
protected String getRenameTableQuery()
-
getSelectAllContextKeysUniqueQuery
protected String getSelectAllContextKeysUniqueQuery()
-
prepareStatement
public PreparedStatement prepareStatement(String query) throws SQLException
- Throws:
SQLException
-
prepareStatement
protected PreparedStatement prepareStatement(String query, int params) throws SQLException
- Throws:
SQLException
-
executeInTransaction
protected <T> T executeInTransaction(org.spongepowered.configurate.util.CheckedSupplier<T,SQLException> func) throws SQLException
- Throws:
SQLException
-
getGlobalParameter
public Optional<String> getGlobalParameter(String key) throws SQLException
- Throws:
SQLException
-
setGlobalParameter
public void setGlobalParameter(String key, @Nullable String value) throws SQLException
- Throws:
SQLException
-
getSubjectRef
public Optional<SqlSubjectRef<?>> getSubjectRef(int id) throws SQLException
- Throws:
SQLException
-
getSubjectRef
public Optional<SqlSubjectRef<?>> getSubjectRef(String type, String name) throws SQLException
- Throws:
SQLException
-
removeSubject
public boolean removeSubject(SqlSubjectRef<?> ref) throws SQLException
- Throws:
SQLException
-
removeSubject
public boolean removeSubject(String type, String name) throws SQLException
- Throws:
SQLException
-
getOrCreateSubjectRef
public SqlSubjectRef<?> getOrCreateSubjectRef(String type, String name) throws SQLException
- Throws:
SQLException
-
allocateSubjectRef
public void allocateSubjectRef(SqlSubjectRef<?> ref) throws SQLException
- Throws:
SQLException
-
getIdAllocating
public int getIdAllocating(SqlSubjectRef<?> ref) throws SQLException
- Throws:
SQLException
-
getSegments
public List<ca.stellardrift.permissionsex.datastore.sql.SqlSegment> getSegments(SqlSubjectRef<?> ref) throws SQLException
- Throws:
SQLException
-
addSegment
public ca.stellardrift.permissionsex.datastore.sql.SqlSegment addSegment(SqlSubjectRef<?> ref) throws SQLException
- Throws:
SQLException
-
updateFullSegment
public void updateFullSegment(SqlSubjectRef<?> ref, ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment) throws SQLException
- Throws:
SQLException
-
setContexts
public void setContexts(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, org.pcollections.PSet<ca.stellardrift.permissionsex.context.ContextValue<?>> contexts) throws SQLException
- Throws:
SQLException
-
allocateSegment
public void allocateSegment(SqlSubjectRef<?> subject, ca.stellardrift.permissionsex.datastore.sql.SqlSegment val) throws SQLException
- Throws:
SQLException
-
removeSegment
public boolean removeSegment(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment) throws SQLException
- Throws:
SQLException
-
getAllIdentifiers
public Set<String> getAllIdentifiers(String type) throws SQLException
- Throws:
SQLException
-
getRegisteredTypes
public Set<String> getRegisteredTypes() throws SQLException
- Throws:
SQLException
-
initializeTables
public void initializeTables() throws SQLException
- Throws:
SQLException
-
clearOption
public void clearOption(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String option) throws SQLException
- Throws:
SQLException
-
setOptions
public void setOptions(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, @Nullable Map<String,String> options) throws SQLException
- Throws:
SQLException
-
setOption
public void setOption(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String key, String value) throws SQLException
- Throws:
SQLException
-
setPermission
public void setPermission(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String permission, int value) throws SQLException
- Throws:
SQLException
-
clearPermission
public void clearPermission(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, String permission) throws SQLException
- Throws:
SQLException
-
setPermissions
public void setPermissions(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Map<String,Integer> permissions) throws SQLException
- Throws:
SQLException
-
setDefaultValue
public void setDefaultValue(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Integer permissionDefault) throws SQLException
- Throws:
SQLException
-
addParent
public void addParent(ca.stellardrift.permissionsex.datastore.sql.SqlSegment seg, SqlSubjectRef<?> parent) throws SQLException
- Throws:
SQLException
-
removeParent
public void removeParent(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, SqlSubjectRef<?> parent) throws SQLException
- Throws:
SQLException
-
setParents
public void setParents(ca.stellardrift.permissionsex.datastore.sql.SqlSegment segment, @Nullable Iterable<SqlSubjectRef<?>> parents) throws SQLException
- Throws:
SQLException
-
getContextInheritance
public SqlContextInheritance getContextInheritance() throws SQLException
- Throws:
SQLException
-
setContextInheritance
public void setContextInheritance(ca.stellardrift.permissionsex.context.ContextValue<?> child, @Nullable org.pcollections.PVector<ca.stellardrift.permissionsex.context.ContextValue<?>> parents) throws SQLException
- Throws:
SQLException
-
getRankLadder
public ca.stellardrift.permissionsex.rank.RankLadder getRankLadder(String name) throws SQLException
- Throws:
SQLException
-
hasEntriesForRankLadder
public boolean hasEntriesForRankLadder(String name) throws SQLException
- Throws:
SQLException
-
setRankLadder
public void setRankLadder(String name, @Nullable ca.stellardrift.permissionsex.rank.RankLadder ladder) throws SQLException
- Throws:
SQLException
-
getAllRankLadderNames
public Set<String> getAllRankLadderNames() throws SQLException
- Throws:
SQLException
-
getAllSubjectRefs
public Iterable<SqlSubjectRef<?>> getAllSubjectRefs() throws SQLException
- Throws:
SQLException
-
getUsedContextKeys
public Set<String> getUsedContextKeys() throws SQLException
- Throws:
SQLException
-
close
public void close() throws SQLException
- Specified by:
closein interfaceAutoCloseable- Throws:
SQLException
-
renameTable
public void renameTable(String oldName, String newName) throws SQLException
- Throws:
SQLException
-
deleteTable
public void deleteTable(String table) throws SQLException
- Throws:
SQLException
-
getSchemaVersion
public int getSchemaVersion() throws SQLException
Get the schema version. Has to include backwards compatibility to correctly handle pre-2.x schema updates.- Returns:
- The schema version,
- Throws:
SQLException- if unable to connect to database or perform query
-
setSchemaVersion
public void setSchemaVersion(int version) throws SQLException
- Throws:
SQLException
-
getDataStore
public SqlDataStore getDataStore()
-
getConnection
public Connection getConnection()
-
-