Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
minerva
core
Commits
7314bddf
Commit
7314bddf
authored
8 years ago
by
piotr.gawron
Browse files
Options
Downloads
Patches
Plain Diff
test
parent
63926f60
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!1
Issue 37
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java
+145
-144
145 additions, 144 deletions
...in/java/lcsb/mapviewer/annotation/cache/GeneralCache.java
with
145 additions
and
144 deletions
annotation/src/main/java/lcsb/mapviewer/annotation/cache/GeneralCache.java
+
145
−
144
View file @
7314bddf
package
lcsb.mapviewer.annotation.cache
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.model.cache.CacheType
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.w3c.dom.Node
;
/**
* Cache used by the application. It contains two sub-classes responsible for
* application level cache (for single run of the application) and database
* level cache (for information that were gathere since the beginning).
*
* @author Piotr Gawron
*
*/
@Transactional
(
value
=
"txManager"
)
public
class
GeneralCache
implements
GeneralCacheInterface
{
/**
* Default class logger.
*/
@SuppressWarnings
(
"unused"
)
private
static
Logger
logger
=
Logger
.
getLogger
(
GeneralCache
.
class
);
/**
* Application level cache. More information can be found
* {@link ApplicationLevelCache here}.
*/
private
QueryCacheInterface
cache1
=
ApplicationLevelCache
.
getInstance
();
/**
* Database level cache. More information can be found
* {@link PermanentDatabaseLevelCache here}.
*/
@Autowired
private
QueryCacheInterface
cache2
;
@Override
public
void
clearCache
()
{
if
(
cache1
!=
null
)
{
cache1
.
clearCache
();
}
if
(
cache2
!=
null
)
{
cache2
.
clearCache
();
}
}
@Override
public
Node
getXmlNodeByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
Node
result
=
null
;
if
(
cache1
!=
null
)
{
result
=
cache1
.
getXmlNodeByQuery
(
query
,
type
);
}
if
(
result
==
null
&&
cache2
!=
null
)
{
result
=
cache2
.
getXmlNodeByQuery
(
query
,
type
);
if
(
result
!=
null
&&
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
result
);
}
}
return
result
;
}
@Override
public
String
getStringByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
String
result
=
null
;
if
(
cache1
!=
null
)
{
result
=
cache1
.
getStringByQuery
(
query
,
type
);
}
if
(
result
==
null
&&
cache2
!=
null
)
{
result
=
cache2
.
getStringByQuery
(
query
,
type
);
if
(
result
!=
null
&&
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
result
);
}
}
return
result
;
}
@Override
public
void
setCachedQuery
(
String
query
,
CacheType
type
,
Object
object
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
object
);
}
if
(
cache2
!=
null
)
{
cache2
.
setCachedQuery
(
query
,
type
,
object
);
}
}
@Override
public
void
removeByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
removeByQuery
(
query
,
type
);
}
if
(
cache2
!=
null
)
{
cache2
.
removeByQuery
(
query
,
type
);
}
}
@Override
public
void
invalidateByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
invalidateByQuery
(
query
,
type
);
}
if
(
cache2
!=
null
)
{
cache2
.
invalidateByQuery
(
query
,
type
);
}
}
/**
* @return the cache2
* @see #cache2
*/
public
QueryCacheInterface
getCache2
()
{
return
cache2
;
}
/**
* @param cache2
* the cache2 to set
* @see #cache2
*/
public
void
setCache2
(
QueryCacheInterface
cache2
)
{
this
.
cache2
=
cache2
;
}
}
package
lcsb.mapviewer.annotation.cache
;
import
lcsb.mapviewer.common.exception.InvalidArgumentException
;
import
lcsb.mapviewer.model.cache.CacheType
;
import
org.apache.log4j.Logger
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.transaction.annotation.Transactional
;
import
org.w3c.dom.Node
;
/**
* Cache used by the application. It contains two sub-classes responsible for
* application level cache (for single run of the application) and database
* level cache (for information that were gathere since the beginning).
*
* @author Piotr Gawron
*
*/
@Transactional
(
value
=
"txManager"
)
public
class
GeneralCache
implements
GeneralCacheInterface
{
/**
* Default class logger.
*/
@SuppressWarnings
(
"unused"
)
private
static
Logger
logger
=
Logger
.
getLogger
(
GeneralCache
.
class
);
/**
* Application level cache. More information can be found
* {@link ApplicationLevelCache here}.
*/
private
QueryCacheInterface
cache1
=
ApplicationLevelCache
.
getInstance
();
/**
* Database level cache. More information can be found
* {@link PermanentDatabaseLevelCache here}.
*/
@Autowired
private
QueryCacheInterface
cache2
;
@Override
public
void
clearCache
()
{
if
(
cache1
!=
null
)
{
cache1
.
clearCache
();
}
if
(
cache2
!=
null
)
{
cache2
.
clearCache
();
}
}
@Override
public
Node
getXmlNodeByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
Node
result
=
null
;
if
(
cache1
!=
null
)
{
result
=
cache1
.
getXmlNodeByQuery
(
query
,
type
);
}
if
(
result
==
null
&&
cache2
!=
null
)
{
result
=
cache2
.
getXmlNodeByQuery
(
query
,
type
);
if
(
result
!=
null
&&
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
result
);
}
}
return
result
;
}
@Override
public
String
getStringByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
String
result
=
null
;
if
(
cache1
!=
null
)
{
result
=
cache1
.
getStringByQuery
(
query
,
type
);
}
if
(
result
==
null
&&
cache2
!=
null
)
{
result
=
cache2
.
getStringByQuery
(
query
,
type
);
if
(
result
!=
null
&&
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
result
);
}
}
return
result
;
}
@Override
public
void
setCachedQuery
(
String
query
,
CacheType
type
,
Object
object
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
setCachedQuery
(
query
,
type
,
object
);
}
if
(
cache2
!=
null
)
{
cache2
.
setCachedQuery
(
query
,
type
,
object
);
}
}
@Override
public
void
removeByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
removeByQuery
(
query
,
type
);
}
if
(
cache2
!=
null
)
{
cache2
.
removeByQuery
(
query
,
type
);
}
}
@Override
public
void
invalidateByQuery
(
String
query
,
CacheType
type
)
{
if
(
type
==
null
)
{
throw
new
InvalidArgumentException
(
"Cache type cannot be null"
);
}
if
(
cache1
!=
null
)
{
cache1
.
invalidateByQuery
(
query
,
type
);
}
if
(
cache2
!=
null
)
{
cache2
.
invalidateByQuery
(
query
,
type
);
}
}
/**
* @return the cache2
* @see #cache2
*/
public
QueryCacheInterface
getCache2
()
{
return
cache2
;
}
/**
* @param cache2
* the cache2 to set
* @see #cache2
*/
public
void
setCache2
(
QueryCacheInterface
cache2
)
{
this
.
cache2
=
cache2
;
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment