Coverage Report - org.apache.torque.engine.platform.PlatformDefaultImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
PlatformDefaultImpl
0%
0/51
0%
0/14
1.474
 
 1  
 package org.apache.torque.engine.platform;
 2  
 
 3  
 /*
 4  
  * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE
 5  
  * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the
 7  
  * License. You may obtain a copy of the License at
 8  
  * 
 9  
  * http://www.apache.org/licenses/LICENSE-2.0
 10  
  * 
 11  
  * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
 12  
  * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
 13  
  * specific language governing permissions and limitations under the License.
 14  
  */
 15  
 
 16  
 import java.sql.Connection;
 17  
 import java.sql.DatabaseMetaData;
 18  
 import java.sql.ResultSet;
 19  
 import java.sql.SQLException;
 20  
 import java.util.ArrayList;
 21  
 import java.util.HashMap;
 22  
 import java.util.Iterator;
 23  
 import java.util.List;
 24  
 import java.util.Map;
 25  
 
 26  
 import org.apache.commons.lang.StringUtils;
 27  
 import org.apache.torque.engine.database.model.Domain;
 28  
 import org.apache.torque.engine.database.model.SchemaType;
 29  
 
 30  
 /**
 31  
  * Default implementation for the Platform interface.
 32  
  * 
 33  
  * @author <a href="mailto:mpoeschl@marmot.at">Martin Poeschl</a>
 34  
  * @version $Id: PlatformDefaultImpl.java,v 1.1.6.2 2008-04-18 17:04:37 jkeller Exp $
 35  
  */
 36  
 public class PlatformDefaultImpl implements Platform {
 37  
     private Map<SchemaType, Domain> schemaDomainMap;
 38  
 
 39  
     /**
 40  
      * Default constructor.
 41  
      */
 42  0
     public PlatformDefaultImpl() {
 43  0
         initialize();
 44  0
     }
 45  
 
 46  
     private void initialize() {
 47  0
         schemaDomainMap = new HashMap<SchemaType, Domain>(30);
 48  0
         Iterator<SchemaType> iter = SchemaType.iterator();
 49  0
         while (iter.hasNext()) {
 50  0
             SchemaType type = iter.next();
 51  0
             schemaDomainMap.put(type, new Domain(type));
 52  0
         }
 53  0
         schemaDomainMap.put(SchemaType.BOOLEANCHAR, new Domain(SchemaType.BOOLEANCHAR, "CHAR"));
 54  0
         schemaDomainMap.put(SchemaType.BOOLEANINT, new Domain(SchemaType.BOOLEANINT, "INTEGER"));
 55  0
     }
 56  
 
 57  
     protected void setSchemaDomainMapping(Domain domain) {
 58  0
         schemaDomainMap.put(domain.getType(), domain);
 59  0
     }
 60  
 
 61  
     public String getServerUrl(String url) {
 62  
         // By default just return the existing url
 63  0
         return url;
 64  
     }
 65  
 
 66  
     public String getSchemaName(String artifactId) {
 67  0
         String suffix = "-db";
 68  0
         if (artifactId.endsWith(suffix)) {
 69  0
             int length = artifactId.length();
 70  0
             artifactId = artifactId.substring(0, length - suffix.length());
 71  
         }
 72  0
         return StringUtils.remove(artifactId, "-");
 73  
     }
 74  
 
 75  
     /**
 76  
      * @see Platform#getMaxColumnNameLength()
 77  
      */
 78  
     public int getMaxColumnNameLength() {
 79  0
         return 64;
 80  
     }
 81  
 
 82  
     /**
 83  
      * @see Platform#getNativeIdMethod()
 84  
      */
 85  
     public String getNativeIdMethod() {
 86  0
         return Platform.IDENTITY;
 87  
     }
 88  
 
 89  
     /**
 90  
      * @see Platform#getDomainForSchemaType(SchemaType)
 91  
      */
 92  
     public Domain getDomainForSchemaType(SchemaType jdbcType) {
 93  0
         return schemaDomainMap.get(jdbcType);
 94  
     }
 95  
 
 96  
     /**
 97  
      * @return Only produces a SQL fragment if null values are disallowed.
 98  
      * @see Platform#getNullString(boolean)
 99  
      */
 100  
     public String getNullString(boolean notNull) {
 101  
         // TODO: Check whether this is true for all DBs. Also verify
 102  
         // the old Sybase templates.
 103  0
         return (notNull ? "NOT NULL" : "");
 104  
     }
 105  
 
 106  
     /**
 107  
      * @see Platform#getAutoIncrement()
 108  
      */
 109  
     public String getAutoIncrement() {
 110  0
         return "IDENTITY";
 111  
     }
 112  
 
 113  
     /**
 114  
      * @see Platform#hasScale(String) TODO collect info for all platforms
 115  
      */
 116  
     public boolean hasScale(String sqlType) {
 117  0
         return true;
 118  
     }
 119  
 
 120  
     /**
 121  
      * @see Platform#hasSize(String) TODO collect info for all platforms
 122  
      */
 123  
     public boolean hasSize(String sqlType) {
 124  0
         return true;
 125  
     }
 126  
 
 127  
     /**
 128  
      * @see Platform#createNotNullBeforeAutoincrement()
 129  
      */
 130  
     public boolean createNotNullBeforeAutoincrement() {
 131  0
         return true;
 132  
     }
 133  
 
 134  
     public String filterInvalidDefaultValues(String defaultValue) {
 135  0
         return defaultValue;
 136  
     }
 137  
 
 138  
     public boolean isSpecialDefault(String defaultValue) {
 139  0
         return false;
 140  
     }
 141  
 
 142  
     public Long getSequenceNextVal(Connection con, String schema, String sequenceName) {
 143  0
         throw new UnsupportedOperationException("getSequenceDefinition");
 144  
     }
 145  
 
 146  
     public String getViewDefinition(Connection con, String schema, String viewName) {
 147  0
         throw new UnsupportedOperationException("getViewDefinition");
 148  
     }
 149  
 
 150  
     /**
 151  
      * Retrieves a list of the columns composing the primary key for a given table.
 152  
      * 
 153  
      * @param dbMeta
 154  
      *            JDBC metadata.
 155  
      * @param tableName
 156  
      *            Table from which to retrieve PK information.
 157  
      * @return A list of the primary key parts for <code>tableName</code>.
 158  
      * @throws SQLException
 159  
      */
 160  
     public List<String> getPrimaryKeys(DatabaseMetaData dbMeta, String dbSchema, String tableName) throws SQLException {
 161  0
         List<String> pk = new ArrayList<String>();
 162  0
         ResultSet parts = null;
 163  
         try {
 164  0
             parts = dbMeta.getPrimaryKeys(null, dbSchema, tableName);
 165  0
             while (parts.next()) {
 166  0
                 pk.add(parts.getString(4));
 167  
             }
 168  
         } finally {
 169  0
             if (parts != null) {
 170  0
                 parts.close();
 171  
             }
 172  
         }
 173  0
         return pk;
 174  
     }
 175  
 
 176  
     /**
 177  
      * Get all the table names in the current database that are not system tables.
 178  
      * 
 179  
      * @param dbMeta
 180  
      *            JDBC database metadata.
 181  
      * @return The list of all the tables in a database.
 182  
      * @throws SQLException
 183  
      */
 184  
     public List<String> getTableNames(DatabaseMetaData dbMeta, String databaseSchema) throws SQLException {
 185  
         // System.out.println("Getting table list...");
 186  0
         List<String> tables = new ArrayList<String>();
 187  0
         ResultSet tableNames = null;
 188  
         // these are the entity types we want from the database
 189  0
         String[] types = { "TABLE" }; // JHK: removed views from list
 190  
         try {
 191  0
             tableNames = dbMeta.getTables(null, databaseSchema, null, types);
 192  0
             while (tableNames.next()) {
 193  0
                 String name = tableNames.getString(3);
 194  0
                 tables.add(name);
 195  0
             }
 196  
         } finally {
 197  0
             if (tableNames != null) {
 198  0
                 tableNames.close();
 199  
             }
 200  
         }
 201  
         // System.out.println("Found " + tables.size() + " tables.");
 202  0
         return tables;
 203  
     }
 204  
 }