Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2007 Daniel Spiewak
   * 
   * Licensed under the Apache License, Version 2.0 (the "License"); 
   * you may not use this file except in compliance with the License. 
   * You may obtain a copy of the License at
   * 
   *	    http://www.apache.org/licenses/LICENSE-2.0 
   * 
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package net.java.ao.db;
 
 import java.sql.Blob;
 import java.sql.Types;
 import java.util.Set;
 
 
 

Author(s):
Daniel Spiewak
 
 abstract class DerbyDatabaseProvider extends DatabaseProvider
 {
     {
         super(dataSourcenull, TypeManager.derby());
     }
 
     @Override
 	public void setQueryStatementProperties(Statement stmtQuery querythrows SQLException {
 		int limit = query.getLimit();
 		
 		if (limit >= 0) {
 			stmt.setFetchSize(limit);
 			stmt.setMaxRows(limit);
 		}
 	}
 	
 	public void setQueryResultSetProperties(ResultSet resQuery querythrows SQLException {
 		if (query.getOffset() > 0) {
 			res.absolute(query.getOffset());
 		}
 	}
 	
 	public ResultSet getTables(Connection connthrows SQLException {
 		return conn.getMetaData().getTables("APP"getSchema(), nullnew String[] {"TABLE"});
 	}
 	
 	public Object parseValue(int typeString value)
     {
         if (value == null || value.equals("") || value.equals("NULL"))
         {
             return null;
         }
 
         switch (type)
         {
             case .:
             case .:
             case .:
             case .:
                 Matcher matcher = Pattern.compile("'(.*)'.*").matcher(value);
                 if (matcher.find())
                 {
                     value = matcher.group(1);
                 }
                 break;
         }
 
         return super.parseValue(typevalue);
    }
	protected void setPostConnectionProperties(Connection connthrows SQLException {
		Statement stmt = conn.createStatement();
		stmt.executeUpdate("SET SCHEMA app");
		stmt.close();
	}
	protected String renderQueryLimit(Query query) {
		return "";
	}
	protected String renderAutoIncrement() {
		return "GENERATED BY DEFAULT AS IDENTITY";
	}
    public Object handleBlob(ResultSet resClass<?> typeString fieldthrows SQLException
    {
        final Blob blob = res.getBlob(field);
        if (type.equals(InputStream.class))
        {
            return new ByteArrayInputStream(blob.getBytes(1, (intblob.length()));
        }
        else if (type.equals(byte[].class))
        {
            return blob.getBytes(1, (intblob.length());
        }
        else
        {
            return null;
        }
    }
	protected Iterable<SQLActionrenderAlterTableChangeColumn(NameConverters nameConvertersDDLTable tableDDLField oldFieldDDLField field)
	{
		.warn("Derby doesn't support CHANGE TABLE statements!");
		.warn("Migration may not be entirely in sync as a result!");
		return ImmutableList.of();
	}
	protected Iterable<SQLActionrenderAlterTableDropColumn(NameConverters nameConvertersDDLTable tableDDLField field)
	{
		..println("WARNING: Derby doesn't support ALTER TABLE DROP COLUMN statements");
        return ImmutableList.of();
	}
	protected SQLAction renderDropIndex(IndexNameConverter indexNameConverterDDLIndex index)
	{
	    return SQLAction.of("DROP INDEX " + processID(indexNameConverter.getName(shorten(index.getTable()), shorten(index.getField()))));
	}
	protected Set<StringgetReservedWords() {
	}
	public boolean isCaseSensitive() {
		return false;
	}
    private static final Set<StringRESERVED_WORDS = ImmutableSet.of(
            "ADD""ALL""ALLOCATE""ALTER""AND""ANY""ARE""AS",
            "ASC""ASSERTION""AT""AUTHORIZATION""AVG""BEGIN""BETWEEN""BIT",
            "BOOLEAN""BOTH""BY""CALL""CASCADE""CASCADED""CASE""CAST",
            "CHAR""CHARACTER""CHECK""CLOSE""COLLATE""COLLATION""COLUMN",
            "COMMIT""CONNECT""CONNECTION""CONSTRAINT""CONSTRAINTS""CONTINUE",
            "CONVERT""CORRESPONDING""COUNT""CREATE""CURRENT""CURRENT_DATE",
            "CURRENT_TIME""CURRENT_TIMESTAMP""CURRENT_USER""CURSOR""DEALLOCATE",
            "DEC""DECIMAL""DECLARE""DEFERRABLE""DEFERRED""DELETE""DESC",
            "DESCRIBE""DIAGNOSTICS""DISCONNECT""DISTINCT""DOUBLE""DROP""ELSE",
            "END""ENDEXEC""ESCAPE""EXCEPT""EXCEPTION""EXEC""EXECUTE""EXISTS",
            "EXPLAIN""EXTERNAL""FALSE""FETCH""FIRST""FLOAT""FOR""FOREIGN",
            "FOUND""FROM""FULL""FUNCTION""GET""GET_CURRENT_CONNECTION""GLOBAL",
            "GO""GOTO""GRANT""GROUP""HAVING""HOUR""IDENTITY""IMMEDIATE",
            "IN""INDICATOR""INITIALLY""INNER""INOUT""INPUT""INSENSITIVE",
            "INSERT""INT""INTEGER""INTERSECT""INTO""IS""ISOLATION""JOIN",
            "KEY""LAST""LEFT""LIKE""LONGINT""LOWER""LTRIM""MATCH""MAX",
            "MIN""MINUTE""NATIONAL""NATURAL""NCHAR""NVARCHAR""NEXT""NO",
            "NOT""NULL""NULLIF""NUMERIC""OF""ON""ONLY""OPEN""OPTION""OR",
            "ORDER""OUT""OUTER""OUTPUT""OVERLAPS""PAD""PARTIAL""PREPARE",
            "PRESERVE""PRIMARY""PRIOR""PRIVILEGES""PROCEDURE""PUBLIC""READ",
            "REAL""REFERENCES""RELATIVE""RESTRICT""REVOKE""RIGHT""ROLLBACK",
            "ROWS""RTRIM""SCHEMA""SCROLL""SECOND""SELECT""SESSION_USER""SET",
            "SMALLINT""SOME""SPACE""SQL""SQLCODE""SQLERROR""SQLSTATE""SUBSTR",
            "SUBSTRING""SUM""SYSTEM_USER""TABLE""TEMPORARY""TIMEZONE_HOUR",
            "TIMEZONE_MINUTE""TO""TRAILING""TRANSACTION""TRANSLATE""TRANSLATION",
            "TRUE""UNION""UNIQUE""UNKNOWN""UPDATE""UPPER""USER""USING",
            "VALUES""VARCHAR""VARYING""VIEW""WHENEVER""WHERE""WITH""WORK",
            "WRITE""XML""XMLEXISTS""XMLPARSE""XMLSERIALIZE""YEAR");
New to GrepCode? Check out our FAQ X