- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
首先,我对 Spring Boot、REST API,尤其是 apache ignite 还很陌生,所以这可能是一个小问题,但我暂时无法解决。
我有一个 Oracle 12c 数据库,其中包含一些表,问题中的两个表是:
create table la_license_count (
total_count number not null default 100,
active_count number not null default 0,
temporary_count number not null default 0,
id number not null
);
列“id”是主键,除此之外还有检查约束和唯一索引。
create table la_license_mapping (
client_id varchar2(200 byte) not null,
license_count number not null default 0,
license_type chat(1 byte) not null default 'F',
registered_at date not null default sysdate,
keepalive_time number,
id number not null;
);
列“id”是主键,除此之外还有检查约束和唯一约束。
需要基于 Spring Boot 的 REST API 来读取和更新此表。 Apache Ignite 缓存层需要位于 REST API 和数据库之间。这是按如下方式实现的。整个解决方案基于此指南: https://dzone.com/articles/in-memory-data-grid-with-apache-ignite ,并根据其他 StackOverflow 和各种论坛文章(当它不起作用时)进行了一些更改。
数据库 bean(自定义,因为密码以自定义方式在日志中加密)。 DataSource 本身工作正常,通过使用 Autowiring 的 JdbcTemplate 执行 CallableStatement 进行了测试;
@Configuration
public class DatabaseBean {
@Autowired
private ConfigReader configReader;
@Bean(destroyMethod = "")
public DataSource dataSource() {
DatabaseSettings db = configReader.getDatabaseSettings();
return DataSourceBuilder
.create()
.url(db.getConnectionString())
.username(db.getUserName())
.password(db.isPasswordEncrypted() ? Encryptor.decrypt(db.getPassword()) : db.getPassword())
.driverClassName(db.getDriverClassName())
.build();
}
}
实体类:
public class LALicenseCount implements Serializable {
private static final long serialVersionUID = -1L;
private final AtomicLong ID_GEN = new AtomicLong();
private Long id;
private Long totalCount;
private Long activeCount;
private Long temporaryCount;
// getters, setters
public void init() {
this.id = ID_GEN.getAndIncrement();
}
// Various methods for business logic
}
public class LALicenseMapping implements Serializable {
private static final long serialVersionUID = -1L;
private final AtomicLong ID_GEN = new AtomicLong();
private Long id;
@QuerySqlField(index = false)
private String clientID;
private Long licenseCount;
@QuerySqlField(index = false)
private String licenseType;
private Date registeredAt;
private Long keepaliveTime;
// getters, setters
public void init() {
this.id = ID_GEN.getAndIncrement();
}
// Various methods for business logic
}
存储库:
@Repository
@RepositoryConfig(cacheName = "LALicenseCountCache")
public interface LALicenseCountRepository extends IgniteRepository<LALicenseCount, Long> {
}
@Repository
@RepositoryConfig(cacheName = "LALicenseMappingCache")
public interface LALicenseMappingRepository extends IgniteRepository<LALicenseMapping, Long> {
List<LALicenseMapping> findByClientID(String clientID);
List<LALicenseMapping> findByClientIDAndLicenseType(String clientID, String licenseType);
}
点燃 bean :
@Component
public class IgniteConfigurationBean {
@Autowired
private ConfigReader configReader;
@Autowired
private ApplicationContext applicationContext;
@Bean
public Ignite igniteInstance() {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setIgniteInstanceName("ignite-1");
cfg.setPeerClassLoadingEnabled(true);
CacheConfiguration<Long, LALicenseCount> ccfg = new CacheConfiguration<>("LALicenseCountCache");
ccfg.setIndexedTyped(Long.class, LALicenseCount.class);
ccfg.setWriteBehind(true);
ccfg.setReadThrough(true);
ccfg.setWriteThrough(true);
CacheJdbcPojoStoreFactory<Long, LALicenseCount> f = new CacheJdbcPojoStoreFactory<>();
f.setDataSourceBean("dataSource");
f.setDialect(new OracleDialect());
JdbcType t = new JdbcType();
t.setCacheName("LALicenseCountCache");
t.setKeyType(Long.class);
t.setValueType(LALicenseCount.class);
t.setDatabaseTable("la_license_count");
t.setDatabaseSchema(configReader.getDatabaseSettings().getUserName());
t.setKeyFields(new JdbcTypeField(Types.INTEGER, "id", Long.class, "id"));
t.setValueFields(
new JdbcTypeField(Types.INTEGER, "total_count", Long.class, "totalCount"),
new JdbcTypeField(Types.INTEGER, "active_count", Long.class, "activeCount"),
new JdbcTypeField(Types.INTEGER, "temporary_count", Long.class, "temporaryCount"));
f.setTypes(t);
ccfg.setCacheStoreFactory(f);
CacheConfiguration<Long, LALicenseMapping> ccfg2 = new CacheConfiguration<>("LALicenseMappingCache");
ccfg2.setIndexedTyped(Long.class, LALicenseMapping.class);
ccfg2.setWriteBehind(true);
ccfg2.setReadThrough(true);
ccfg2.setWriteThrough(true);
CacheJdbcPojoStoreFactory<Long, LALicenseMapping> f2 = new CacheJdbcPojoStoreFactory<>();
f2.setDataSourceBean("dataSource");
f2.setDialect(new OracleDialect());
JdbcType t2 = new JdbcType();
t2.setCacheName("LALicenseMappingCache");
t2.setKeyType(Long.class);
t2.setValueType(LALicenseCount.class);
t2.setDatabaseTable("la_license_mapping");
t2.setDatabaseSchema(configReader.getDatabaseSettings().getUserName());
t2.setKeyFields(new JdbcTypeField(Types.INTEGER, "id", Long.class, "id"));
t2.setValueFields(
new JdbcTypeField(Types.VARCHAR, "client_id", String.class, "clientID"),
new JdbcTypeField(Types.INTEGER, "license_count", Long.class, "licenseCount"),
new JdbcTypeField(Types.VARCHAR, "license_type", String.class, "licenseType"),
new JdbcTypeField(Types.DATE, "registered_at", java.sql.Date.class, "registeredAt"),
new JdbcTypeField(Types.INTEGER, "keepalive_time", Long.class, "keepaliveTime"));
f2.setTypes(t2);
ccfg2.setCacheStoreFactory(f2);
cfg.setCacheConfiguration(ccfg, ccfg2);
return IgniteSpring.start(cfg, applicationContext);
}
}
主要应用程序类:
@SpringBootApplication
@EnableSwagger2
@ComponentScan(basePackages = {...})
@EnableIgniteRepositories("...")
public class Swagger2SpringBoot extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Swagger2SpringBoot.class);
}
public static void main(String[] args) throws Exception {
SpringApplication.run(Swagger2SpringBoot.class, args);
}
}
使用此配置,应用程序至少可以启动。我花了相当多的时间来弄清楚如何设置 bean、注释、依赖项等。现在我使用这些的方式:
@Service
public class LicenseManager {
@Autowired
private LALicenseCountRepository laLicenseCountRepository;
@Autowired
private LALicenseMappingRepository laLicenseMappingRepository;
@Autowired
private Ignite ignite;
private LALicenseCount licenseCount;
private IgniteCache<Long, LALicenseCount> laLicenseCountCache;
@PostConstruct
public void init() {
// There is only one LA_LICENSE_COUNT record always in the DB, and the ID is 1
licenseCount = laLicenseCountRepository.findOne(1L);
laLicenseCountCache = ignite.getOrCreateCache("LALicenseCountCache");
}
public Iterable<LALicenseMapping> getAllAllocatedLicenses() {
return laLicenseMappingRepository.findAll();
}
public void allocateNewLicense(String clientID) {
// prechecks
laLicenseCountCache.query(
new SqlFieldsQuery(
sqlReader.getLicense().getUpdateAllocatedCounts()
).setArgs(
licenseCount.getActiveCount(),
licenseCount.getTemporaryCount(),
1L
)
);
// remaining logic
}
}
请保留代码中关于1L常量的注释,这部分会改变,这段代码只是为了看看我是否可以读/写数据库。到目前为止, getAllAllocationLicenses() 函数似乎正在工作(没有发生异常),我成功地在响应中收到一个空的 JSON 数组。问题是,在我手动将一条记录输入数据库表后,我也收到一个空的 JSON 数组(不确定 Ignite 是否应该找到该记录,但我认为是的)。
更大的问题是写操作失败。应执行的 SQL 来自属性文件,如下所示:
update la_license_count set active_count = ?, temporary_count = ? where id = ?
我收到以下堆栈跟踪(仅在 laLicenseCountCache.query 行之前显示):
2018-07-11 17:40:33.211 [http-nio-9080-exec-8] INFO h.t.c.e.service.LicenseManager - 123456 - Processing new license allocation for client
2018-07-11 17:40:33.506 [http-nio-9080-exec-8] DEBUG h.t.c.e.service.LicenseManager - 123456 - Checks done, allocating new final license
2018-07-11 17:40:33.515 [http-nio-9080-exec-8] ERROR h.t.c.e.a.LAMiddlewareApiController - Unknown exception
javax.cache.CacheException: Failed to parse query. Table "LA_LICENSE_COUNT" not found; SQL statement:
update la_license_count set active_count = ?, temporary_count = ? where id = ? [42102-196]
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:676)
at org.apache.ignite.internal.processors.cache.IgniteCacheProxyImpl.query(IgniteCacheProxyImpl.java:615)
at org.apache.ignite.internal.processors.cache.GatewayProtectedCacheProxy.query(GatewayProtectedCacheProxy.java:356)
at h.t.c.e.s.LicenseManager.allocateLicenseForCid(LicenseManager.java:127)
at h.t.c.e.s.a.LAMiddlewareApiController.lAMiddlewareLicensesCidGet(LAMiddlewareApiController.java:147)
...
Caused by: org.apache.ignite.internal.processors.query.IgniteSQLException: Failed to parse query. Table "LA_LICENSE_COUNT" not found; SQL statement:
update la_license_count set active_count = ?, temporary_count = ? where id = ? [42102-196]
...
Caused by: org.h2.jdbc.JdbcSQLException: Table "LA_LICENSE_COUNT" not found; SQL statement:
update la_license_count set active_count = ?, temporary_count = ? where id = ? [42102-196]
at org.h2.message.DbException.getJdbcSQLException(DbException.java:345)
at org.h2.message.DbException.get(DbException.java:179)
at org.h2.message.DbException.get(DbException.java:155)
at org.h2.command.Parser.readTableOrView(Parser.java:5552)
at org.h2.command.Parser.readTableOrView(Parser.java:5529)
at org.h2.command.Parser.readSimpleTableFilter(Parser.java:796)
at org.h2.command.Parser.parseUpdate(Parser.java:739)
at org.h2.command.Parser.parsePrepared(Parser.java:471)
at org.h2.command.Parser.parse(Parser.java:321)
at org.h2.command.Parser.parse(Parser.java:293)
at org.h2.command.Parser.prepareCommand(Parser.java:258)
at org.h2.engine.Session.prepareLocal(Session.java:578)
at org.h2.engine.Session.prepareCommand(Session.java:519)
at org.h2.jdbc.JdbcConnection.prepareCommand(JdbcConnection.java:1204)
at org.h2.jdbc.JdbcPreparedStatement.<init>(JdbcPreparedStatement.java:73)
at org.h2.jdbc.JdbcConnection.prepareStatement(JdbcConnection.java:288)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepare0(IgniteH2Indexing.java:484)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatement(IgniteH2Indexing.java:452)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatement(IgniteH2Indexing.java:419)
at org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing.prepareStatementAndCaches(IgniteH2Indexing.java:2008)
... 85 common frames omitted
根据最后一个异常,看起来它正在尝试像访问 H2 DB 一样访问 Oracle DB?那可能吗?我为 Ignite 显式设置了 OracleDialect,并且 Oracle JDBC 驱动程序位于 pom.xml 文件中。或者 Ignite 无法连接到数据库? (我没有在日志中找到任何表明这一点的内容。)
我在这里缺少什么?
最佳答案
如果您正在针对 Apache Ignite 执行查询,则可能应该是 update "LALicenseCountCache".LALicenseCount set active_count = ?,temporary_count = ?其中 id = ?
Ignite 表名称和架构 != Oracle 表名称和架构。 Ignite 不实现 SQL 查询的透明代理。您不是通过 Ignite 查询 Oracle,而是查询 Ignite 自己的 SQL。
请注意,您还应该执行 loadCache()
来最初将所有数据从 Oracle 提取到 Apache Ignite 的缓存。否则,您的更新将无法工作,因为 Ignite 的 SQL 仅对缓存中已有的内容进行操作。
关于java - Spring Boot apache ignite表未找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51290798/
我找到了 this excellent question and answer它以 x/y(加上 center x/y 和 degrees/radians)开始并计算旋转- 到 x'/y'。这个计算很
全部: 我已经创建了一个 Windows 窗体和一个按钮。在另一个线程中,我试图更改按钮的文本,但它崩溃了;但是如果我尝试更改按钮的颜色,它肯定会成功。我认为如果您更改任何 Windows 窗体控件属
本网站的另一个问题已证实,C 中没有缩写的字面后缀,并且可以执行以下操作: short Number = (short)1; 但是转换它和不这样做有什么区别: short Number = 1; 您使
我有下表: ID (int) EMAIL (varchar(50)) CAMPAIGNID (int) isSubscribe (bit) isActionByUser (bit) 此表存储了用户对事
也就是说,无需触发Javascript事件即可改变的属性,如何保留我手动选中或取消选中的复选框的状态,然后复制到另一个地方? 运行下面的代码片段并选中或取消选中其中的一些,然后点击“复制”: $('#
我在网上找到的所有关于递增指针导致段错误的示例都涉及指针的取消引用 - 如果我只想递增它(例如在 for 循环的末尾)并且我不在乎它是否最终进入无效内存,因为我不会再使用它。例如,在这个程序中,每次迭
我有一个 Spring MVC REST 服务,它使用 XStream 将消息与 XML 相互转换。 有什么方法可以将请求和响应中的 xml(即正文)打印到普通的 log4j 记录器? 在 Contr
做我的任务有一个很大的挑战,那就是做相互依赖的任务我在这张照片中说的。假设我们有两个任务 A 和 B,执行子任务 A1、A2 和 B1、B2,假设任务 B 依赖于 A。 要理想地执行任务 B,您应该执
通过阅读该网站上的几个答案,我了解到 CoInitialize(Ex) should be called by the creator of a thread 。然后,在该线程中运行的任何代码都可以使
这个问题已经困扰我一段时间了。我以前从未真正使用过 ListViews,也没有使用过 FirebaseListAdapters。我想做的就是通过显示 id 和用户位置来启动列表的基础,但由于某种原因,
我很难解释这两个(看似简单)句子的含义: “受检异常由编译器在编译时检查” 这是什么意思?编译器检查是否捕获了所有已检查的异常(在代码中抛出)? “未经检查的异常在运行时检查,而不是编译时” 这句话中
我有一个包含排除子字符串的文本文件,我想迭代该文件以检查并返回不带排除子字符串的输入项。 这里我使用 python 2.4,因此下面的代码可以实现此目的,因为 with open 和 any 不起作用
Spring 的缓存框架能否了解请求上下文的身份验证状态,或者更容易推出自己的缓存解决方案? 最佳答案 尽管我发现这个用例 super 奇怪,但您可以为几乎任何与 SpEL 配合使用的内容设置缓存条件
我有以下函数模板: template HeldAs* duplicate(MostDerived *original, HeldAs *held) { // error checking omi
如果我的应用程序具有设备管理员/设备所有者权限(未获得 root 权限),我如何才能从我的应用程序中终止(或阻止启动)另一个应用程序? 最佳答案 设备所有者可以阻止应用程序: DevicePolicy
非常简单的问题,但我似乎无法让它正常工作。 我有一个组件,其中有一些 XSLT(用于导航)。它通过 XSLT TBB 使用 XSLT Mediator 发布。 发布后
我正在将一个对象拖动到一个可拖放的对象内,该对象也是可拖动的。放置对象后,它会嵌套在可放置对象内。同样,如果我将对象拖到可放置的外部,它就不再嵌套。 但是,如果我经常拖入和拖出可放置对象,则可拖动对象
我正在尝试为按钮和弹出窗口等多个指令实现“取消选择”功能。也就是说,我希望当用户单击不属于指令模板一部分的元素时触发我的函数。目前,我正在使用以下 JQuery 代码: $('body').click
我从 this question 得到了下面的代码,该脚本用于在 Google tasks 上更改 iframe[src="about:blank"] 内的 CSS使用 Chrome 扩展 Tempe
我有一些 @Mock 对象,但没有指定在该对象上调用方法的返回值。该方法返回 int (不是 Integer)。我很惊讶地发现 Mockito 没有抛出 NPE 并返回 0。这是预期的行为吗? 例如:
我是一名优秀的程序员,十分优秀!