Search in sources :

Example 11 with PKStrategy

use of org.sagacity.sqltoy.config.model.PKStrategy in project sagacity-sqltoy by chenrenfei.

the class Oracle11gDialect method update.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#update(org.sagacity.sqltoy.
	 * SqlToyContext , java.io.Serializable, java.lang.String[],
	 * java.sql.Connection)
	 */
@Override
public Long update(SqlToyContext sqlToyContext, Serializable entity, String[] forceUpdateFields, final boolean cascade, final Class[] emptyCascadeClasses, final HashMap<Class, String[]> subTableForceUpdateProps, Connection conn, final Integer dbType, final String dialect, final String tableName) throws Exception {
    return DialectUtils.update(sqlToyContext, entity, NVL_FUNCTION, forceUpdateFields, cascade, (cascade == false) ? null : new GenerateSqlHandler() {

        @Override
        public String generateSql(EntityMeta entityMeta, String[] forceUpdateFields) {
            PKStrategy pkStrategy = entityMeta.getIdStrategy();
            String sequence = entityMeta.getSequence() + NEXTVAL;
            if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
                pkStrategy = PKStrategy.SEQUENCE;
                sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
            }
            return DialectUtils.getSaveOrUpdateSql(sqlToyContext.getUnifyFieldsHandler(), dbType, entityMeta, pkStrategy, forceUpdateFields, VIRTUAL_TABLE, NVL_FUNCTION, sequence, isAssignPKValue(pkStrategy), null);
        }
    }, emptyCascadeClasses, subTableForceUpdateProps, conn, dbType, tableName);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) GenerateSqlHandler(org.sagacity.sqltoy.callback.GenerateSqlHandler) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) PKStrategy(org.sagacity.sqltoy.config.model.PKStrategy)

Example 12 with PKStrategy

use of org.sagacity.sqltoy.config.model.PKStrategy in project sagacity-sqltoy by chenrenfei.

the class Oracle11gDialect method saveAll.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
	 * SqlToyContext , java.util.List,
	 * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
	 */
@Override
public Long saveAll(SqlToyContext sqlToyContext, List<?> entities, final int batchSize, ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName) throws Exception {
    // oracle12c 开始支持identity机制
    EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
    PKStrategy pkStrategy = entityMeta.getIdStrategy();
    boolean isAssignPK = isAssignPKValue(pkStrategy);
    String sequence = entityMeta.getSequence() + NEXTVAL;
    if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
        pkStrategy = PKStrategy.SEQUENCE;
        sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
    }
    String insertSql = DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
    return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize, reflectPropsHandler, conn, dbType, autoCommit);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) PKStrategy(org.sagacity.sqltoy.config.model.PKStrategy)

Example 13 with PKStrategy

use of org.sagacity.sqltoy.config.model.PKStrategy in project sagacity-sqltoy by chenrenfei.

the class OracleDialect method save.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
	 * SqlToyContext , java.io.Serializable, java.util.List, java.sql.Connection)
	 */
@Override
public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType, final String dialect, final String tableName) throws Exception {
    EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
    PKStrategy pkStrategy = entityMeta.getIdStrategy();
    String sequence = entityMeta.getSequence().concat(".nextval");
    if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
        pkStrategy = PKStrategy.SEQUENCE;
        sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
    }
    boolean isAssignPK = OracleDialectUtils.isAssignPKValue(pkStrategy);
    String insertSql = DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
    return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, isAssignPK, ReturnPkType.PREPARD_ID, insertSql, entity, new GenerateSqlHandler() {

        @Override
        public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
            PKStrategy pkStrategy = entityMeta.getIdStrategy();
            String sequence = entityMeta.getSequence().concat(".nextval");
            if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
                pkStrategy = PKStrategy.SEQUENCE;
                sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
            }
            return DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, OracleDialectUtils.isAssignPKValue(pkStrategy), null);
        }
    }, new GenerateSavePKStrategy() {

        @Override
        public SavePKStrategy generate(EntityMeta entityMeta) {
            PKStrategy pkStrategy = entityMeta.getIdStrategy();
            if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
                pkStrategy = PKStrategy.SEQUENCE;
            }
            return new SavePKStrategy(pkStrategy, OracleDialectUtils.isAssignPKValue(pkStrategy));
        }
    }, conn, dbType);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) GenerateSqlHandler(org.sagacity.sqltoy.callback.GenerateSqlHandler) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) PKStrategy(org.sagacity.sqltoy.config.model.PKStrategy) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy)

Example 14 with PKStrategy

use of org.sagacity.sqltoy.config.model.PKStrategy in project sagacity-sqltoy by chenrenfei.

the class OracleDialect method saveAll.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#saveAll(org.sagacity.sqltoy.
	 * SqlToyContext , java.util.List,
	 * org.sagacity.sqltoy.callback.ReflectPropsHandler, java.sql.Connection)
	 */
@Override
public Long saveAll(SqlToyContext sqlToyContext, List<?> entities, final int batchSize, ReflectPropsHandler reflectPropsHandler, Connection conn, final Integer dbType, final String dialect, final Boolean autoCommit, final String tableName) throws Exception {
    // oracle12c 开始支持identity机制
    EntityMeta entityMeta = sqlToyContext.getEntityMeta(entities.get(0).getClass());
    PKStrategy pkStrategy = entityMeta.getIdStrategy();
    boolean isAssignPK = OracleDialectUtils.isAssignPKValue(pkStrategy);
    String sequence = entityMeta.getSequence().concat(".nextval");
    if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
        pkStrategy = PKStrategy.SEQUENCE;
        sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
    }
    String insertSql = DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, isAssignPK, tableName);
    return DialectUtils.saveAll(sqlToyContext, entityMeta, pkStrategy, isAssignPK, insertSql, entities, batchSize, reflectPropsHandler, conn, dbType, autoCommit);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) PKStrategy(org.sagacity.sqltoy.config.model.PKStrategy)

Example 15 with PKStrategy

use of org.sagacity.sqltoy.config.model.PKStrategy in project sagacity-sqltoy by chenrenfei.

the class OceanBaseDialect method save.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.sagacity.sqltoy.dialect.Dialect#save(org.sagacity.sqltoy.
	 * SqlToyContext , java.io.Serializable, java.util.List, java.sql.Connection)
	 */
@Override
public Object save(SqlToyContext sqlToyContext, Serializable entity, Connection conn, final Integer dbType, final String dialect, final String tableName) throws Exception {
    EntityMeta entityMeta = sqlToyContext.getEntityMeta(entity.getClass());
    PKStrategy pkStrategy = entityMeta.getIdStrategy();
    String sequence = entityMeta.getSequence().concat(".nextval");
    if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
        pkStrategy = PKStrategy.SEQUENCE;
        sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
    }
    String insertSql = DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, OracleDialectUtils.isAssignPKValue(pkStrategy), tableName);
    return DialectUtils.save(sqlToyContext, entityMeta, pkStrategy, OracleDialectUtils.isAssignPKValue(pkStrategy), ReturnPkType.PREPARD_ID, insertSql, entity, new GenerateSqlHandler() {

        @Override
        public String generateSql(EntityMeta entityMeta, String[] forceUpdateField) {
            PKStrategy pkStrategy = entityMeta.getIdStrategy();
            String sequence = entityMeta.getSequence().concat(".nextval");
            if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
                pkStrategy = PKStrategy.SEQUENCE;
                sequence = entityMeta.getFieldsMeta().get(entityMeta.getIdArray()[0]).getDefaultValue();
            }
            return DialectExtUtils.generateInsertSql(dbType, entityMeta, pkStrategy, NVL_FUNCTION, sequence, OracleDialectUtils.isAssignPKValue(pkStrategy), null);
        }
    }, new GenerateSavePKStrategy() {

        @Override
        public SavePKStrategy generate(EntityMeta entityMeta) {
            PKStrategy pkStrategy = entityMeta.getIdStrategy();
            if (pkStrategy != null && pkStrategy.equals(PKStrategy.IDENTITY)) {
                pkStrategy = PKStrategy.SEQUENCE;
            }
            return new SavePKStrategy(pkStrategy, OracleDialectUtils.isAssignPKValue(pkStrategy));
        }
    }, conn, dbType);
}
Also used : EntityMeta(org.sagacity.sqltoy.config.model.EntityMeta) GenerateSqlHandler(org.sagacity.sqltoy.callback.GenerateSqlHandler) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy) PKStrategy(org.sagacity.sqltoy.config.model.PKStrategy) SavePKStrategy(org.sagacity.sqltoy.dialect.model.SavePKStrategy) GenerateSavePKStrategy(org.sagacity.sqltoy.callback.GenerateSavePKStrategy)

Aggregations

PKStrategy (org.sagacity.sqltoy.config.model.PKStrategy)30 EntityMeta (org.sagacity.sqltoy.config.model.EntityMeta)28 SavePKStrategy (org.sagacity.sqltoy.dialect.model.SavePKStrategy)25 GenerateSavePKStrategy (org.sagacity.sqltoy.callback.GenerateSavePKStrategy)17 GenerateSqlHandler (org.sagacity.sqltoy.callback.GenerateSqlHandler)14 GenerateSavePKStrategy (org.sagacity.sqltoy.dialect.handler.GenerateSavePKStrategy)8 GenerateSqlHandler (org.sagacity.sqltoy.dialect.handler.GenerateSqlHandler)6 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ReflectPropsHandler (org.sagacity.sqltoy.callback.ReflectPropsHandler)2 IOException (java.io.IOException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 PreparedStatementResultHandler (org.sagacity.sqltoy.callback.PreparedStatementResultHandler)1 ReturnPkType (org.sagacity.sqltoy.dialect.model.ReturnPkType)1