/** * PUBLIC: * Set the database platform to be JDBC. */ public void useJDBC() { DatabasePlatform newPlatform = new DatabasePlatform(); getPlatform().copyInto(newPlatform); setPlatform(newPlatform); }
/** * Return the JDBC type for the Java type. For some reason PostgreSQL does * not seem to like the JDBC Blob type (PostgreSQL 8.2). */ @Override public int getJDBCType(Class javaType) { if (javaType == ClassConstants.BLOB) { return Types.LONGVARBINARY; } return super.getJDBCType(javaType); }
/** * INTERNAL: * return the original field name based on the argument name. */ protected String getFieldName(String argumentName) { if (getSession().getPlatform().isOracle()) { return argumentName.substring(getSession().getPlatform().getStoredProcedureParameterPrefix().length()); } else { return argumentName; } }
DatabasePlatform platform = session.getPlatform(); @SuppressWarnings("unchecked") Map<Integer, ExpressionOperator> platformOperators = platform.getPlatformOperators(); String dbms; platform.setShouldBindLiterals(false); if (platform.isMySQL()) { dbms = "mysql"; } else if (platform.isOracle()) { dbms = "oracle"; } else if (platform.isSQLServer()) { dbms = "microsoft"; } else if (platform.isSybase()) { dbms = "sybase"; } else if (platform.isH2()) { dbms = "h2"; } else {
@PostConstruct @Transactional public void init() throws SQLException { jdbcService.runJdbcWork(connection -> { String fileName; if (connection.profile().isMySQL()) { fileName = "mysql"; } else if (connection.profile().isH2()) { fileName = "h2"; } else throw new IllegalStateException("not support for:" + connection.getConnection()); try { try (Statement statement = connection.getConnection().createStatement()) { statement.executeUpdate("DROP TABLE IF EXISTS `UNSETTLEMENTUSAGESTOCK`"); statement.executeUpdate("DROP TABLE IF EXISTS `USAGESTOCK`"); statement.executeUpdate("DROP TABLE IF EXISTS `UsageStockInfo`"); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "0.sql").getInputStream() , Charset.forName("UTF-8"))); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "1.sql").getInputStream() , Charset.forName("UTF-8"))); statement.executeUpdate(StreamUtils.copyToString(new ClassPathResource("/logistics_views/" + fileName + "2.sql").getInputStream() , Charset.forName("UTF-8"))); } } catch (IOException e) { throw new IllegalStateException("读取SQL失败", e); } }); } }
/** * Initialize any platform-specific operators */ protected void initializePlatformOperators() { super.initializePlatformOperators(); addOperator(ExpressionOperator.simpleTwoArgumentFunction(ExpressionOperator.Concat, "CONCAT")); }
public static Project loadDynamicProject(Project project, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) { if (project != null) { if (login == null) { if (project.getLogin() == null) { project.setLogin(new DatabaseLogin()); } } else { project.setLogin(login); } if (project.getLogin().getPlatform() == null) { project.getLogin().setPlatform(new DatabasePlatform()); } project.getLogin().getPlatform().getConversionManager().setLoader(dynamicClassLoader); for (Iterator<?> i = project.getAliasDescriptors().values().iterator(); i.hasNext();) { ClassDescriptor descriptor = (ClassDescriptor) i.next(); if (descriptor.getJavaClass() == null) { createType(dynamicClassLoader, descriptor, project); } } project.convertClassNamesToClasses(dynamicClassLoader); } return project; }
protected Hashtable buildFieldTypes() { Hashtable fieldTypeMapping; fieldTypeMapping = super.buildFieldTypes(); fieldTypeMapping.put(Boolean.class, new FieldTypeDefinition("BOOLEAN")); fieldTypeMapping.put(Long.class, new FieldTypeDefinition("NUMERIC", 19)); fieldTypeMapping.put(Short.class, new FieldTypeDefinition("NUMERIC", 5)); fieldTypeMapping.put(Byte.class, new FieldTypeDefinition("NUMERIC", 3)); fieldTypeMapping.put(java.math.BigInteger.class, new FieldTypeDefinition("NUMERIC", 19)); fieldTypeMapping.put(Integer.class, new FieldTypeDefinition("INTEGER", false)); fieldTypeMapping.put(Float.class, new FieldTypeDefinition("REAL", false)); fieldTypeMapping.put(Double.class, new FieldTypeDefinition("DOUBLE", false)); fieldTypeMapping.put(Short.class, new FieldTypeDefinition("SMALLINT", false)); fieldTypeMapping.put(java.math.BigDecimal.class, new FieldTypeDefinition("DECIMAL")); fieldTypeMapping.put(Number.class, new FieldTypeDefinition("DECIMAL")); fieldTypeMapping.put(Character.class, new FieldTypeDefinition("CHARACTER")); return fieldTypeMapping; }
@Override protected void setSingleResult(XRServiceAdapter xrService, StoredProcedureCall spCall, QName resultType) { if (isCursorType(xrService, resultType)) { spCall.useUnnamedCursorOutputAsResultSet(); } else { StoredFunctionCall sfCall = (StoredFunctionCall)spCall; Class<?> clz = SCHEMA_2_CLASS.get(resultType); if (clz != null) { sfCall.setResult("", clz); } else { sfCall.setResult("", OBJECT); } DatabasePlatform platform = xrService.getORSession().getPlatform(); if (platform == null) { platform = new DatabasePlatform(); } // StoredFunction's return value is the first parameter ((DatabaseField)sfCall.getParameters().get(0)).setSqlType( platform.getJDBCType(clz)); } } }
/** * INTERNAL: * This method checks that tables are present in the database. */ public boolean checkTable(DatabaseTable table, AbstractSession session) { if (getTables().size() == 0) { // load the tables from the session initializeTables(session); } boolean tableExists = getTables().contains(table.getName()); //Some DBs (e.g. some versions of MySQL) convert all the table names to lower case. if (!tableExists && session.getPlatform().isMySQL()) { return getTables().contains(table.getName().toLowerCase()); } return tableExists; }
/** * PUBLIC: * The default value to substitute for database NULLs can be configured * on a per-class basis. * Example: login.setDefaultNullValue(long.class, new Long(0)) */ public void setDefaultNullValue(Class type, Object value) { getPlatform().getConversionManager().setDefaultNullValue(type, value); }
/** * PUBLIC: * Create a new login. */ public DatabaseLogin() { this(new DatabasePlatform()); }
/** * PUBLIC: * Set the database platform to be SQL Server. */ public void useSQLServer() { if (getPlatform().isSQLServer()) { return; } DatabasePlatform newPlatform = new SQLServerPlatform(); getPlatform().copyInto(newPlatform); setPlatform(newPlatform); }
protected void prepareUpdateAllUsingTempStorage(HashMap tables_databaseFieldsToValues, HashMap<DatabaseTable, List<DatabaseField>> tablesToPrimaryKeyFields) { if(getExecutionSession().getPlatform().supportsTempTables()) { prepareUpdateAllUsingTempTables(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); } else if(getExecutionSession().getPlatform().isOracle()) { prepareUpdateAllUsingOracleAnonymousBlock(tables_databaseFieldsToValues, tablesToPrimaryKeyFields); } else { throw QueryException.tempTablesNotSupported(getQuery(), Helper.getShortClassName(getExecutionSession().getPlatform())); } }
/** * INTERNAL: Generates the mapping stored procedures for this descriptor. * currently only 1:1 and 1:M are supported */ protected Hashtable generateMappingStoredProcedures(ClassDescriptor descriptor) { Vector mappings = descriptor.getMappings(); Hashtable mappingSP = new Hashtable(); Hashtable mappingTable; for (Enumeration enumtr = mappings.elements(); enumtr.hasMoreElements();) { mappingTable = new Hashtable(); DatabaseMapping mapping = (DatabaseMapping)enumtr.nextElement(); if (mapping.isOneToManyMapping()) { if (!getSession().getPlatform().isOracle()) { //reads not supported in oracle mappingTable.put("1MREAD", generateOneToManyMappingReadProcedure((OneToManyMapping)mapping)); } if (mapping.isPrivateOwned()) { //generate delete all for 1:M query mappingTable.put("1MDALL", generateOneToManyMappingDeleteAllProcedure((OneToManyMapping)mapping)); } mappingSP.put(mapping.getAttributeName(), mappingTable); } } return mappingSP; }
DatabasePlatform dbPlatform = new DatabasePlatform(); dbPlatform.getDbIdentity().setIdType(IdType.IDENTITY); dbPlatform.getDbIdentity().setSupportsGetGeneratedKeys(true); dbPlatform.getDbIdentity().setSupportsSequence(false); dbPlatform.getDbIdentity().setSupportsIdentity(true); serverConfig.setDatabasePlatform(dbPlatform);
/** * 增强当前数据库以符合该类规则 * * @param connection 链接 * @throws SQLException */ public static void enhance(ConnectionProvider connection) throws SQLException { if (connection.profile().isH2()) { try (Statement statement = connection.getConnection().createStatement()) { statement.executeUpdate("DROP ALIAS IF EXISTS `IF`"); statement.executeUpdate("CREATE ALIAS IF NOT EXISTS `IF` FOR \"" + JpaFunctionUtils.class.getName() + ".h2If\""); // // statement.executeUpdate("DROP ALIAS IF EXISTS `DATEDIFF`"); // statement.executeUpdate("CREATE ALIAS IF NOT EXISTS `DATEDIFF` FOR \"" + JpaFunctionUtils.class.getName() + ".H2DATEDIFF\""); } } }