Revision f4142aa7
Added by Cherian Mathew almost 9 years ago
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.util; |
11 | 11 |
|
12 |
import java.io.File; |
|
13 |
import java.io.FileOutputStream; |
|
14 |
import java.io.IOException; |
|
15 |
import java.io.ObjectOutputStream; |
|
16 |
|
|
17 |
import org.apache.log4j.Logger; |
|
12 | 18 |
import org.hibernate.cfg.Configuration; |
13 | 19 |
|
20 |
import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher; |
|
21 |
|
|
14 | 22 |
/** |
15 | 23 |
* @author cmathew |
16 | 24 |
* @date 27 May 2015 |
17 | 25 |
* |
18 | 26 |
*/ |
19 | 27 |
public class Serializer { |
28 |
private static final Logger logger = Logger.getLogger(Serializer.class); |
|
29 |
|
|
30 |
|
|
31 |
public static String HB_CONFIG_SER_FILE_NAME = "hibernate.cfg.ser"; |
|
32 |
|
|
33 |
public static boolean checkDir(String dirString) { |
|
34 |
if(dirString == null || dirString.isEmpty()) { |
|
35 |
logger.warn("Directory not set or set to empty string"); |
|
36 |
return false; |
|
37 |
} |
|
38 |
|
|
39 |
File dir = new File(dirString); |
|
40 |
|
|
41 |
if(!dir.exists()) { |
|
42 |
logger.warn("Directory does not exist"); |
|
43 |
return false; |
|
44 |
} |
|
45 |
|
|
46 |
return true; |
|
47 |
|
|
48 |
} |
|
49 |
public static void serializeHbConfig() { |
|
50 |
|
|
51 |
Configuration configuration = CdmModelCacher.buildConfiguration(); |
|
52 |
String hbConfigDir = System.getProperty("hb.config.dir"); |
|
53 |
if(checkDir(hbConfigDir)) { |
|
54 |
try { |
|
55 |
FileOutputStream fileOut = new FileOutputStream(hbConfigDir + File.separator + HB_CONFIG_SER_FILE_NAME); |
|
56 |
ObjectOutputStream out = new ObjectOutputStream(fileOut); |
|
57 |
out.writeObject(configuration); |
|
58 |
out.close(); |
|
59 |
fileOut.close(); |
|
60 |
logger.info("Serialized configuration object"); |
|
61 |
} catch(IOException i) { |
|
62 |
i.printStackTrace(); |
|
63 |
} |
|
64 |
} |
|
65 |
} |
|
20 | 66 |
|
21 |
String HB_CONFIG_PATH= "/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"; |
|
67 |
public static void main(String[] args) { |
|
68 |
serializeHbConfig(); |
|
22 | 69 |
|
23 |
public static void serializeHbConfig(String serializedFilePath) { |
|
24 |
Configuration configuration = new Configuration().configure("/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml"); |
|
25 |
configuration.buildMappings(); |
|
26 | 70 |
} |
27 | 71 |
|
28 | 72 |
} |
Also available in: Unified diff
cdmlib-ehcache : removed disk based cache manager since the hb config is now cached in memory
CdmApplicationRemoteController, CdmModelCacher, CdmRemoteCacheManager, CdmModelGetMethodCacherTest : running the hibernate config load in separate thread
CdmTransientEntityCacher, EntityCacherDebugResult, CdmStore, SessionsViewPart: refactoring
httpInvokerServiceClients.xml : removed lazy loading of beans