KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cayenne > access > DbGeneratorPostprocessor


1 /*****************************************************************
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  ****************************************************************/

19 package org.apache.cayenne.access;
20
21 import java.sql.Connection JavaDoc;
22 import java.sql.PreparedStatement JavaDoc;
23 import java.sql.SQLException JavaDoc;
24 import java.util.HashMap JavaDoc;
25 import java.util.Map JavaDoc;
26
27 import org.apache.cayenne.dba.AutoAdapter;
28 import org.apache.cayenne.dba.DbAdapter;
29 import org.apache.cayenne.dba.hsqldb.HSQLDBAdapter;
30
31 /**
32  * A helper class that handles postprocessing after the schema generation operation. E.g.
33  * some databases require a checkpoint command to be run for the schema changes to be
34  * flushed to disk.
35  *
36  * @author Andrus Adamchik
37  */

38 class DbGeneratorPostprocessor {
39
40     private static final Map JavaDoc postprocessors;
41
42     static {
43         postprocessors = new HashMap JavaDoc();
44         postprocessors.put(HSQLDBAdapter.class.getName(), new HSQLDBPostprocessor());
45     }
46
47     void execute(Connection JavaDoc connection) throws SQLException JavaDoc {
48
49         DbAdapter adapter = AutoAdapter.getDefaultFactory().createAdapter(
50                 connection.getMetaData());
51         if (adapter != null) {
52             Postprocessor postprocessor = (Postprocessor) postprocessors.get(adapter
53                     .getClass()
54                     .getName());
55             if (postprocessor != null) {
56                 postprocessor.execute(connection);
57             }
58         }
59     }
60
61     static abstract class Postprocessor {
62
63         abstract void execute(Connection JavaDoc c) throws SQLException JavaDoc;
64     }
65
66     static class HSQLDBPostprocessor extends Postprocessor {
67
68         void execute(Connection JavaDoc c) throws SQLException JavaDoc {
69             PreparedStatement JavaDoc st = c.prepareStatement("CHECKPOINT");
70             try {
71                 st.execute();
72             }
73             finally {
74                 st.close();
75             }
76         }
77     }
78 }
79
Popular Tags