Skip to content

Commit

Permalink
Merge pull request #27 from vzakharchenko/cacheConcurrent
Browse files Browse the repository at this point in the history
Concurent Cache Fix
  • Loading branch information
vzakharchenko authored Mar 19, 2020
2 parents c2e25db + b72ca9c commit 92e2eeb
Show file tree
Hide file tree
Showing 57 changed files with 802 additions and 1,103 deletions.
6 changes: 6 additions & 0 deletions dynamic-orm-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,11 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.10.6</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.github.vzakharchenko.dynamic.orm.core;

import java.io.Serializable;

/**
* Created with IntelliJ IDEA.
* User: vassio
* Date: 13.04.15
* Time: 18:16
*/
public interface DMLModel {
public interface DMLModel extends Serializable {

default boolean isDynamicModel() {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.querydsl.sql.RelationalPath;
import com.querydsl.sql.SQLCommonQuery;

import java.io.Serializable;
import java.util.List;

/**
Expand All @@ -25,6 +26,7 @@ public interface SelectBuilder
*/
<MODEL extends DMLModel> List<MODEL> findAll(RelationalPath<?> qTable,
Class<MODEL> modelClass);

/**
* The fetch all data models from a database using sqlQuery query.
* the result is mapped to the data models
Expand Down Expand Up @@ -91,7 +93,7 @@ <MODEL extends DMLModel> List<MODEL> findAll(SQLCommonQuery<?> sqlQuery,
* @param expression any QueryDsl Expression
* @return List of results
*/
<TYPE> List<TYPE> findAll(SQLCommonQuery<?> sqlQuery, Expression<TYPE> expression);
<TYPE extends Serializable> List<TYPE> findAll(SQLCommonQuery<?> sqlQuery, Expression<TYPE> expression);

/**
* The fetch a data model from a database using sqlQuery query.
Expand Down Expand Up @@ -140,7 +142,7 @@ <MODEL extends DMLModel> MODEL findOne(SQLCommonQuery<?> sqlQuery,
* @param expression any QueryDsl Expression
* @return typed result
*/
<TYPE> TYPE findOne(SQLCommonQuery<?> sqlQuery,
<TYPE extends Serializable> TYPE findOne(SQLCommonQuery<?> sqlQuery,
Expression<TYPE> expression);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.datasource.DataSourceUtils;

import java.io.Serializable;
import java.sql.Connection;
import java.util.List;

Expand Down Expand Up @@ -73,7 +74,8 @@ public <MODEL extends DMLModel> List<MODEL> findAll(SQLCommonQuery<?> sqlQuery,
}

@Override
public <TYPE> List<TYPE> findAll(SQLCommonQuery<?> sqlQuery, Expression<TYPE> expression) {
public <TYPE extends Serializable>
List<TYPE> findAll(SQLCommonQuery<?> sqlQuery, Expression<TYPE> expression) {

try {
Connection connection = DataSourceUtils.getConnection(queryContext.getDataSource());
Expand Down Expand Up @@ -120,7 +122,8 @@ public <MODEL extends DMLModel> MODEL findOne(SQLCommonQuery<?> sqlQuery,
}

@Override
public <TYPE> TYPE findOne(SQLCommonQuery<?> sqlQuery, Expression<TYPE> expression) {
public <TYPE extends Serializable> TYPE findOne(SQLCommonQuery<?> sqlQuery,
Expression<TYPE> expression) {
List<TYPE> list = findAll(sqlQuery, expression);
if (list.isEmpty()) {
return null;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,21 @@ public Path getColumn() {
return column == null ? columnMetaDataInfo.getColumn() : column;
}

@Override
public void setColumn(Path column) {
this.column = column;
}

@Override
public Integer getSize() {
return size == null ? columnMetaDataInfo.getSize() : size;
}

@Override
public void setSize(Integer size) {
this.size = size;
}

@Override
public String getJdbcType() {
return columnMetaDataInfo.getJdbcType();
Expand All @@ -34,6 +44,11 @@ public Integer getDecimalDigits() {
return decimalDigits == null ? columnMetaDataInfo.getDecimalDigits() : decimalDigits;
}

@Override
public void setDecimalDigits(Integer decimalDigits) {
this.decimalDigits = decimalDigits;
}

@Override
public Boolean isNullable() {
return nullable == null ? columnMetaDataInfo.isNullable() : nullable;
Expand All @@ -44,21 +59,6 @@ public Boolean isPrimaryKey() {
return columnMetaDataInfo.isPrimaryKey();
}

@Override
public void setColumn(Path column) {
this.column = column;
}

@Override
public void setSize(Integer size) {
this.size = size;
}

@Override
public void setDecimalDigits(Integer decimalDigits) {
this.decimalDigits = decimalDigits;
}

@Override
public void setNullable(Boolean nullable) {
this.nullable = nullable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ public abstract class QAbstractDynamicTable<DYNAMIC_TABLE extends QAbstractDynam
extends RelationalPathBase<Object> {

protected final Map<String, Path<?>> columns = new LinkedHashMap<>();
private final Map<String, Path<?>> removedColumns = new LinkedHashMap<>();

protected final Map<Path<?>, ColumnMetaDataInfo> columnMetaDataInfoMap = new HashMap<>();
private final Map<String, Path<?>> removedColumns = new LinkedHashMap<>();


protected QAbstractDynamicTable(String tableName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public interface QDynamicTableFactory {

/**
* Is table exists
*
* @param tableName
* @return true if exists otherwise false
*/
Expand All @@ -55,7 +56,7 @@ public interface QDynamicTableFactory {
/**
* drop sequence
*
* @param sequenceNames
* @param sequenceNames
* @return tableBuilder
* @see QDynamicTableFactory
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ public class QCustomColumnImpl

private String jdbc;

public QCustomColumnImpl(String name) {
super(name);
}

public void setColumn(Path<?> column) {
this.column = column;
}
Expand All @@ -19,10 +23,6 @@ public void setJdbc(String jdbc) {
this.jdbc = jdbc;
}

public QCustomColumnImpl(String name) {
super(name);
}

public void setDecimalDigits(Integer d) {
this.dd = d;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import com.querydsl.core.types.PathMetadata;

public interface CustomColumnCreator {
Path<?> create(PathMetadata metadata);
Path<?> create(PathMetadata metadata);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public interface QCustomColumnBuilder
extends QNumberColumnBuilder<RETURN_TYPE, BUILDER_TYPE> {

BUILDER_TYPE jdbcType(LiquibaseDataType dataType);

BUILDER_TYPE jdbcType(String liquibaseType);

BUILDER_TYPE column(CustomColumnCreator customColumnCreator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public abstract class QDefaultColumnBuilder<COLUMN_TYPE extends QDefaultColumn,
BUILDER_TYPE extends QColumnBuilder<QTableColumn, ?>>
implements QColumnBuilder<QTableColumn, BUILDER_TYPE> {
protected final COLUMN_TYPE columnType;
private final QTableColumnContext qTableColumn;
protected final QDynamicTable qDynamicTable;
private final QTableColumnContext qTableColumn;

protected QDefaultColumnBuilder(QTableColumnContext qTableColumnContext,
QDynamicTable dynamicTable, String columnName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ public final class JavaTypeUtils {

private static final Map<Integer, Class<?>> DEFAULT_TYPES = new HashMap<>();

private JavaTypeUtils() {
}

// CHECKSTYLE:OFF
static {
registerDefault(-101, Object.class);
Expand Down Expand Up @@ -78,6 +75,9 @@ private JavaTypeUtils() {

}

private JavaTypeUtils() {
}

private static void registerDefault(int sqlType, Class<?> javaType) {
DEFAULT_TYPES.put(sqlType, javaType);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.github.vzakharchenko.dynamic.orm.core.helper;

import com.github.vzakharchenko.dynamic.orm.core.DMLModel;
import com.github.vzakharchenko.dynamic.orm.core.cache.*;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedAllData;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedColumn;
import com.github.vzakharchenko.dynamic.orm.core.cache.CachedColumnWithValue;
import com.github.vzakharchenko.dynamic.orm.core.cache.MapModel;
import com.github.vzakharchenko.dynamic.orm.core.dynamic.QDynamicTable;
import com.github.vzakharchenko.dynamic.orm.core.dynamic.dml.DynamicTableModel;
import com.github.vzakharchenko.dynamic.orm.core.query.QueryContextImpl;
import com.querydsl.core.types.Path;
import com.querydsl.sql.RelationalPath;
import org.apache.commons.collections4.MapUtils;
Expand All @@ -21,20 +23,15 @@
*/
public abstract class CacheHelper {

public static void checkModelIsDeleted(
QueryContextImpl queryContext, DMLModel model, RelationalPath<?> qTable) {
PrimaryKeyCacheKey primaryKeyCacheKey = buildPrimaryKeyCacheModel(model, qTable);
if (queryContext.getTransactionCache().isDeleted(primaryKeyCacheKey)) {
throw new IllegalStateException(qTable + ":" + model + "is deleted");
}
}
// public static void checkModelIsDeleted(
// QueryContextImpl queryContext, DMLModel model, RelationalPath<?> qTable) {
// CompositeKey primaryKeyCacheKey = buildPrimaryKeyCacheModel(model, qTable);
// if (queryContext.getTransactionCache().isDeleted(primaryKeyCacheKey)) {
// throw new IllegalStateException(qTable + ":" + model + "is deleted");
// }
// }


public static PrimaryKeyCacheKey buildPrimaryKeyCacheKey(
CompositeKey key) {
return new PrimaryKeyCacheKey(key);
}

public static CachedAllData buildAllDataCache(RelationalPath<?> qTable) {
return new CachedAllData(qTable);
}
Expand All @@ -48,14 +45,10 @@ public static CachedColumn buildCachedColumn(Path column) {
return new CachedColumn(column);
}

public static CachedAllData buildCachedAllData(RelationalPath<?> qTable) {
return new CachedAllData(qTable);
}

public static PrimaryKeyCacheKey buildPrimaryKeyCacheModel(
public static CompositeKey buildPrimaryKeyCacheModel(
DMLModel model, RelationalPath<?> qTable) {
return new PrimaryKeyCacheKey(PrimaryKeyHelper
.getPrimaryKeyValues(model, qTable));
return PrimaryKeyHelper
.getPrimaryKeyValues(model, qTable);
}

public static <MODEL extends DMLModel> MODEL newInstance(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static CompositeKeyBuilder create(RelationalPath qTable) {
return new CompositeKeyBuilder(qTable);
}

public CompositeKeyBuilder addPrimaryKey(
String column, Object value) {
return addPrimaryKey(ModelHelper.getColumnByName(qTable, column), value);
}

public CompositeKeyBuilder addPrimaryKey(
Path column, Object value) {
Assert.notNull(column, "Column is Null");
Expand Down
Loading

0 comments on commit 92e2eeb

Please sign in to comment.