Skip to content

Commit

Permalink
Database features are not cleaned when database is closed #111
Browse files Browse the repository at this point in the history
  • Loading branch information
lehvolk committed Jul 3, 2023
1 parent 1b0873f commit ad68c6b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ interface HierarchyExtension {
*/
fun findSubClasses(name: String, allHierarchy: Boolean): Sequence<JcClassOrInterface>

/**
* @return same as `findSubClasses` but with instance of this class
*/
fun classWithSubClasses(name: String, allHierarchy: Boolean): Sequence<JcClassOrInterface>

/**
* find all subclasses or implementations if name points to interface. If [allHierarchy] is true then search
* will be done recursively
Expand All @@ -39,6 +44,11 @@ interface HierarchyExtension {
*/
fun findSubClasses(jcClass: JcClassOrInterface, allHierarchy: Boolean): Sequence<JcClassOrInterface>

/**
* @return same as `findSubClasses` but with instance of this class
*/
fun classWithSubClasses(jcClass: JcClassOrInterface, allHierarchy: Boolean): Sequence<JcClassOrInterface> = sequenceOf(jcClass) + findSubClasses(jcClass, allHierarchy)

/**
* find overrides of current method
* @return list with unique methods overriding current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,30 @@ object Approximations : JcFeature<Any?, Any?>, JcClassExtFeature, JcInstExtFeatu
): ByteCodeIndexer = ApproximationIndexer(originalToApproximation, approximationToOriginal)

override fun onSignal(signal: JcSignal) {
val persistence = signal.jcdb.persistence
persistence.read { jooq ->
val approxSymbol = persistence.findSymbolId(approximationAnnotationClassName)
jooq.select(CLASSES.NAME, ANNOTATIONVALUES.CLASS_SYMBOL)
.from(ANNOTATIONS)
.join(CLASSES).on(ANNOTATIONS.CLASS_ID.eq(CLASSES.ID))
.join(ANNOTATIONVALUES).on(ANNOTATIONVALUES.ANNOTATION_ID.eq(ANNOTATIONS.ID))
.where(
ANNOTATIONS.ANNOTATION_NAME.eq(approxSymbol).and(
ANNOTATIONVALUES.NAME.eq("value")
if (signal is JcSignal.BeforeIndexing) {
val persistence = signal.jcdb.persistence
persistence.read { jooq ->
val approxSymbol = persistence.findSymbolId(approximationAnnotationClassName)
jooq.select(CLASSES.NAME, ANNOTATIONVALUES.CLASS_SYMBOL)
.from(ANNOTATIONS)
.join(CLASSES).on(ANNOTATIONS.CLASS_ID.eq(CLASSES.ID))
.join(ANNOTATIONVALUES).on(ANNOTATIONVALUES.ANNOTATION_ID.eq(ANNOTATIONS.ID))
.where(
ANNOTATIONS.ANNOTATION_NAME.eq(approxSymbol).and(
ANNOTATIONVALUES.NAME.eq("value")
)
)
)
.fetch().forEach { (approximation, original) ->
val approximationClassName = persistence.findSymbolName(approximation!!).toApproximationName()
val originalClassName = persistence.findSymbolName(original!!).toOriginalName()
originalToApproximation[originalClassName] = approximationClassName
approximationToOriginal[approximationClassName] = originalClassName
}
.fetch().forEach { (approximation, original) ->
val approximationClassName = persistence.findSymbolName(approximation!!).toApproximationName()
val originalClassName = persistence.findSymbolName(original!!).toOriginalName()
originalToApproximation[originalClassName] = approximationClassName
approximationToOriginal[approximationClassName] = originalClassName
}
}
}
}


/**
* Returns a list of [JcEnrichedVirtualField] if there is an approximation for [clazz] and null otherwise.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import org.jacodb.api.JcClasspath
import org.jacodb.api.JcMethod
import org.jacodb.api.ext.HierarchyExtension
import org.jacodb.api.ext.JAVA_OBJECT
import org.jacodb.api.ext.findClass
import org.jacodb.api.ext.findDeclaredMethodOrNull
import org.jacodb.impl.fs.PersistenceClassSource
import org.jacodb.impl.storage.BatchedSequence
Expand Down Expand Up @@ -80,6 +81,10 @@ class HierarchyExtensionImpl(private val cp: JcClasspath) : HierarchyExtension {
return findSubClasses(jcClass, allHierarchy)
}

override fun classWithSubClasses(name: String, allHierarchy: Boolean): Sequence<JcClassOrInterface> {
return sequenceOf(cp.findClass(name)) + findSubClasses(name, allHierarchy)
}

override fun findSubClasses(jcClass: JcClassOrInterface, allHierarchy: Boolean): Sequence<JcClassOrInterface> {
if (jcClass.isFinal) {
return emptySequence()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ object InMemoryHierarchy : JcFeature<InMemoryHierarchyReq, ClassSource> {
is JcSignal.Drop -> {
hierarchies[signal.jcdb]?.clear()
}
is JcSignal.Closed -> {
hierarchies.remove(signal.jcdb)
}

else -> Unit
}
Expand Down

0 comments on commit ad68c6b

Please sign in to comment.