tinkerpop(2) 使用java调用tinkerpop,存储到derby数据库

简介: 1,关于tinkerpop本文原文连接: http://blog.csdn.net/freewebsys/article/details/46470651 转载请注明出处!之前体验了下tinkerpop的console服务。 存储数据,然后进行查询数据。 之前写的文章: http://blog.csdn.net/freewebsys/article/details

1,关于tinkerpop

本文原文连接: http://blog.csdn.net/freewebsys/article/details/46470651 转载请注明出处!

之前体验了下tinkerpop的console服务。
存储数据,然后进行查询数据。
之前写的文章:
http://blog.csdn.net/freewebsys/article/details/46348975

2,关于blueprints

这里写图片描述
Blueprints是一组针对属性图数据模型的接口、实现、测试套件,有些类似于JDBC,不同之处在于Blueprints是针对图形数据库的。Blueprints提供了一组通用的接口,允许开发者在他们的图形数据库后端即插即用。
这里写图片描述
这个图表示了blueprints的位置,在最底层,决定数据存储。

wiki参考:
https://github.com/tinkerpop/blueprints/wiki

其中blueprints支持的存储:
TinkerGraph (TinkerGraph)
Neo4j Implementation (Neo4jGraph)
Neo4jHA Implementation (Neo4jHaGraph)
Neo4jBatch Implementation (Neo4jBatchGraph)
Sail Implementation (SailGraph)
Sparksee Implementation (SparkseeGraph)
Rexster Implementation (RexsterGraph)
Accumulo Implementation (AccumuloGraph – 3rd party – implements Blueprints 2.4.0)
ArangoDB Implementation (ArangoDBGraph – 3rd party – implements Blueprints 2.3.0)
Bitsy (BitsyGraph – 3rd party – implements Blueprints 2.4.0)
Bigdata (BigdataGraph – 3rd party – implements Blueprints 2.5.0)
FluxGraph - Datomic Implementation (FluxGraph – 3rd party – implements Blueprints 2.1.0)
FoundationDB Implementation (FoundationDBGraph – 3rd party – implements Blueprints 2.4.0)
InfiniteGraph Implementation (IGGraph – 3rd party – implements Blueprints 2.1.0)
JPA Implementation (JpaGraph – 3rd party – implements Blueprints 2.5.0)
MongoDB Implementation (MongoDBGraph – 3rd party – implements Blueprints 2.3.0)
Oracle NoSQL Implementation (KVGraph – 3rd party – implements Blueprints 2.1.0)
OrientDB Implementation (OrientGraph – 3rd party – implements Blueprints 2.4.0)
SQL/JDBC Implementation – 3rd party – implements Blueprints 2.4.0)
Titan Implementation (TitanGraph – 3rd party – implements Blueprints 2.3.0)

3,配置依赖包

maven依赖:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>tinkerpop-demo</groupId>
    <artifactId>tinkerpop-demo</artifactId>
    <version>1.0</version>

    <!--
        https://maven.apache.org/guides/mini/guide-multiple-repositories.html
        增加wingnest-repo repo。
    -->
    <repositories>
        <repository>
            <id>wingnest-repo</id>
            <name>wingnest repo</name>
            <url>http://www.wingnest.com/mvn-repo/</url>
        </repository>
    </repositories>

    <dependencies>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-core</artifactId>
            <version>3.0.0.M9-incubating</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tinkerpop</groupId>
            <artifactId>gremlin-driver</artifactId>
            <version>3.0.0.M9-incubating</version>
        </dependency>
        <dependency>
            <groupId>com.tinkerpop.blueprints</groupId>
            <artifactId>blueprints-core</artifactId>
            <version>2.6.0</version>
        </dependency>
        <dependency>
            <groupId>com.wingnest.blueprints</groupId>
            <artifactId>blueprints-jpa-graph</artifactId>
            <version>2.5.0_01</version>
        </dependency>

        <!-- add hibernate dependency -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.7.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>1.6.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.11.1.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derbytools</artifactId>
            <version>10.11.1.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.3.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>4.3.10.Final</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.11.1.1</version>
        </dependency>
    </dependencies>

    <!-- 插件管理 -->
    <build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <!-- 设置路径,读取路径问题. -->
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>2.5.1</version>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <encoding>UTF-8</encoding>
                    </configuration>
                </plugin>

                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-resources-plugin</artifactId>
                    <version>2.4</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>


</project>

测试代码:

package com.tinkerpop.demo;

import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Graph;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.blueprints.impls.tg.TinkerGraph;
import com.wingnest.blueprints.impls.jpa.JpaGraph;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

/**
 *
 */

public class TinkerPopDemo {

    private JpaGraph jpaGraph = null;

    @Before
    public void setUp() {
        //初始化jpa。保存到数据库中。使用hibernate 自动创建表结构。
        //如果要使用mysql,这里修改属性。
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("javax.persistence.jdbc.url", String.format("jdbc:derby:db/HibernateUnit_test_perf;create=true"));
        jpaGraph = new JpaGraph("HibernateUnit", props);
    }

    @After
    public void tearDown() throws Exception {
        //关闭
        jpaGraph.shutdown();
    }

    @Test
    public void testCreate() {

        //创建张三数据
        Vertex zhangsan = jpaGraph.addVertex(null);
        zhangsan.setProperty("name", "zhangsan");
        System.out.println("zhangsan:" + zhangsan.getId());

        //创建李四数据
        Vertex lisi = jpaGraph.addVertex(null);
        lisi.setProperty("name", "lisi");
        System.out.println("lisi:" + lisi.getId());

        //创建王五数据
        Vertex wangwu = jpaGraph.addVertex(null);
        wangwu.setProperty("name", "wangwu");
        System.out.println("wangwu:" + wangwu.getId());

        //设置李四和王五朋友关系,friend是连接的名字,可以随意取。
        Edge friend1 = jpaGraph.addEdge(null, zhangsan, lisi, "friend");

        //设置王五和李四朋友关系
        Edge friend2 = jpaGraph.addEdge(null, wangwu, lisi, "friend");

        System.out.println("create finish");
    }

    @Test
    public void testQuery() {
        //查询全部数据。
        queryAll();
        queryZhansanFriends();
        System.out.println("query finish");
    }

    private void queryAll() {
        Iterable<Vertex> allVertex = jpaGraph.getVertices();
        System.out.println("######################query all######################");
        for (Vertex vertex : allVertex) {
            System.out.print("name:" + vertex.getProperty("name"));
            System.out.println(",id:" + vertex.getId());
        }
    }

    private void queryZhansanFriends() {
        Vertex zhangsan = jpaGraph.getVertex(1);
        System.out.println("######################query zhangsan friends######################");
        Iterable<Vertex> zhansanFriends = zhangsan.getVertices(Direction.OUT, "friend");
        for (Vertex vertex : zhansanFriends) {
            System.out.print("name:" + vertex.getProperty("name"));
            System.out.println(",id:" + vertex.getId());
        }
    }

    @Test
    public void testDelete() {
        Vertex lisi = jpaGraph.getVertex(2);
        jpaGraph.removeVertex(lisi);
        //删除之后,查询全部。
        queryAll();
        queryZhansanFriends();
    }

}

运行结果:

SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Jun 12, 2015 5:19:11 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Jun 12, 2015 5:19:11 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Jun 12, 2015 5:19:11 PM org.hibernate.ejb.HibernatePersistence logDeprecation
WARN: HHH015016: Encountered a deprecated javax.persistence.spi.PersistenceProvider [org.hibernate.ejb.HibernatePersistence]; use [org.hibernate.jpa.HibernatePersistenceProvider] instead.
Jun 12, 2015 5:19:11 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
    name: HibernateUnit
    ...]
Jun 12, 2015 5:19:11 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.10.Final}
Jun 12, 2015 5:19:11 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
Jun 12, 2015 5:19:11 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Jun 12, 2015 5:19:12 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
Jun 12, 2015 5:19:13 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH000402: Using Hibernate built-in connection pool (not for production use!)
Jun 12, 2015 5:19:13 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000401: using driver [org.apache.derby.jdbc.EmbeddedDriver] at URL [jdbc:derby:db/HibernateUnit_test_perf;create=true]
Jun 12, 2015 5:19:13 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000046: Connection properties: {user=admin, password=****}
Jun 12, 2015 5:19:13 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH000006: Autocommit mode: false
Jun 12, 2015 5:19:13 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
Jun 12, 2015 5:19:14 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.DerbyTenSevenDialect
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.BpJpaElement.propMap not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndexItem.indexName not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndex.keyIndexedItems not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndex.indexClassName not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndex.indexItems not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndexBase.version not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.BpJpaProperty.keyName not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty.propertyId not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty.keyName not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty.elementType not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty.elementId not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.annotations.reflection.JPAOverriddenAnnotationReader checkForOrphanProperties
WARN: HHH000207: Property com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty.bpJpaKeyIndex not found in class but described in <mapping-file/> (possible typo error)
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.BpJpaElement
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndexItem
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.BpJpaVertex
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.BpJpaEdge
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndex
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaIndex
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.BpJpaProperty
Jun 12, 2015 5:19:14 PM org.hibernate.cfg.AnnotationBinder bindClass
WARN: HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: com.wingnest.blueprints.impls.jpa.internal.models.index.BpJpaKeyIndexedProperty
Jun 12, 2015 5:19:14 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Jun 12, 2015 5:19:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
Jun 12, 2015 5:19:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
Jun 12, 2015 5:19:14 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: .ADMIN.ENTITY
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [element_id, id, valuedata, incomingvertex_id, dtype, removed, label, keyname, outgoingvertex_id, version]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: [fk_9r4w6h2jlb9a4e9pt3d95girc, fk_wb8dqej10hriw3o6m72yj9p, fk_ay9plo3t1cprfwdwjvp6fdwi6]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [uk_7hyan3asmdvrxrlywl7v0lj6e, sql150612170336740, uk_ejspyse8mcceolr4vps96aohp, sql150612170337000, sql150612170337030, sql150612170336940]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: .ADMIN.INDEX_BASE
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [id, bpjpakeyindex_id, indexclassname, elementtype, dtype, removed, elementid, keyname, indexvalue, bpjpaindex_id, propertyid, indexname, version]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: [fk_7ipiov9b2bb97hkncnl76mkkm, fk_olnpc5iekqlpsk6n61ucruk96]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [sql150612170337100, uk_o7ehuddxk2u2rgtqv9c8kbj75, uk_fd9ey72b1ypwplyllo410siv1, sql150612170337080, sql150612170336780, uk_l9wg7u7fi95namecr9p3apnn5, uk_tidr0ggw8dtylnj1ldr1oy4gb, uk_bke0r11vg7q6vtfud90jnfx4, uk_2u6spckbs5deg5048qfvxg5ca]
Jun 12, 2015 5:19:15 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Jun 12, 2015 5:19:15 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: SQL Warning Code: 10000, SQLState: 01J01
Jun 12, 2015 5:19:15 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper$StandardWarningHandler logWarning
WARN: Database 'db/HibernateUnit_test_perf' not created, connection made to existing database instead.
zhangsan:1
lisi:2
wangwu:3
create finish
Jun 12, 2015 5:19:16 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl stop
INFO: HHH000030: Cleaning up connection pool [jdbc:derby:db/HibernateUnit_test_perf;create=true]

Process finished with exit code 0

对数据进行CRUD没有问题。

4,总结

本文原文连接: http://blog.csdn.net/freewebsys/article/details/46470651 转载请注明出处!

代码就一个pom和java类,非常简单的就把图的数据存储到了数据库中。
存储到mysql里面类似,需要修改下jdbc连接即可。
如果作为业务服务,现在的代码再加点就基本满足了。
虽然数据库存储的比neo4j,solr等稍微慢点,但是运维成本低,数据库可以做主从复制,保护数据,同时多个服务访问一个数据库也可以解决单点服务问题。
数据库的优化非常多,非常方便,同时索引速度也挺快的。这个存储的是关系,一般情况先数据不太大,再使用mycat进行分库分表就可以扩展了。

目录
相关文章
|
1月前
|
XML Java 数据库连接
性能提升秘籍:如何高效使用Java连接池管理数据库连接
在Java应用中,数据库连接管理至关重要。随着访问量增加,频繁创建和关闭连接会影响性能。为此,Java连接池技术应运而生,如HikariCP。本文通过代码示例介绍如何引入HikariCP依赖、配置连接池参数及使用连接池高效管理数据库连接,提升系统性能。
62 5
|
6天前
|
存储 druid 分布式数据库
列式存储数据库与超市的关系?
列式存储数据库是一种高效的数据管理方式,类似于超市将相似商品集中摆放。它将相同类型的数据(如年龄、价格)归类存储,便于快速查询和压缩,广泛应用于市场分析、财务报告和健康数据分析等领域。知名产品包括HBase、ClickHouse、Druid和Apache Cassandra等,适合处理大规模数据和实时分析任务。
22 4
|
1月前
|
JSON Java 关系型数据库
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
在Java中,使用mybatis-plus更新实体类对象到mysql,其中一个字段对应数据库中json数据类型,更新时报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
70 4
Java更新数据库报错:Data truncation: Cannot create a JSON value from a string with CHARACTER SET 'binary'.
|
16天前
|
存储 Java
Java 11 的String是如何优化存储的?
本文介绍了Java中字符串存储优化的原理和实现。通过判断字符串是否全为拉丁字符,使用`byte`代替`char`存储,以节省空间。具体实现涉及`compress`和`toBytes`方法,前者用于尝试压缩字符串,后者则按常规方式存储。代码示例展示了如何根据配置决定使用哪种存储方式。
|
29天前
|
存储 数据库
快速搭建南大通用GBase 8s数据库SSC共享存储集群
本文介绍如何GBase8s 数据库 在单机环境中快速部署SSC共享存储集群,涵盖准备工作、安装数据库、创建环境变量文件、准备数据存储目录、修改sqlhost、设置onconfig、搭建sds集群及集群检查等步骤,助你轻松完成集群功能验证。
|
1月前
|
存储 缓存 安全
在 Java 编程中,创建临时文件用于存储临时数据或进行临时操作非常常见
在 Java 编程中,创建临时文件用于存储临时数据或进行临时操作非常常见。本文介绍了使用 `File.createTempFile` 方法和自定义创建临时文件的两种方式,详细探讨了它们的使用场景和注意事项,包括数据缓存、文件上传下载和日志记录等。强调了清理临时文件、确保文件名唯一性和合理设置文件权限的重要性。
96 2
|
22天前
|
存储 Oracle 关系型数据库
服务器数据恢复—华为S5300存储Oracle数据库恢复案例
服务器存储数据恢复环境: 华为S5300存储中有12块FC硬盘,其中11块硬盘作为数据盘组建了一组RAID5阵列,剩下的1块硬盘作为热备盘使用。基于RAID的LUN分配给linux操作系统使用,存放的数据主要是Oracle数据库。 服务器存储故障: RAID5阵列中1块硬盘出现故障离线,热备盘自动激活开始同步数据,在同步数据的过程中又一块硬盘离线,RAID5阵列瘫痪,上层LUN无法使用。
|
1月前
|
SQL Java 数据库连接
在Java应用中,数据库访问常成为性能瓶颈。连接池技术通过预建立并复用数据库连接,有效减少连接开销,提升访问效率
在Java应用中,数据库访问常成为性能瓶颈。连接池技术通过预建立并复用数据库连接,有效减少连接开销,提升访问效率。本文介绍了连接池的工作原理、优势及实现方法,并提供了HikariCP的示例代码。
55 3
|
1月前
|
存储 Java 关系型数据库
在Java开发中,数据库连接是应用与数据交互的关键环节。本文通过案例分析,深入探讨Java连接池的原理与最佳实践
在Java开发中,数据库连接是应用与数据交互的关键环节。本文通过案例分析,深入探讨Java连接池的原理与最佳实践,包括连接创建、分配、复用和释放等操作,并通过电商应用实例展示了如何选择合适的连接池库(如HikariCP)和配置参数,实现高效、稳定的数据库连接管理。
66 2
|
1月前
|
Java 数据库连接 数据库
如何构建高效稳定的Java数据库连接池,涵盖连接池配置、并发控制和异常处理等方面
本文介绍了如何构建高效稳定的Java数据库连接池,涵盖连接池配置、并发控制和异常处理等方面。通过合理配置初始连接数、最大连接数和空闲连接超时时间,确保系统性能和稳定性。文章还探讨了同步阻塞、异步回调和信号量等并发控制策略,并提供了异常处理的最佳实践。最后,给出了一个简单的连接池示例代码,并推荐使用成熟的连接池框架(如HikariCP、C3P0)以简化开发。
56 2