Created
February 14, 2011 12:18
-
-
Save dai0304/825796 to your computer and use it in GitHub Desktop.
basically usage of Jiemamy API v0.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void tutorial_01_read() throws Exception { | |
JiemamySerializer serializer = JiemamyContext.findSerializer(); | |
JiemamyContext context = serializer.deserialize(new FileInputStream("tutorial.jiemamy")); | |
Set<JmTable> tables = context.getTables(); | |
for (JmTable table : tables) { | |
System.out.println(table.getName()); | |
} | |
} | |
void tutorial_02_write() throws Exception { | |
JiemamyContext context = new JiemamyContext(); | |
SimpleJmTable table = new SimpleJmTable(); | |
table.setName("FOO"); | |
// カラムなど追加 | |
context.store(table); | |
JiemamySerializer serializer = JiemamyContext.findSerializer(); | |
serializer.serialize(context, new FileOutputStream("output.jiemamy")); | |
} | |
void tutorial_03_export() throws Exception { | |
JiemamyContext context = new JiemamyContext(); | |
SqlExporter exporter = new SqlExporter(); | |
SimpleSqlExportConfig config = new SimpleSqlExportConfig(); | |
config.setDataSetIndex(-1); // INSERT文は出力しない | |
config.setEmitDropStatements(true); // CREATE前に古いテーブルをDROPする | |
config.setOutputFile(new File("tutorial.sql")); // 出力先 | |
config.setOverwrite(true); // 既に存在したら上書き | |
exporter.exportModel(context, config); | |
} | |
void tutorial_04_import() throws Exception { | |
JiemamyContext context = new JiemamyContext(); | |
DbImporter importer = new DbImporter(); | |
SimpleDbImportConfig config = new SimpleDbImportConfig(); | |
config.setUri("jdbc:postgresql://loacalhost:5432/tutorial"); | |
config.setUsername("sa"); | |
// 略 | |
importer.importModel(context, config); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment