1 22 23 package org.xquark.mapper.storage; 24 25 import java.sql.ResultSet ; 26 import java.sql.SQLException ; 27 import java.sql.Statement ; 28 29 import org.xquark.mapper.dbms.AbstractConnection; 30 import org.xquark.mapper.dbms.TableInfo; 31 import org.xquark.mapper.metadata.RepositoryInfo; 32 33 38 39 public class PersistentRepositoryInfo 40 { 41 private static final String RCSRevision = "$Revision: 1.1 $"; 42 private static final String RCSName = "$Name: $"; 43 44 48 private RepositoryInfo config = null; 49 50 private TableInfo configTable = null; 51 52 53 private AbstractConnection connection; 54 55 public PersistentRepositoryInfo(TableInfo configTable, AbstractConnection connection) 56 { 57 this.config = new RepositoryInfo(); 58 this.connection = connection; 59 this.configTable = configTable; 60 } 61 62 public PersistentRepositoryInfo(RepositoryInfo config, TableInfo configTable, AbstractConnection connection) 63 { 64 this.config = config; 65 this.connection = connection; 66 this.configTable = configTable; 67 } 68 69 public RepositoryInfo getRepositoryInfo() 70 { 71 return config; 72 } 73 74 79 public void save() 80 throws SQLException 81 { 82 connection.executeUpdate("DELETE FROM "+ configTable.getName()); 83 StringBuffer stmt = new StringBuffer (); 84 stmt.append("INSERT INTO "); 85 stmt.append(configTable.getName()); 86 stmt.append(" VALUES('"); 87 stmt.append(config.getName()); 88 stmt.append("',"); 89 stmt.append(config.getColIDSize()); 90 stmt.append(",'"); 91 stmt.append(config.getVersion()); 92 stmt.append("')"); 93 connection.executeUpdate(stmt.toString()); 94 } 95 96 public boolean fetchRow() 97 throws SQLException 98 { 99 Statement stmt = connection.getConnection().createStatement(); 100 ResultSet rs = null; 101 try { 102 rs = stmt.executeQuery("SELECT NAME,CID_SIZE,VERSION FROM " + configTable.getName()); 103 104 if (rs.next()) 105 { 106 config.setName(rs.getString(1)); 107 config.setColIDSize(rs.getByte(2)); 108 config.setVersion(rs.getString(3)); 109 return true; } 111 else 112 return false; } 114 finally { 115 if (rs != null) 116 rs.close(); 117 stmt.close(); 118 } 119 } 120 121 } 122 | Popular Tags |