@Override public void connectedConfiguration(Connection conn) throws SQLException { super.connectedConfiguration(conn); if (versionEqualOrLaterThan(10, 5)) { supportsSelectStartIndex = true; supportsSelectEndIndex = true; } }
public Connection decorate(Connection conn) throws SQLException { // some versions of the DB2 driver seem to default to // READ_UNCOMMITTED, which will prevent locking from working // (multiple SELECT ... FOR UPDATE statements are allowed on // the same instance); if we have not overridden the // transaction isolation in the configuration, default to // TRANSACTION_READ_COMMITTED conn = super.decorate(conn); if (conf.getTransactionIsolationConstant() == -1 && conn.getTransactionIsolation() < conn.TRANSACTION_READ_COMMITTED) conn.setTransactionIsolation(conn.TRANSACTION_READ_COMMITTED); return conn; }
public OpenJPAException newStoreException(String msg, SQLException[] causes, Object failed) { if (appendExtendedExceptionText == true && causes != null && causes.length > 0) { msg = appendExtendedExceptionMsg(msg, causes[0]); } return super.newStoreException(msg, causes, failed); }
public boolean supportsRandomAccessResultSet(Select sel, boolean forUpdate) { return !forUpdate && super.supportsRandomAccessResultSet(sel, forUpdate); }
/** * Return the batch limit. If the batchLimit is -1, change it to 100 for * best performance */ public int getBatchLimit() { int limit = super.getBatchLimit(); if (limit == UNLIMITED) { limit = defaultBatchLimit; if (log.isTraceEnabled()) log.trace(_loc.get("batch_unlimit", String.valueOf(limit))); } return limit; }
public void closeDataSource(DataSource dataSource) { super.closeDataSource(dataSource); if (!shutdownOnClose) return; // as well as closing the DataSource, we also need to // shut down the instance if we are using an embedded database, which // can only be done by connecting to the same URL with the // ";shutdown=true" string appended to the end // see: http://db.apache.org/derby/docs/dev/devguide/tdevdvlp40464.html if (conf != null && conf.getConnectionDriverName() != null && conf.getConnectionDriverName().indexOf("EmbeddedDriver") != -1) { try { DriverManager.getConnection(conf.getConnectionURL() + ";shutdown=true"); } catch (SQLException e) { // we actually expect a SQLException to be thrown here: // Derby strangely uses that as a mechanism to report // a successful shutdown } } }
/** * If this dictionary supports XML type, * use this method to append xml predicate. * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison * @param rhs the right hand side of the comparison * @param lhsxml indicates whether the left operand maps to xml * @param rhsxml indicates whether the right operand maps to xml */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml && rhsxml) appendXmlComparison2(buf, op, lhs, rhs); else if (lhsxml) appendXmlComparison1(buf, op, lhs, rhs); else appendXmlComparison1(buf, op, rhs, lhs); }
protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel, int idx) { // if this is a literal value, add a cast... Object val = sel.getSelects().get(idx); if (val instanceof Lit) selectSQL.append("CAST("); // ... and add the select per super's behavior... super.appendSelect(selectSQL, alias, sel, idx); // ... and finish the cast if (val instanceof Lit) { Class c = ((Lit) val).getType(); int javaTypeCode = JavaTypes.getTypeCode(c); int jdbcTypeCode = getJDBCType(javaTypeCode, false); String typeName = getTypeName(jdbcTypeCode); selectSQL.append(" AS " + typeName); // if the literal is a string, use the default char col size // in the cast statement. if (String.class.equals(c)) selectSQL.append("(" + characterColumnSize + ")"); selectSQL.append(")"); } }
@Override public void substring(SQLBuffer buf, FilterValue str, FilterValue start, FilterValue length) { buf.append("SUBSTR(CAST(("); str.appendTo(buf); buf.append(") AS VARCHAR(").append(Integer.toString(varcharCastLength)) .append(")), "); if (start.getValue() instanceof Number) { buf.append(Long.toString(toLong(start))); } else { buf.append("CAST(("); start.appendTo(buf); buf.append(") AS INTEGER)"); } if (length != null) { buf.append(", "); if (length.getValue() instanceof Number) { buf.append(Long.toString(toLong(length))); } else { buf.append("CAST(("); length.appendTo(buf); buf.append(") AS INTEGER)"); } } buf.append(")"); } }
super.setBatchLimit(defaultBatchLimit);
public boolean supportsRandomAccessResultSet(Select sel, boolean forUpdate) { return !forUpdate && super.supportsRandomAccessResultSet(sel, forUpdate); }
/** * Return the batch limit. If the batchLimit is -1, change it to 100 for * best performance */ public int getBatchLimit() { int limit = super.getBatchLimit(); if (limit == UNLIMITED) { limit = defaultBatchLimit; if (log.isTraceEnabled()) log.trace(_loc.get("batch_unlimit", String.valueOf(limit))); } return limit; }
public void closeDataSource(DataSource dataSource) { super.closeDataSource(dataSource); if (!shutdownOnClose) return; // as well as closing the DataSource, we also need to // shut down the instance if we are using an embedded database, which // can only be done by connecting to the same URL with the // ";shutdown=true" string appended to the end // see: http://db.apache.org/derby/docs/dev/devguide/tdevdvlp40464.html if (conf != null && conf.getConnectionDriverName() != null && conf.getConnectionDriverName().indexOf("EmbeddedDriver") != -1) { try { DriverManager.getConnection(conf.getConnectionURL() + ";shutdown=true"); } catch (SQLException e) { // we actually expect a SQLException to be thrown here: // Derby strangely uses that as a mechanism to report // a successful shutdown } } }
/** * If this dictionary supports XML type, * use this method to append xml predicate. * * @param buf the SQL buffer to write the comparison * @param op the comparison operation to perform * @param lhs the left hand side of the comparison * @param rhs the right hand side of the comparison * @param lhsxml indicates whether the left operand maps to xml * @param rhsxml indicates whether the right operand maps to xml */ public void appendXmlComparison(SQLBuffer buf, String op, FilterValue lhs, FilterValue rhs, boolean lhsxml, boolean rhsxml) { super.appendXmlComparison(buf, op, lhs, rhs, lhsxml, rhsxml); if (lhsxml && rhsxml) appendXmlComparison2(buf, op, lhs, rhs); else if (lhsxml) appendXmlComparison1(buf, op, lhs, rhs); else appendXmlComparison1(buf, op, rhs, lhs); }
protected void appendSelect(SQLBuffer selectSQL, Object alias, Select sel, int idx) { // if this is a literal value, add a cast... Object val = sel.getSelects().get(idx); boolean toCast = (val instanceof Lit) && ((Lit)val).getParseType() != Literal.TYPE_DATE && ((Lit)val).getParseType() != Literal.TYPE_TIME && ((Lit)val).getParseType() != Literal.TYPE_TIMESTAMP; if (toCast) selectSQL.append("CAST("); // ... and add the select per super's behavior... super.appendSelect(selectSQL, alias, sel, idx); // ... and finish the cast if (toCast) { Class<?> c = ((Lit) val).getType(); int javaTypeCode = JavaTypes.getTypeCode(c); int jdbcTypeCode = getJDBCType(javaTypeCode, false); String typeName = getTypeName(jdbcTypeCode); selectSQL.append(" AS " + typeName); // if the literal is a string, use the default char col size // in the cast statement. if (String.class.equals(c)) selectSQL.append("(" + getCastStringColumnSize(val) + ")"); selectSQL.append(")"); } }
@Override public void substring(SQLBuffer buf, FilterValue str, FilterValue start, FilterValue length) { buf.append("SUBSTR(CAST(("); str.appendTo(buf); buf.append(") AS VARCHAR(").append(Integer.toString(varcharCastLength)) .append(")), "); if (start.getValue() instanceof Number) { buf.append(Long.toString(toLong(start))); } else { buf.append("CAST(("); start.appendTo(buf); buf.append(") AS INTEGER)"); } if (length != null) { buf.append(", "); if (length.getValue() instanceof Number) { buf.append(Long.toString(toLong(length))); } else { buf.append("CAST(("); length.appendTo(buf); buf.append(") AS INTEGER)"); } } buf.append(")"); } }
super.setBatchLimit(defaultBatchLimit);
@Override public void connectedConfiguration(Connection conn) throws SQLException { super.connectedConfiguration(conn); if (versionEqualOrLaterThan(10, 5)) { supportsSelectStartIndex = true; supportsSelectEndIndex = true; } }
public boolean supportsRandomAccessResultSet(Select sel, boolean forUpdate) { return !forUpdate && super.supportsRandomAccessResultSet(sel, forUpdate); }
public OpenJPAException newStoreException(String msg, SQLException[] causes, Object failed) { if (appendExtendedExceptionText == true && causes != null && causes.length > 0) { msg = appendExtendedExceptionMsg(msg, causes[0]); } return super.newStoreException(msg, causes, failed); }